class BtsTests(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()
        self.bts = self.udd.Bts(True)
        self.btsc = self.udd.Bts(False)

    def tearDown(self):
        self.bts = None
        self.btsc = None
        self.udd = None

    def testBugs(self):
        bugs = [500000, 500001, 500002, 666666]
        self.assertTrue(self.bts.bugs(bugs))
        self.assertEqual(len(self.bts.bugs(bugs)), 4)
        self.assertEqual(len(self.btsc.bugs(bugs)), 0)

    def testBug(self):
        b = self.bts.bug(500000)
        self.assertTrue(b)
        self.assertEqual(b.title,
                         "cdbs: Please add dh_installdefoma in debhelper.mk")
        self.assertEqual(b.id, 500000)
        self.assertEqual(b.severity, "wishlist")
        self.assertEqual(b.status, "done")
        self.assertEqual(b.archived, True)
        self.assertTrue(self.bts.bug("500000"))
        self.assertTrue(self.bts.bug("544925"))
        self.assertTrue(self.bts.bug("#500000"))
        self.assertRaises(BugNotFoundError, self.bts.bug, -1)
        self.assertRaises(BugNotFoundError, self.bts.bug, 99999999)
        self.assertRaises(BugNotFoundError, self.btsc.bug,
                          500000)  # bug is archived

    def test_get_bugs(self):
        self.assertTrue(self.bts.get_bugs({'package': 'latexdraw'}))
        self.assertTrue(self.bts.get_bugs({'package': 'pyx'
                                           }))  # package -> source mapping
        self.assertTrue(self.btsc.get_bugs({'title': 'RM: '}))
        self.assertTrue(self.bts.get_bugs({'source': 'latexdraw'}))
        self.assertFalse(self.btsc.get_bugs({'source': 'spline'}))
        self.assertTrue(
            self.bts.get_bugs({
                'source': 'latexdraw',
                'sort': 'id DESC'
            }))
        self.assertEqual(
            len(self.bts.get_bugs({
                'source': 'latexdraw',
                'limit': 1
            })), 1)

    def test_get_bugs_tags(self):
        b = self.bts.bug(2297)
        self.bts.get_bugs_tags(b)
        self.assertEqual(len(b.tags), 1)
        bl = self.bts.bugs([500000, 500001, 500002, 620381])
        self.bts.get_bugs_tags(bl)
class BuildDepCheckerTests(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()
        self.checker = BuildDepsChecker(
            self.udd.BindRelease(arch="i386", release="sid"))

    def tearDown(self):
        self.udd = None
        self.checker = None

    def testCheck(self):
        """Test checking the build-dependencies of a package"""
        # simple package, check by source package name
        b = self.checker.Check(package="pyxplot")
        self.assertTrue(b)
        self.assertTrue(len(b.bd.good) > 0)
        self.assertTrue(len(b.bd.bad) == 0)
        # big complicated package with lots of arch-dependent entries, check by binary name
        b = self.checker.Check(package="libc6")
        self.assertTrue(b)
        self.assertTrue(len(b.bd.good) > 0)
        self.assertTrue(len(b.bdi.good) > 0)
        self.assertTrue(len(b.bd.bad) == 0)
        self.assertTrue(len(b.bdi.bad) == 0)
        # check by SourcePackage object
        p = self.udd.BindSourcePackage(package="latexdraw", release="squeeze")
        b = self.checker.Check(package=p)
        self.assertTrue(b)
        self.assertTrue(len(b.bd.good) > 0)
        self.assertTrue(len(b.bd.bad) == 0)
        # non-existent package
        self.assertRaises(PackageNotFoundError,
                          self.checker.Check,
                          package="no-such-package")
        # bd and bdi lists
        p = self.udd.BindSourcePackage(package="libc6")
        bd = p.RelationshipOptionsList("build_depends")
        b = self.checker.Check(bdList=bd)
        self.assertTrue(b)
        self.assertTrue(len(b.bd.good) > 0)
        b = self.checker.Check(
            bdList=p.RelationshipOptionsList("build_depends"),
            bdiList=p.RelationshipOptionsList("build_depends"))
        self.assertTrue(b)
        self.assertTrue(len(b.bd.good) > 0)
        self.assertTrue(len(b.bdi.good) > 0)
        self.assertRaises(ValueError, self.checker.Check)
        self.assertRaises(ValueError, self.checker.Check, bdList=[])
class SolverHierarchyTests(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()

    def tearDown(self):
        self.udd = None

    def testInit(self):
        s = SolverHierarchy('dpkg')
        self.assertTrue(not s is None)

    def testGet(self):
        s = SolverHierarchy('')
        rs = RelationshipStatus()
        rs.good.append('dpkg')
        s.depends.extend(rs)
        self.assertTrue(s.get('depends'))
        self.assertFalse(s.get('recommends'))
        rs2 = RelationshipStatus()
        rs2.bad.append('dpkg2')
        s.depends.extend(rs2)
        self.assertFalse(s.get('recommends'))

    def testFlatten(self):
        self.checker = InstallChecker(
            self.udd.BindRelease(arch="i386", release="squeeze"))
        s = self.checker.Check('perl', True)
        f = s.flatten()
        self.assertTrue(f)
        self.assertTrue(len(f.depends))

    def testChains(self):
        self.checker = InstallChecker(
            self.udd.BindRelease(arch="i386", release="squeeze"))
        s = self.checker.Check('pyxplot', True)
        c = s.chains()
        self.assertTrue(c)
        self.assertTrue(len(c))

    def testStr(self):
        self.checker = InstallChecker(
            self.udd.BindRelease(arch="i386", release="squeeze"))
        s = self.checker.Check('perl', True)
        self.assertTrue(unicode(s))
        #self.assertTrue(str(s))
        f = s.flatten()
        self.assertTrue(unicode(f))
class InstallCheckerTests(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()
        self.checker = InstallChecker(self.udd.BindRelease())

    def tearDown(self):
        self.udd = None
        self.checker = None

    @unittest.skipIf(exclude_slow_tests, 'slow test')
    def testCheck(self):
        """Test installability of packages"""
        # FIXME: it would be good to check if these results are right
        self.assertTrue(self.checker.Check('libc6'))
        self.assertRaises(PackageNotFoundError, self.checker.Check,
                          'nosuchpackage')
        self.assertTrue(self.checker.Check('perl', True))
        self.assertTrue(self.checker.Check(
            'openjdk-6-jre-headless', True))  # missing recommended package
class database(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()

    def tearDown(self):
        self.udd = None

    def testDBTypes(self):
        """Test creating a Debian and derivative UDD instance"""
        self.assertTrue(Udd(distro='debian'))
        self.assertRaises(NotImplementedError, Udd,
                          distro='ubuntu')  # TODO: update when implemented
        self.assertRaises(ValueError, Udd, distro='nosuchdistro')

    def testPassConfig(self):
        """Test loading a config file manually"""
        config = Config()
        self.assertTrue(Udd(config=config))

    def testRelease(self):
        """Test binding to a release and doing a lookup"""
        r = self.udd.BindRelease('sid', 'i386')
        self.assertTrue(r)
        r = self.udd.BindRelease(['stable', 'stable-backports'], 'i386')
        self.assertTrue(r)

    def testPackage(self):
        """Test binding to a binary package and doing a lookup"""
        r = self.udd.BindPackage('libc6', 'sid', 'i386')
        self.assertTrue(r)
        self.assertTrue(r.Found())

    def testSource(self):
        """Test binding to a source package and doing a lookup"""
        r = self.udd.BindSourcePackage('glibc', 'sid')
        self.assertTrue(r)
        self.assertTrue(r.Found())
        r = self.udd.BindSourcePackage('libc6', 'sid')
        self.assertTrue(r)
        self.assertTrue(r.Found())
        self.assertTrue(r.data['version'])

    def testBts(self):
        """Test binding to a source package and doing a lookup"""
        tracker = self.udd.Bts(False)
        self.assertFalse(tracker.include_archived)
 def setUp(self):
     self.udd = Udd()
 def setUp(self):
     self.udd = Udd()
     self.checker = InstallChecker(self.udd.BindRelease())
 def setUp(self):
     self.udd = Udd()
     self.checker = BuildDepsChecker(
         self.udd.BindRelease(arch="i386", release="sid"))
 def setUp(self):
     self.udd = Udd()
     self.bts = self.udd.Bts(True)
     self.btsc = self.udd.Bts(False)
 def testDBTypes(self):
     """Test creating a Debian and derivative UDD instance"""
     self.assertTrue(Udd(distro='debian'))
     self.assertRaises(NotImplementedError, Udd,
                       distro='ubuntu')  # TODO: update when implemented
     self.assertRaises(ValueError, Udd, distro='nosuchdistro')
Example #11
0
 def setUp(self):
     self.udd = Udd()
     self.dispatcher = Commands(self.udd)
Example #12
0
class commands(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()
        self.dispatcher = Commands(self.udd)

    def tearDown(self):
        self.udd = None
        self.dispatcher = None

    def testVersions(self):
        """Test version lookups"""
        self.assertTrue(self.dispatcher.versions('libc6', 'sid', 'i386'))
        self.assertRaises(PackageNotFoundError, self.dispatcher.versions, 'nosuchpackage', 'sid', 'i386')
        self.assertRaises(PackageNotFoundError, self.dispatcher.versions, 'libc0.1', 'sid', 'armhf')
        self.assertTrue(self.dispatcher.versions('libc6', None, 'amd64'))
        self.assertTrue(self.dispatcher.versions('src:glibc', 'sid', 'i386'))
        self.assertRaises(PackageNotFoundError, self.dispatcher.versions, 'src:nosuchpackage', 'sid', 'i386')

    def testInfo(self):
        """Test package information lookups"""
        self.assertTrue(self.dispatcher.info('libc6', 'sid', 'i386'))
        self.assertRaises(PackageNotFoundError, self.dispatcher.info, 'nosuchpackage', 'sid', 'i386')
        self.assertRaises(PackageNotFoundError, self.dispatcher.info, 'libc6', 'sid', 'ia64')

    @unittest.skipIf(exclude_slow_tests, 'slow test')
    def testNames(self):
        """Test package name lookups"""
        self.assertTrue(self.dispatcher.names('libc6', 'sid', 'i386'))
        self.assertTrue(self.dispatcher.names('lib?6', 'sid', 'i386'))
        self.assertTrue(self.dispatcher.names('libc6*', 'sid', 'i386'))
        self.assertTrue(self.dispatcher.names('*bc6', 'sid', 'i386'))
        self.assertTrue(self.dispatcher.names('l*6', 'sid', 'i386'))
        self.assertFalse(self.dispatcher.names('libc0.1', 'sid', 'armhf'))
        self.assertTrue(self.dispatcher.names('libc6*', 'sid', 'armhf'))
        self.assertTrue(self.dispatcher.names('src:glibc', 'sid', 'armhf'))
        self.assertFalse(self.dispatcher.names('src:nosuchpackage', 'sid', 'i386'))

    def testArchs(self):
        """Test architecture availability lookups"""
        self.assertTrue(self.dispatcher.archs('libc6', 'sid'))
        self.assertRaises(PackageNotFoundError, self.dispatcher.archs, 'nosuchpackage', 'sid')

    def testPopcon(self):
        """Test popcon data lookups"""
        self.assertTrue(self.dispatcher.popcon('libc6'))
        self.assertRaises(PackageNotFoundError, self.dispatcher.popcon, 'nosuchpackage')

    def testUploads(self):
        """Test upload/maintainer data lookups"""
        self.assertTrue(self.dispatcher.uploads('glibc', max=10))
        self.assertTrue(self.dispatcher.uploads('glibc'))
        self.assertTrue(self.dispatcher.uploads('eglibc', '2.9-11'))
        self.assertRaises(PackageNotFoundError, self.dispatcher.uploads, 'nosuchpackage')
        self.assertRaises(PackageNotFoundError, self.dispatcher.uploads, 'glibc', 'nosuchversion')
        self.assertRaises(PackageNotFoundError, self.dispatcher.uploads, 'libc6')  # only does source packages
        p = self.udd.BindSourcePackage('glibc', 'sid')
        self.assertTrue(self.dispatcher.uploads(p), 'Check uploads with bind to source package failed')
        p = self.udd.BindSourcePackage('libc6', 'sid')
        self.assertTrue(self.dispatcher.uploads(p), 'Check uploads with bind to source package via bin2src failed')

    @unittest.skipIf(exclude_slow_tests, 'slow test')
    def testCheckDeps(self):
        """Test dependency testing for packages"""
        # TODO: it would be nice to actually test the accuracy of the tests
        self.assertTrue(self.dispatcher.checkdeps('libc6', 'sid', 'i386', ['depends']))
        self.assertTrue(self.dispatcher.checkdeps('libc6', 'sid', 'i386', ['depends', 'recommends', 'suggests']))
        self.assertTrue(self.dispatcher.checkdeps('cbedic', 'sid', 'i386', ['suggests']), 'broken relations not handled correctly')
        self.assertRaises(PackageNotFoundError, self.dispatcher.checkdeps, 'nosuchpackage', 'squeeze', 'i386', ['depends'])

    @unittest.skipIf(exclude_slow_tests, 'slow test')
    def testCheckInstall(self):
        """Test installability for packages"""
        # TODO: it would be nice to actually test the accuracy of the tests
        self.assertTrue(self.dispatcher.checkInstall('libc6', 'sid', 'i386', False))
        self.assertTrue(self.dispatcher.checkInstall('perl', 'sid', 'i386', True))
        #self.assertTrue(self.dispatcher.checkInstall('openjdk-6-jre-headless', 'lenny', 'i386', False))
        #self.assertTrue(self.dispatcher.checkInstall('openjdk-6-jre-headless', 'lenny', 'i386', True))
        self.assertRaises(PackageNotFoundError, self.dispatcher.checkInstall, 'nosuchpackage', 'sid', 'i386', True)

    @unittest.skipIf(exclude_slow_tests, 'slow test')
    def testWhy(self):
        """Test existence of package dependency chains"""
        # TODO: it would be nice to actually test the accuracy of the tests
        self.assertTrue(self.dispatcher.why('dpkg', 'libc6', 'squeeze', 'i386', False))
        self.assertEqual(self.dispatcher.why('dpkg', 'dolphin', 'squeeze','i386', False), [])
        self.assertEqual(self.dispatcher.why('dpkg', 'libc6-i686', 'squeeze', 'i386', False), [])
        self.assertTrue(self.dispatcher.why('dpkg', 'libc6-i686', 'squeeze', 'i386', True))
        self.assertEqual(self.dispatcher.why('dpkg', 'nosuchpackage', 'squeeze', 'i386', False), [])
        self.assertRaises(PackageNotFoundError, self.dispatcher.why, 'nosuchpackage', 'dpkg', 'squeeze', 'i386', False)

    @unittest.skipIf(exclude_slow_tests, 'slow test')
    def testCheckBackport(self):
        """Test 'simple sid backport' procedure on packages"""
        # TODO: it would be nice to actually test the accuracy of the tests
        fr = self.udd.BindRelease(arch='i386', release='sid')

        tr = self.udd.BindRelease(arch='i386', release='squeeze')
        self.assertTrue(self.dispatcher.checkBackport('iceweasel', fr, tr), 'Check [im]possible backport that requires bpo')

        trbp = self.udd.BindRelease(arch='i386',
                        release=self.udd.data.list_dependent_releases('squeeze', suffixes=['backports']))
        self.assertTrue(self.dispatcher.checkBackport('libxfont1', fr, trbp), 'Check possible backport that requires bpo')

        tro = self.udd.BindRelease(arch='i386', release="squeeze")
        self.assertTrue(self.dispatcher.checkBackport('gcc', fr, tro), 'Check impossible backport')

        self.assertTrue(self.dispatcher.checkBackport('openjdk-6', fr, tr), 'Check resolution of arch-dependent build-deps')

        self.assertTrue(self.dispatcher.checkBackport('pyxplot', fr, tr), 'Check resolution of virtual build-deps')

        self.assertTrue(self.dispatcher.checkBackport('libv4l-0', fr, tr), 'Check resolution of virtual build-deps')

        self.assertRaises(PackageNotFoundError, self.dispatcher.checkBackport, 'nosuchpackage', fr, tr)
Example #13
0
class RelationshipStatusTests(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()

    def tearDown(self):
        self.udd = None

    def testPackageSets(self):
        release = self.udd.BindRelease(arch="i386", release="sid")
        s = RelationshipStatus()
        s.good.append(release.Package('dpkg').DependsList()[0])
        s.good.append(release.Package('dpkg').DependsList()[0])
        self.assertTrue(s.PackageSets())
        self.assertTrue(len(s.PackageSets().good) == 1)
        self.assertTrue(len(s.PackageSets().bad) == 0)
        s.good.append(release.Package('perl').DependsList()[0])
        s.bad.append(release.Package('python').DependsList()[0])
        self.assertTrue(s.PackageSets())
        self.assertTrue(len(s.PackageSets().good) == 2)
        self.assertTrue(len(s.PackageSets().bad) == 1)

    def testExtend(self):
        s = RelationshipStatus()
        s.good.append('pkg')
        s2 = RelationshipStatus()
        s2.good.append('pkg2')
        s2.bad.append('pkg3')
        s.extend(s2)
        self.assertTrue(len(s.good) == 2)
        self.assertTrue(len(s.bad) == 1)

    def testSwap(self):
        s = RelationshipStatus()
        s.good.extend(['pkg1', 'pkg2'])
        self.assertTrue(s.satisfied())
        s.bad.extend(['pkg3'])
        self.assertFalse(s.satisfied())
        s = RelationshipStatus()
        s.unchecked.extend(['pkg1', 'pkg2'])
        self.assertFalse(s.satisfied())
        s = RelationshipStatus()
        s.bad.extend(['pkg1', 'pkg2'])
        self.assertFalse(s.satisfied())

    def testSatisfied(self):
        s = RelationshipStatus()
        s.good.extend(['pkg1', 'pkg2'])
        s.bad.extend(['pkg3'])
        self.assertTrue(len(s.good) == 2)
        self.assertTrue(len(s.bad) == 1)
        s.swap()
        self.assertTrue(len(s.good) == 1)
        self.assertTrue(len(s.bad) == 2)

    def testStr(self):
        release = self.udd.BindRelease(arch="i386", release="squeeze")
        s = RelationshipStatus()
        s.good.extend(release.Package('dpkg').DependsList())
        #self.assertTrue(unicode(s))
        self.assertTrue(str(s))

        release = self.udd.BindRelease(arch="i386", release="squeeze")
        s = RelationshipStatus()
        s.good.extend(release.Package('dpkg').DependsList())
        s.bad.extend(release.Package('python').DependsList())
        s.unchecked.extend(release.Package('ruby').DependsList())
        #self.assertTrue(unicode(s))
        self.assertTrue(str(s))

        release = self.udd.BindRelease(arch="i386", release="squeeze")
        s = RelationshipStatus()
        s.good.extend(release.Package('dpkg').DependsList())
        s2 = RelationshipStatus()
        s2.good.extend(release.Package('perl').DependsList())
        s.good[0].status = s2
        s3 = RelationshipStatus()
        s3.good.extend(release.Package('python').DependsList())
        s2.good[0].status = s3
        #self.assertTrue(unicode(s))
        self.assertTrue(str(s))

    def testNonzero(self):
        s = RelationshipStatus()
        self.assertFalse(s)
        s.good.append('pkg')
        self.assertTrue(s)
        s = RelationshipStatus()
        s.bad.append('pkg')
        self.assertTrue(s)
        s = RelationshipStatus()
        s.unchecked.append('pkg')
        self.assertTrue(s)
        s = RelationshipStatus()
        s.good.append('pkg')
        s.bad.append('pkg')
        s.unchecked.append('pkg')
        self.assertTrue(s)
Example #14
0
class BuildDepStatusTests(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()

    def tearDown(self):
        self.udd = None

    def testInit(self):
        self.assertTrue(BuildDepStatus())
        self.assertTrue(
            BuildDepStatus(bd=RelationshipStatus(), bdi=RelationshipStatus()))

    def testAllFound(self):
        release = self.udd.BindRelease(arch="i386", release="sid")
        checker = Checker(release)
        p = release.Source("glibc")
        bdstatus = BuildDepStatus(bd=checker.CheckRelationshipOptionsList(
            p.BuildDependsList()),
                                  bdi=checker.CheckRelationshipOptionsList(
                                      p.BuildDependsIndepList()))
        self.assertTrue(bdstatus.AllFound())

        release = self.udd.BindRelease(arch="kfreebsd-amd64", release="sid")
        checker = Checker(release)
        p = release.Source(
            "fuse-umfuse-fat")  # has been BD-uninstallable since 2009
        bdstatus = BuildDepStatus(bd=checker.CheckRelationshipOptionsList(
            p.BuildDependsList()),
                                  bdi=checker.CheckRelationshipOptionsList(
                                      p.BuildDependsIndepList()))
        self.assertFalse(bdstatus.AllFound())

    def testReleaseMap(self):
        release = self.udd.BindRelease(arch="i386", release="sid")
        checker = Checker(release)
        p = release.Source("glibc")
        bdstatus = BuildDepStatus(bd=checker.CheckRelationshipOptionsList(
            p.BuildDependsList()),
                                  bdi=checker.CheckRelationshipOptionsList(
                                      p.BuildDependsIndepList()))
        m = bdstatus.ReleaseMap()
        self.assertEqual(sorted(m.keys()), ['archignore', 'sid', 'virtual'])
        self.assertTrue(len(m['sid']) > 1)

        release = self.udd.BindRelease(
            arch="i386", release=["squeeze", "squeeze-backports"])
        checker = Checker(release)
        p = release.Source("libxfont1", version='1:1.4.3', operator='>>')
        bdstatus = BuildDepStatus(bd=checker.CheckRelationshipOptionsList(
            p.BuildDependsList()),
                                  bdi=checker.CheckRelationshipOptionsList(
                                      p.BuildDependsIndepList()))
        m = bdstatus.ReleaseMap()
        self.assertEqual(sorted(m.keys()), ['squeeze', 'squeeze-backports'])

    def testStr(self):
        bdstatus = BuildDepStatus()
        self.assertTrue(str(bdstatus))

        release = self.udd.BindRelease(arch="i386", release="sid")
        checker = Checker(release)
        p = release.Source("glibc")
        bdstatus = BuildDepStatus(bd=checker.CheckRelationshipOptionsList(
            p.BuildDependsList()),
                                  bdi=checker.CheckRelationshipOptionsList(
                                      p.BuildDependsIndepList()))
        self.assertTrue(str(bdstatus))
Example #15
0
class RelationshipOptionsListTests(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()

    def tearDown(self):
        self.udd = None

    def testReleaseMap(self):
        """Test mapping a list of RelationshipOptions into a releases/packages dict"""
        # non-existent package should be unresolvable
        rl = RelationshipOptionsList()
        rl.append(RelationshipOptions("no-such-package"))
        self.assertTrue(rl)
        self.assertTrue(rl.ReleaseMap()['unresolved'])

        # resolver not run so all relationships are "unresolved"
        p = self.udd.BindPackage("libc6", "sid", "i386")
        rl = p.RelationshipOptionsList("depends")
        self.assertTrue(rl)
        self.assertTrue(rl.ReleaseMap()['unresolved'])

        release = self.udd.BindRelease(arch="i386", release="sid")
        checker = Checker(release)

        # all resolvable, options, versioned deps
        p = release.Package("build-essential")
        rl = checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList("depends"))
        self.assertTrue(rl.good.ReleaseMap())
        self.assertTrue(rl.good.ReleaseMap()['sid'])
        self.assertFalse('unresolved' in rl.good.ReleaseMap())

        # all resolvable, virtual packages
        p = release.Package("debbugs")
        rl = checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList("depends"))
        self.assertTrue(rl.good.ReleaseMap())
        self.assertTrue(rl.good.ReleaseMap()['sid'])
        self.assertFalse('unresolved' in rl.good.ReleaseMap())
        self.assertTrue('virtual' in rl.good.ReleaseMap())
        self.assertTrue(rl.good.ReleaseMap()['virtual'])
        #print rl.good.ReleaseMap()
        #print rl

        # some arch-specific dependencies
        p = release.Source("glibc")
        rl = checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList("build_depends"))
        self.assertTrue(rl.good.ReleaseMap())
        self.assertTrue(rl.good.ReleaseMap()['sid'])
        self.assertTrue('archignore' in rl.good.ReleaseMap())
        self.assertTrue(rl.good.ReleaseMap()['archignore'])

    def testPackageSet(self):
        """Test reducing a list of RelationshipOptions into list of packages"""
        # resolver not run so all relationships are unsatisified
        p = self.udd.BindPackage("libc6", "sid", "i386")
        rl = p.RelationshipOptionsList("depends")
        #print rl.PackageSet()
        self.assertTrue(rl.PackageSet())

        release = self.udd.BindRelease(arch="i386", release="sid")
        checker = Checker(release)

        # all resolvable, options, versioned deps
        p = release.Package("build-essential")
        rl = checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList("depends"))
        #print rl.good.PackageSet()
        self.assertTrue(rl.good.PackageSet())
        self.assertFalse(rl.bad.PackageSet())

        # all resolvable, virtual packages
        p = release.Package("debbugs")
        rl = checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList("depends"))
        #print rl.good.PackageSet()
        self.assertTrue(rl.good.PackageSet())
        self.assertFalse(rl.bad.PackageSet())

    def testStr(self):
        # non-existent package
        rl = RelationshipOptionsList()
        rl.append(RelationshipOptions("no-such-package"))
        self.assertTrue(str(rl))

        # list of packages
        release = self.udd.BindRelease(arch="i386", release="sid")
        p = release.Package("build-essential")
        rl = p.RelationshipOptionsList("depends")
        self.assertTrue(str(rl))
class CheckerTests(unittest.TestCase):
    def setUp(self):
        self.udd = Udd()
        self.checker = Checker(self.udd.BindRelease())  # i386 stable
        self.sidchecker = Checker(self.udd.BindRelease(release='sid'))  # i386

    def tearDown(self):
        self.udd = None
        self.checker = None

    def testInit(self):
        self.assertRaises(TypeError, Checker, None)

    def testCheckRelationsList(self):
        """Test checking the dependencies of a package"""
        # FIXME: really need to check that the results are correct
        # package with no dependencies
        p = self.udd.BindPackage(package="libjiu-java", release="sid")
        r = self.checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList('depends'))
        self.assertTrue(r != None)
        # package with one dependency
        p = self.udd.BindPackage(package="patch")
        r = self.checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList('depends'))
        self.assertTrue(r)
        # package with lots of dependencies
        p = self.udd.BindPackage(package="perl")
        r = self.checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList('depends'))
        self.assertTrue(r)
        # package with lots of dependencies including options
        p = self.udd.BindPackage(package="php5")
        r = self.checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList('depends'))
        self.assertTrue(r)
        # package with dependencies including virtual package with no alternatives listed
        p = self.udd.BindPackage(package="bcron-run")
        r = self.checker.CheckRelationshipOptionsList(
            p.RelationshipOptionsList('depends'))
        self.assertTrue(r)
        # bad input object
        r = self.checker.CheckRelationshipOptionsList(None)
        self.assertTrue(not r is None)

    def testCheckRelationArch(self):
        """Check architecture-specific dependency syntax"""
        # note: self.checker is configured to be i386
        # nothing specified implies everything satisfies
        self.assertTrue(self.checker.CheckRelationArch(""))
        self.assertTrue(self.checker.CheckRelationArch(None))
        self.assertTrue(self.checker.CheckRelationArch([]))
        # single options
        self.assertTrue(self.checker.CheckRelationArch(["i386"]))
        self.assertFalse(self.checker.CheckRelationArch(["amd64"]))
        self.assertTrue(self.checker.CheckRelationArch(["!amd64"]))
        # multiple options
        self.assertTrue(
            self.checker.CheckRelationArch(["!alpha", "!amd64", "!ia64"]))
        self.assertFalse(
            self.checker.CheckRelationArch(
                ["!alpha", "!amd64", "!i386", "!ia64"]))
        # wildcard archs
        self.assertTrue(self.checker.CheckRelationArch(["linux-any"]))
        self.assertTrue(self.checker.CheckRelationArch(["any-i386"]))
        self.assertFalse(self.checker.CheckRelationArch(["kfreebsd-any"]))
        self.assertTrue(self.checker.CheckRelationArch(["!kfreebsd-i386"]))
        self.assertFalse(
            self.checker.CheckRelationArch(["!linux-any", "!hurd-any"]))
        # bad input
        self.assertRaises(TypeError, self.checker.CheckRelationArch, 1)

    def testRelationSatisfied(self):
        """Check whether relationships can be satisfied correctly"""
        # NOTE: self.checker is an i386 instance
        # >>
        r = Relationship(relation="libc6 (>> 1.0.1)")
        self.assertTrue(self.checker.RelationSatisfied(r))
        r = Relationship(relation="libc6 (>> 10:1.0.1)")
        self.assertFalse(self.checker.RelationSatisfied(r))
        # <<
        r = Relationship(relation="libc6 (<< 10.0.1)")
        self.assertTrue(self.checker.RelationSatisfied(r))
        r = Relationship(relation="libc6 (<< 1.0.1)")
        self.assertFalse(self.checker.RelationSatisfied(r))
        # =
        r = Relationship(relation="spline (= 1.2-1)")
        self.assertTrue(self.checker.RelationSatisfied(r))
        r = Relationship(relation="dpkg (= 1.14.1)")
        self.assertFalse(self.checker.RelationSatisfied(r))
        # >=
        r = Relationship(relation="spline (>= 1.1-11)")
        self.assertTrue(self.checker.RelationSatisfied(r))
        r = Relationship(relation="dpkg (>= 1.12.0)")
        self.assertTrue(self.checker.RelationSatisfied(r))
        # <=
        r = Relationship(relation="dpkg (<= 1.14.1)")
        self.assertFalse(self.checker.RelationSatisfied(r))
        r = Relationship(relation="dpkg (<= 5:1.14.27)")
        self.assertTrue(self.checker.RelationSatisfied(r))
        # simple relations
        r = Relationship(relation="libc6")
        self.assertTrue(self.checker.RelationSatisfied(r))
        r = Relationship(relation="no-such-package")
        self.assertFalse(self.checker.RelationSatisfied(r))
        # arch specific
        r = Relationship(relation="libc6 [i386]")
        self.assertTrue(self.checker.RelationSatisfied(r))
        r = Relationship(relation="libc6.1 [amd64]")  # irrelevant for i386
        self.assertTrue(self.checker.RelationSatisfied(r))
        r = Relationship(
            relation="no-such-package [amd64]")  # irrelevant for i386
        self.assertTrue(self.checker.RelationSatisfied(r))
        r = Relationship(relation="no-such-package [i386]")
        self.assertFalse(self.checker.RelationSatisfied(r))

    def testCheck(self):
        # package with no dependencies
        c = self.checker.Check(package="when")
        self.assertTrue(not c is None)
        self.assertTrue(len(c.good) == 0)
        self.assertTrue(len(c.bad) == 0)
        # known good package
        c = self.checker.Check(package="libc6")
        self.assertTrue(c)
        self.assertTrue(len(c.good) > 0)
        self.assertTrue(len(c.bad) == 0)
        # known bad package [cbedic has unsatisfied suggests]
        c = self.sidchecker.Check(package="cbedic", relation='suggests')
        self.assertTrue(c)
        self.assertTrue(len(c.bad) > 0)
        # non-existent package
        self.assertRaises(PackageNotFoundError,
                          self.checker.Check,
                          package="no-such-package")
        # conflicts in a package
        c = self.checker.Check(package="libc6", relation="conflicts")
        self.assertTrue(c)
        self.assertTrue(len(c.good) > 0)
        self.assertTrue(len(c.bad) == 0)
        # non-existent conflicts in a package
        c = self.checker.Check(package="libapr1", relation="conflicts")
        self.assertTrue(c)
        self.assertTrue(len(c.good) > 0)
        self.assertTrue(len(c.bad) == 0)
 def setUp(self):
     self.udd = Udd()
     self.checker = Checker(self.udd.BindRelease())  # i386 stable
     self.sidchecker = Checker(self.udd.BindRelease(release='sid'))  # i386
 def testPassConfig(self):
     """Test loading a config file manually"""
     config = Config()
     self.assertTrue(Udd(config=config))