示例#1
0
    def testFlavorSetOps(self):
        a = parseFlavor('foo,bar is: x86')
        b = parseFlavor('foo,~!bar')
        x = a & b
        assert(x.freeze() == '5#use:foo')
        x = a - b
        assert(x.freeze() == '1#x86|5#use:bar')
        x = flavorDifferences((a,b))
        assert(x[a].freeze() == '1#x86|5#use:bar')
        assert(x[b].freeze() == '5#use:~!bar')
        a = DependencySet()
        a.addDep(TroveDependencies, Dependency("foo:runtime"))

        assert(a.copy() & a == a)
        assert(not (a - a))
        x = flavorDifferences((a, a))
        assert(not x[a])

        #now test non-strict ops
        a = parseFlavor('foo,bar')
        b = parseFlavor('~foo,~!bar,bam')
        assert(str(a.intersection(b, strict=False)) == 'foo')
        assert(str(a.difference(b, strict=False)) == 'bar')
        assert(str(flavorDifferences([a, b],strict=False)[a]) == 'bar')
        assert(str(flavorDifferences([a, b],strict=False)[b]) == 'bam,~!bar')

        # test empty set
        assert(flavorDifferences([]) == {})
示例#2
0
    def testUnknownDependency(self):
        # Adding a dependency that is unknown to the current version of the
        # code

        intTag = 65535
        stringTag = "yet-to-be-defined"
        class YetToBeDefinedDependency(DependencyClass):
            tag = intTag
            tagName = stringTag
            justOne = False
            depClass = Dependency

        ds = DependencySet()
        depName = "some"
        depFlag = "flag1"
        ds.addDep(YetToBeDefinedDependency,
            Dependency(depName, [ (depFlag, FLAG_SENSE_REQUIRED) ]))
        frozen = ds.freeze()

        x = ThawDependencySet(frozen)
        self.assertEqual(str(x), "unknown-%s: %s(%s)" % 
            (intTag, depName, depFlag))
示例#3
0
    def testDepSet(self):
        requires = DependencySet()
        requires.addDep(FileDependencies, Dependency("/bin/sed"))
        requires.addDep(FileDependencies, Dependency("/bin/awk"))
        requires.addDep(TroveDependencies, Dependency("foo:runtime"))
        assert(str(requires) ==
                "file: /bin/awk\nfile: /bin/sed\ntrove: foo:runtime")
        assert(ThawDependencySet(requires.freeze()) == requires)

        provides = DependencySet()
        provides.addDep(FileDependencies, Dependency("/bin/sed"))
        provides.addDep(FileDependencies, Dependency("/bin/awk"))
        provides.addDep(TroveDependencies, Dependency("foo:runtime"))
        assert(ThawDependencySet(provides.freeze()) == provides)

        assert(provides.satisfies(requires))

        provides.addDep(FileDependencies, Dependency("/bin/grep"))
        assert(provides.satisfies(requires))

        requires.addDep(FileDependencies, Dependency("/bin/grep"))
        assert(provides.satisfies(requires))

        requires.addDep(TroveDependencies, Dependency("bar:runtime"))
        assert(not provides.satisfies(requires))

        provides.addDep(TroveDependencies, Dependency("bar:runtime"))
        assert(provides.satisfies(requires))

        requires.addDep(InstructionSetDependency,
                        Dependency("x86", [("cmov", FLAG_SENSE_REQUIRED),
                                           ("sse", FLAG_SENSE_REQUIRED)]))
        assert(not provides.satisfies(requires))

        provides.addDep(InstructionSetDependency,
                        Dependency("x86", [("cmov", FLAG_SENSE_REQUIRED),
                                           ("mmx", FLAG_SENSE_REQUIRED),
                                           ("sse", FLAG_SENSE_REQUIRED)]))
        assert(provides.satisfies(requires))

        requires = DependencySet()
        requires.addDep(InstructionSetDependency,
                        Dependency("x86", [("cmov", FLAG_SENSE_REQUIRED),
                                           ("sse", FLAG_SENSE_REQUIRED)]))

        provides = DependencySet()
        provides.addDep(InstructionSetDependency,
                        Dependency("x86", [("3dnow", FLAG_SENSE_REQUIRED),
                                           ("cmov",  FLAG_SENSE_REQUIRED)]))
        assert(not provides.satisfies(requires))

        first = DependencySet()
        first.addDep(InstructionSetDependency,
                        Dependency("x86", [("cmov", FLAG_SENSE_REQUIRED),
                                           ("sse", FLAG_SENSE_REQUIRED)]))
        first.addDep(FileDependencies, Dependency("/bin/awk"))
        first.addDep(FileDependencies, Dependency("/bin/grep"))
        first.addDep(TroveDependencies, Dependency("foo:runtime"))

        second = DependencySet()
        second.addDep(InstructionSetDependency,
                        Dependency("x86", [("cmov", FLAG_SENSE_REQUIRED),
                                           ("mmx", FLAG_SENSE_REQUIRED)]))
        second.addDep(FileDependencies, Dependency("/bin/sed"))
        second.addDep(SonameDependencies, Dependency("libc.so.6"))
        first.union(second)
        assert(str(first) == "is: x86(cmov mmx sse)\n"
                             "file: /bin/awk\n"
                             "file: /bin/grep\n"
                             "file: /bin/sed\n"
                             "trove: foo:runtime\n"
                             "soname: libc.so.6")

        first = DependencySet()
        second = DependencySet()
        assert(hash(first) == hash(second))
        first.addDep(FileDependencies, Dependency("/bin/sed"))
        second.addDep(FileDependencies, Dependency("/bin/sed"))
        assert(hash(first) == hash(second))

        # test that dictionary order has no affect on frozen form
        class shadowDict(dict):
            def __init__(self, otherdict):
                dict.__init__(self, otherdict)

            def iteritems(self):
                items = self.items()
                items.reverse()
                for key, value in items:
                    yield key, value

        # this isn't ordered by path; make sure the frozen dep is ordered
        # by path
        depset = DependencySet()
        for x in range(10):
            depset.addDep(FileDependencies, Dependency("/bin/%d" % x))

        frz = depset.freeze()
        l = frz.split("|")
        assert( [ int(x[-1]) for x in  l ] == list(range(10)) )

        # make sure removing works properly
        s = DependencySet()
        s.addDep(FileDependencies, Dependency('/bin/foo'));
        s.addDep(TroveDependencies, Dependency('bar') )
        self.assertEquals(str(s), 'file: /bin/foo\ntrove: bar')

        self.assertRaises(KeyError, s.removeDeps,
                          SonameDependencies, [ Dependency('foo') ])
        self.assertRaises(KeyError, s.removeDeps,
                          FileDependencies, [ Dependency('foo') ])
        s.removeDeps(SonameDependencies, [ Dependency('foo') ],
                     missingOkay = True)
        s.removeDeps(FileDependencies, [ Dependency('foo') ],
                     missingOkay = True)
        self.assertEquals(str(s), 'file: /bin/foo\ntrove: bar')

        s.removeDeps(FileDependencies, [ Dependency('/bin/foo') ],
                     missingOkay = True)
        self.assertEquals(str(s), 'trove: bar')
        s2 = ThawDependencySet(s.freeze())
        assert(s2.freeze() == s.freeze())

        s.removeDeps(TroveDependencies, [ Dependency('bar') ],
                     missingOkay = True)
        self.assertEquals(str(s), '')

        s2 = ThawDependencySet(s.freeze())
        assert(s2.freeze() == s.freeze())