示例#1
0
 def testIterRawDeps(self):
     dep = ThawDependencySet('4#blam|4#foo:!bar')
     expected = [(4, 'blam', []), (4, 'foo', ['!bar'])]
     self.assertEqual(list(dep.iterRawDeps()), expected)
     # Ensure it did not force a lazy parse
     assert isinstance(dep._members, str)
     # Now try again after parsing
     str(dep)
     assert isinstance(dep._members, dict)
     self.assertEqual(sorted(dep.iterRawDeps()), expected)
示例#2
0
 def _testStr(self, strForm, frzForm):
     first = parseDep(strForm)
     frz = first.freeze()
     second = ThawDependencySet(frz)
     assert(frz == frzForm)
     assert(first == second)
     assert(parseDep(str(first)).freeze() == frzForm)
示例#3
0
    def testPickleDeps(self):
        for text in ('', '~foo.bar target: sparc is: x86_64'):
            flavor = parseFlavor(text)
            self.assertEquals(flavor, pickle.loads(pickle.dumps(flavor)))

        for text in ('', '4#blam|4#foo'):
            dep = ThawDependencySet(text)
            self.assertEquals(dep, pickle.loads(pickle.dumps(dep)))
示例#4
0
    def testDependencyMatcher(self):
        m = DependencyMatcher(ignoreDepClasses=[AbiDependency])
        m.add(ThawDependencySet('0#ignored|4#foobar::java|10#ham|10#spam'), 'foobar')
        m.add(ThawDependencySet('0#ignored|11#ham:2.6:lib|11#spam:2.6:lib'), 'hamspam32')
        m.add(ThawDependencySet('0#ignored|11#ham:2.6:lib64|11#spam:2.6:lib64'), 'hamspam64')

        self.assertEqual(m.find(parseDep('java: ham')), [['foobar']])
        self.assertEqual(m.find(parseDep('python: ham')), [['hamspam32', 'hamspam64']])
        s = parseDep('python: ham(lib)')
        s.union(parseDep('python: spam(lib)'))
        self.assertEqual(m.find(s), [ ['hamspam32'], ['hamspam32'] ])

        s = parseDep('python: ham(lib)')
        s.union(parseDep('python: spam'))
        s.union(parseDep('trove: foobar:java'))
        s.union(parseDep('abi: missing(SysV)'))
        self.assertEqual(m.check(s), None)
        s.union(parseDep('python: pork'))
        e = parseDep('python: pork')
        self.assertEqual(m.check(s), e)
        s.union(parseDep('python: spam(nope)'))
        e.union(parseDep('python: spam(nope)'))
        self.assertEqual(m.check(s), e)
示例#5
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))
示例#6
0
 def __thaw__(depList):
     return [(isCross, (thaw('troveTuple', x[0]), ThawDependencySet(x[1])))
             for isCross, x in depList]
示例#7
0
 def __thaw__(depList):
     return [ThawDependencySet(x) for x in depList]
示例#8
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())