@testhelp.context('sysmodel')
    def testScripts(self):
        '''
        Make sure we can attach scripts to groups correctly
        '''
        def _checkScripts(grp):
            scripts = grp.troveInfo.scripts
            for scriptType in scriptTypes:
                script = getattr(scripts, scriptType).script()
                self.assertEquals(script, scriptType % '# %s')

        self.addComponent('foo:runtime=1.0')
        self.addComponent('foo:lib=1.0')
        self.addCollection('foo=1.0', [ 'foo:runtime', 'foo:lib' ])
        
        recipe = []
        # These 5 types are the only types allowed for groups; the
        # other 3 types are supported only for packages (for RPM import)
        scriptTypes = ('postInstall',
                       'preRollback', 'postRollback',
                       'preUpdate', 'postUpdate')
        for scriptType in scriptTypes:
            recipe.append('%s = r.Script(contents="# %s")' %
                            (2 * (scriptType,)))
        recipe.append('scripts = r.Scripts(%s)' %', '.join(
            [' = '.join((x, x)) for x in scriptTypes]))
        recipe.append('foo = world.find("foo")')
        recipe.append('groupInner = foo.createGroup('
                         '"group-inner", scripts=scripts)')
        recipe.append('r.Group(groupInner, scripts=scripts)')
        grp = self._build(*recipe)
        repos = self.openRepository()
        igrp = repos.getTrove('group-inner', grp.getVersion(), grp.getFlavor())
        for g in (grp, igrp):
            _checkScripts(g)

        # now try and build a new group which inherits some of those scripts
        grp = self._build("grp = world['group-test']",
                          "foo = world['foo']",
                          "r.name = 'group-bar'",
                          "scripts = grp.scripts()",
                          "r.Group(foo, scripts = scripts)")
        _checkScripts(grp)

        # these builds fail because of too many/too few items in the troveset
        e = self.assertRaises(cook.CookError,
                  self._build, "grp = world.find('group-test', 'foo')",
                               "scripts = grp.scripts()",
                               "r.Group(grp, scripts = scripts)")
        self.assertEquals(str(e), 'Multiple troves in trove set for scripts()')

        e = self.assertRaises(cook.CookError,
                  self._build, "grp = world.find('group-test')",
                               "scripts = (grp - grp['group-test']).scripts()",
                               "r.Group(grp, scripts = scripts)")
        self.assertEquals(str(e), 'Empty trove set for scripts()')
dataset/ETHPy150Open sassoftware/conary/conary_test/cvctest/buildtest/groupsettest.py/GroupSetTest.testScripts/swapped operands of `%`