From 3b23463156a4e119c520e0e45df09d04b815bebe Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 17 Jul 2009 20:25:17 +0200 Subject: tests/test_cache_invocation.py: Move here from old. --- tests/test_cache_invocation.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/test_cache_invocation.py (limited to 'tests/test_cache_invocation.py') diff --git a/tests/test_cache_invocation.py b/tests/test_cache_invocation.py new file mode 100644 index 00000000..9d34891d --- /dev/null +++ b/tests/test_cache_invocation.py @@ -0,0 +1,32 @@ +#!/usr/bin/python +import apt_pkg + +import unittest + +class TestCache(unittest.TestCase): + + def setUp(self): + apt_pkg.init_config() + apt_pkg.init_system() + + def test_wrong_invocation(self): + """wrongly invoke GetCache() rather than GetDepCache().""" + apt_cache = apt_pkg.Cache(apt_pkg.OpProgress()) + if apt_pkg._COMPAT_0_7: + self.assertRaises(ValueError, apt_pkg.Cache, apt_cache) + self.assertRaises(ValueError, apt_pkg.Cache, + apt_pkg.AcquireProgress()) + self.assertRaises(ValueError, apt_pkg.Cache, 0) + else: + self.assertRaises(TypeError, apt_pkg.Cache, apt_cache) + self.assertRaises(TypeError, apt_pkg.Cache, + apt_pkg.AcquireProgress()) + self.assertRaises(TypeError, apt_pkg.Cache, 0) + + def test_proper_invocation(self): + """Invoke it the right way.""" + apt_cache = apt_pkg.Cache(apt_pkg.OpProgress()) + apt_depcache = apt_pkg.DepCache(apt_cache) + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From c88f6ea1f3d2cca1ff7f1a22f51318ea3f28c01f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 17 Jul 2009 20:53:45 +0200 Subject: tests: Import more tests from tests/old. --- tests/__init__.py | 2 +- tests/data/aptsources/sources.list | 6 + .../data/aptsources/sources.list.testDistribution | 13 ++ tests/data/aptsources_ports/sources.list | 59 ++++++++ tests/old/data/sources.list | 6 - tests/old/data/sources.list.testDistribution | 13 -- tests/old/test-data-ports/sources.list | 59 -------- tests/old/test_aptsources.py | 151 -------------------- tests/old/test_aptsources_ports.py | 41 ------ tests/test_aptsources.py | 155 +++++++++++++++++++++ tests/test_aptsources_ports.py | 39 ++++++ tests/test_cache_invocation.py | 8 +- 12 files changed, 278 insertions(+), 274 deletions(-) create mode 100644 tests/data/aptsources/sources.list create mode 100644 tests/data/aptsources/sources.list.testDistribution create mode 100644 tests/data/aptsources_ports/sources.list delete mode 100644 tests/old/data/sources.list delete mode 100644 tests/old/data/sources.list.testDistribution delete mode 100644 tests/old/test-data-ports/sources.list delete mode 100644 tests/old/test_aptsources.py delete mode 100644 tests/old/test_aptsources_ports.py create mode 100644 tests/test_aptsources.py create mode 100644 tests/test_aptsources_ports.py (limited to 'tests/test_cache_invocation.py') diff --git a/tests/__init__.py b/tests/__init__.py index 8b137891..792d6005 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1 @@ - +# diff --git a/tests/data/aptsources/sources.list b/tests/data/aptsources/sources.list new file mode 100644 index 00000000..5481d4f0 --- /dev/null +++ b/tests/data/aptsources/sources.list @@ -0,0 +1,6 @@ +# comment 1 +deb http://de.archive.ubuntu.com/ubuntu/ edgy main +# comment 2 +deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted +# comment 3 +deb http://de.archive.ubuntu.com/ubuntu/ edgy universe \ No newline at end of file diff --git a/tests/data/aptsources/sources.list.testDistribution b/tests/data/aptsources/sources.list.testDistribution new file mode 100644 index 00000000..4ff0fae6 --- /dev/null +++ b/tests/data/aptsources/sources.list.testDistribution @@ -0,0 +1,13 @@ +deb http://de.archive.ubuntu.com/ubuntu/ hardy main +deb http://de.archive.ubuntu.com/ubuntu/ hardy restricted +deb http://de.archive.ubuntu.com/ubuntu/ hardy universe +deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates universe multiverse +deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates restricted +deb http://de.archive.ubuntu.com/ubuntu/ hardy-security main +deb http://de.archive.ubuntu.com/ubuntu/ hardy-security multiverse +deb http://ftp.debian.org/debian sid main +deb http://ubuntu.cs.uaf.edu/ubuntu/ hardy main +deb http://ubuntu.cs.uaf.edu/ubuntu/ hardy-backports main +deb http://archive.ubuntu.com/ubuntu/ intrepid main +deb cdrom:[Ubuntu 8.10 _Intrepid Ibex_ - Alpha]/ intrepid main +deb cdrom:[Ubuntu 8.04 _Hardy Heron_] hardy main diff --git a/tests/data/aptsources_ports/sources.list b/tests/data/aptsources_ports/sources.list new file mode 100644 index 00000000..a6b2f6ed --- /dev/null +++ b/tests/data/aptsources_ports/sources.list @@ -0,0 +1,59 @@ +# +# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted + +# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted +# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to +# newer versions of the distribution. + +deb http://ports.ubuntu.com/ubuntu-ports/ hardy main restricted +deb-src http://archive.ubuntu.com/ubuntu hardy main restricted + +## Major bug fix updates produced after the final release of the +## distribution. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates main restricted +deb-src http://archive.ubuntu.com/ubuntu hardy-updates main restricted + +## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +## team, and may not be under a free licence. Please satisfy yourself as to +## your rights to use the software. Also, please note that software in +## universe WILL NOT receive any review or updates from the Ubuntu security +## team. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy universe +deb-src http://archive.ubuntu.com/ubuntu hardy universe +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates universe +deb-src http://archive.ubuntu.com/ubuntu hardy-updates universe + +## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +## team, and may not be under a free licence. Please satisfy yourself as to +## your rights to use the software. Also, please note that software in +## multiverse WILL NOT receive any review or updates from the Ubuntu +## security team. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy multiverse +deb-src http://archive.ubuntu.com/ubuntu hardy multiverse +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates multiverse +deb-src http://archive.ubuntu.com/ubuntu hardy-updates multiverse + +## Uncomment the following two lines to add software from the 'backports' +## repository. +## N.B. software from this repository may not have been tested as +## extensively as that contained in the main release, although it includes +## newer versions of some applications which may provide useful features. +## Also, please note that software in backports WILL NOT receive any review +## or updates from the Ubuntu security team. +# deb http://ports.ubuntu.com/ubuntu-ports/ hardy-backports main restricted universe multiverse +# deb-src http://archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse + +## Uncomment the following two lines to add software from Canonical's +## 'partner' repository. This software is not part of Ubuntu, but is +## offered by Canonical and the respective vendors as a service to Ubuntu +## users. +# deb http://archive.canonical.com/ubuntu hardy partner +# deb-src http://archive.canonical.com/ubuntu hardy partner + +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse +deb-src http://archive.ubuntu.com/ubuntu/ hardy-proposed restricted main multiverse universe diff --git a/tests/old/data/sources.list b/tests/old/data/sources.list deleted file mode 100644 index 5481d4f0..00000000 --- a/tests/old/data/sources.list +++ /dev/null @@ -1,6 +0,0 @@ -# comment 1 -deb http://de.archive.ubuntu.com/ubuntu/ edgy main -# comment 2 -deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted -# comment 3 -deb http://de.archive.ubuntu.com/ubuntu/ edgy universe \ No newline at end of file diff --git a/tests/old/data/sources.list.testDistribution b/tests/old/data/sources.list.testDistribution deleted file mode 100644 index 0f40e85a..00000000 --- a/tests/old/data/sources.list.testDistribution +++ /dev/null @@ -1,13 +0,0 @@ -deb http://de.archive.ubuntu.com/ubuntu/ hardy main -deb http://de.archive.ubuntu.com/ubuntu/ hardy restricted -deb http://de.archive.ubuntu.com/ubuntu/ hardy universe -deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates universe multiverse -deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates restricted -deb http://de.archive.ubuntu.com/ubuntu/ hardy-security main -deb http://de.archive.ubuntu.com/ubuntu/ hardy-security multiverse -deb http://ftp.debian.org/debian sid main -deb http://ubuntu.cs.uaf.edu/ubuntu/ hardy main -deb http://ubuntu.cs.uaf.edu/ubuntu/ hardy-backports main -deb http://archive.ubuntu.com/ubuntu/ intrepid main -deb cdrom:[Ubuntu 8.10 _Intrepid Ibex_ - Alpha]/ intrepid main -deb cdrom:[Ubuntu 8.04 _Hardy Heron_] hardy main \ No newline at end of file diff --git a/tests/old/test-data-ports/sources.list b/tests/old/test-data-ports/sources.list deleted file mode 100644 index a6b2f6ed..00000000 --- a/tests/old/test-data-ports/sources.list +++ /dev/null @@ -1,59 +0,0 @@ -# -# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted - -# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted -# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to -# newer versions of the distribution. - -deb http://ports.ubuntu.com/ubuntu-ports/ hardy main restricted -deb-src http://archive.ubuntu.com/ubuntu hardy main restricted - -## Major bug fix updates produced after the final release of the -## distribution. -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates main restricted -deb-src http://archive.ubuntu.com/ubuntu hardy-updates main restricted - -## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu -## team, and may not be under a free licence. Please satisfy yourself as to -## your rights to use the software. Also, please note that software in -## universe WILL NOT receive any review or updates from the Ubuntu security -## team. -deb http://ports.ubuntu.com/ubuntu-ports/ hardy universe -deb-src http://archive.ubuntu.com/ubuntu hardy universe -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates universe -deb-src http://archive.ubuntu.com/ubuntu hardy-updates universe - -## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu -## team, and may not be under a free licence. Please satisfy yourself as to -## your rights to use the software. Also, please note that software in -## multiverse WILL NOT receive any review or updates from the Ubuntu -## security team. -deb http://ports.ubuntu.com/ubuntu-ports/ hardy multiverse -deb-src http://archive.ubuntu.com/ubuntu hardy multiverse -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates multiverse -deb-src http://archive.ubuntu.com/ubuntu hardy-updates multiverse - -## Uncomment the following two lines to add software from the 'backports' -## repository. -## N.B. software from this repository may not have been tested as -## extensively as that contained in the main release, although it includes -## newer versions of some applications which may provide useful features. -## Also, please note that software in backports WILL NOT receive any review -## or updates from the Ubuntu security team. -# deb http://ports.ubuntu.com/ubuntu-ports/ hardy-backports main restricted universe multiverse -# deb-src http://archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse - -## Uncomment the following two lines to add software from Canonical's -## 'partner' repository. This software is not part of Ubuntu, but is -## offered by Canonical and the respective vendors as a service to Ubuntu -## users. -# deb http://archive.canonical.com/ubuntu hardy partner -# deb-src http://archive.canonical.com/ubuntu hardy partner - -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted -deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe -deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse -deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse -deb-src http://archive.ubuntu.com/ubuntu/ hardy-proposed restricted main multiverse universe diff --git a/tests/old/test_aptsources.py b/tests/old/test_aptsources.py deleted file mode 100644 index 3761f3ff..00000000 --- a/tests/old/test_aptsources.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env python - -import unittest -import os -import copy -import sys - -sys.path.insert(0, "../") -import apt_pkg -import aptsources -import aptsources.sourceslist -import aptsources.distro - - -class TestAptSources(unittest.TestCase): - - def __init__(self, methodName): - unittest.TestCase.__init__(self, methodName) - apt_pkg.init() - apt_pkg.Config.Set("Dir::Etc", os.getcwd()) - apt_pkg.Config.Set("Dir::Etc::sourceparts", "/xxx") - - def testIsMirror(self): - yes = aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", - "http://de.archive.ubuntu.com") - no = aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", - "http://ftp.debian.org") - self.assertTrue(yes) - self.assertFalse(no) - - def testSourcesListReading(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist", "data/sources.list") - sources = aptsources.sourceslist.SourcesList() - self.assertEqual(len(sources.list), 6) - # test load - sources.list = [] - sources.load("data/sources.list") - self.assertEqual(len(sources.list), 6) - - def testSourcesListAdding(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist", "data/sources.list") - sources = aptsources.sourceslist.SourcesList() - # test to add something that is already there (main) - before = copy.deepcopy(sources) - sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", - "edgy", - ["main"]) - self.assertTrue(sources.list == before.list) - # test to add something that is already there (restricted) - before = copy.deepcopy(sources) - sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", - "edgy", - ["restricted"]) - self.assertTrue(sources.list == before.list) - # test to add something new: multiverse - sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", - "edgy", - ["multiverse"]) - found = False - for entry in sources: - if (entry.type == "deb" and - entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and - entry.dist == "edgy" and - "multiverse" in entry.comps): - found = True - self.assertTrue(found) - # test to add something new: multiverse *and* - # something that is already there - before = copy.deepcopy(sources) - sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", - "edgy", - ["universe", "something"]) - found_universe = 0 - found_something = 0 - for entry in sources: - if (entry.type == "deb" and - entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and - entry.dist == "edgy"): - for c in entry.comps: - if c == "universe": - found_universe += 1 - if c == "something": - found_something += 1 - #print "\n".join([s.str() for s in sources]) - self.assertEqual(found_something, 1) - self.assertEqual(found_universe, 1) - - def testMatcher(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist", "data/sources.list.test" - "Distribution") - sources = aptsources.sourceslist.SourcesList() - distro = aptsources.distro.get_distro() - distro.get_sources(sources) - # test if all suits of the current distro were detected correctly - dist_templates = set() - for s in sources: - if not s.template: - self.fail("source entry '%s' has no matcher" % s) - - def testDistribution(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist", "data/sources.list.test" - "Distribution") - sources = aptsources.sourceslist.SourcesList() - distro = aptsources.distro.get_distro() - distro.get_sources(sources) - # test if all suits of the current distro were detected correctly - dist_templates = set() - for s in sources: - if s.template: - dist_templates.add(s.template.name) - #print dist_templates - for d in ("hardy", "hardy-security", "hardy-updates", "intrepid", - "hardy-backports"): - self.assertTrue(d in dist_templates) - # test enable - comp = "restricted" - distro.enable_component(comp) - found = {} - for entry in sources: - if (entry.type == "deb" and - entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and - "edgy" in entry.dist): - for c in entry.comps: - if c == comp: - if not entry.dist in found: - found[entry.dist] = 0 - found[entry.dist] += 1 - #print "".join([s.str() for s in sources]) - for key in found: - self.assertEqual(found[key], 1) - - # add a not-already available component - comp = "multiverse" - distro.enable_component(comp) - found = {} - for entry in sources: - if (entry.type == "deb" and - entry.template and - entry.template.name == "edgy"): - for c in entry.comps: - if c == comp: - if not entry.dist in found.has_key: - found[entry.dist] = 0 - found[entry.dist] += 1 - #print "".join([s.str() for s in sources]) - for key in found: - self.assertEqual(found[key], 1) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/old/test_aptsources_ports.py b/tests/old/test_aptsources_ports.py deleted file mode 100644 index 09d6e9d9..00000000 --- a/tests/old/test_aptsources_ports.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python - -import unittest - -import os -import copy -import sys - -sys.path.insert(0, "../") -import apt_pkg -import aptsources -import aptsources.sourceslist -import aptsources.distro - - -class TestAptSources(unittest.TestCase): - - def __init__(self, methodName): - unittest.TestCase.__init__(self, methodName) - apt_pkg.init() - apt_pkg.Config.Set("APT::Architecture", "powerpc") - apt_pkg.Config.Set("Dir::Etc", os.path.abspath("test-data-ports")) - apt_pkg.Config.Set("Dir::Etc::sourceparts", "/xxx") - - def testMatcher(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist", "sources.list") - sources = aptsources.sourceslist.SourcesList() - distro = aptsources.distro.get_distro("Ubuntu", "hardy", "desc", - "8.04") - distro.get_sources(sources) - # test if all suits of the current distro were detected correctly - dist_templates = set() - for s in sources: - if not s.line.strip() or s.line.startswith("#"): - continue - if not s.template: - self.fail("source entry '%s' has no matcher" % s) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py new file mode 100644 index 00000000..e5cd1f5a --- /dev/null +++ b/tests/test_aptsources.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python + +import unittest +import os +import copy + +import apt_pkg +import aptsources.sourceslist +import aptsources.distro + + +class TestAptSources(unittest.TestCase): + + def setUp(self): + apt_pkg.init_config() + apt_pkg.init_system() + apt_pkg.config.set("Dir::Etc", os.getcwd()) + apt_pkg.config.set("Dir::Etc::sourceparts", "/xxx") + + def testIsMirror(self): + """Test mirror detection.""" + yes = aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", + "http://de.archive.ubuntu.com") + no = aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", + "http://ftp.debian.org") + self.assertTrue(yes) + self.assertFalse(no) + + def testSourcesListReading(self): + """Test sources.list parsing.""" + apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" + "sources.list") + sources = aptsources.sourceslist.SourcesList() + self.assertEqual(len(sources.list), 6) + # test load + sources.list = [] + sources.load("data/aptsources/sources.list") + self.assertEqual(len(sources.list), 6) + + def testSourcesListAdding(self): + """Test additions to sources.list""" + apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" + "sources.list") + sources = aptsources.sourceslist.SourcesList() + # test to add something that is already there (main) + before = copy.deepcopy(sources) + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["main"]) + self.assertTrue(sources.list == before.list) + # test to add something that is already there (restricted) + before = copy.deepcopy(sources) + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["restricted"]) + self.assertTrue(sources.list == before.list) + # test to add something new: multiverse + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["multiverse"]) + found = False + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "edgy" and + "multiverse" in entry.comps): + found = True + self.assertTrue(found) + # test to add something new: multiverse *and* + # something that is already there + before = copy.deepcopy(sources) + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["universe", "something"]) + found_universe = 0 + found_something = 0 + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "edgy"): + for c in entry.comps: + if c == "universe": + found_universe += 1 + if c == "something": + found_something += 1 + #print "\n".join([s.str() for s in sources]) + self.assertEqual(found_something, 1) + self.assertEqual(found_universe, 1) + + def testMatcher(self): + """Test matcher (detection of what is what in sources.list)""" + apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" + "sources.list.testDistribution") + sources = aptsources.sourceslist.SourcesList() + distro = aptsources.distro.get_distro() + distro.get_sources(sources) + # test if all suits of the current distro were detected correctly + dist_templates = set() + for s in sources: + if not s.template: + self.fail("source entry '%s' has no matcher" % s) + + def testDistribution(self): + """Test distribution detection.""" + apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" + "sources.list.testDistribution") + sources = aptsources.sourceslist.SourcesList() + distro = aptsources.distro.get_distro() + distro.get_sources(sources) + # test if all suits of the current distro were detected correctly + dist_templates = set() + for s in sources: + if s.template: + dist_templates.add(s.template.name) + #print dist_templates + for d in ("hardy", "hardy-security", "hardy-updates", "intrepid", + "hardy-backports"): + self.assertTrue(d in dist_templates) + # test enable + comp = "restricted" + distro.enable_component(comp) + found = {} + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + "edgy" in entry.dist): + for c in entry.comps: + if c == comp: + if not entry.dist in found: + found[entry.dist] = 0 + found[entry.dist] += 1 + #print "".join([s.str() for s in sources]) + for key in found: + self.assertEqual(found[key], 1) + + # add a not-already available component + comp = "multiverse" + distro.enable_component(comp) + found = {} + for entry in sources: + if (entry.type == "deb" and + entry.template and + entry.template.name == "edgy"): + for c in entry.comps: + if c == comp: + if not entry.dist in found.has_key: + found[entry.dist] = 0 + found[entry.dist] += 1 + #print "".join([s.str() for s in sources]) + for key in found: + self.assertEqual(found[key], 1) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_aptsources_ports.py b/tests/test_aptsources_ports.py new file mode 100644 index 00000000..5594ec0b --- /dev/null +++ b/tests/test_aptsources_ports.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +import os +import unittest + + +import apt_pkg +import aptsources.sourceslist +import aptsources.distro + + +class TestAptSourcesPorts(unittest.TestCase): + """Test aptsources on ports.ubuntu.com.""" + + def setUp(self): + apt_pkg.init_config() + apt_pkg.init_system() + apt_pkg.config.set("APT::Architecture", "powerpc") + apt_pkg.config.set("Dir::Etc", + os.path.abspath("data/aptsources_ports")) + apt_pkg.config.set("Dir::Etc::sourceparts", "/xxx") + + def testMatcher(self): + """Test matcher.""" + apt_pkg.config.set("Dir::Etc::sourcelist", "sources.list") + sources = aptsources.sourceslist.SourcesList() + distro = aptsources.distro.get_distro("Ubuntu", "hardy", "desc", + "8.04") + distro.get_sources(sources) + # test if all suits of the current distro were detected correctly + dist_templates = set() + for s in sources: + if not s.line.strip() or s.line.startswith("#"): + continue + if not s.template: + self.fail("source entry '%s' has no matcher" % s) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_cache_invocation.py b/tests/test_cache_invocation.py index 9d34891d..39dae8f4 100644 --- a/tests/test_cache_invocation.py +++ b/tests/test_cache_invocation.py @@ -1,16 +1,18 @@ #!/usr/bin/python +import unittest + import apt_pkg -import unittest class TestCache(unittest.TestCase): + """Test invocation of apt_pkg.Cache()""" def setUp(self): apt_pkg.init_config() apt_pkg.init_system() def test_wrong_invocation(self): - """wrongly invoke GetCache() rather than GetDepCache().""" + """Test wrong invocation of apt_pkg.Cache(apt_pkg.Cache())""" apt_cache = apt_pkg.Cache(apt_pkg.OpProgress()) if apt_pkg._COMPAT_0_7: self.assertRaises(ValueError, apt_pkg.Cache, apt_cache) @@ -24,7 +26,7 @@ class TestCache(unittest.TestCase): self.assertRaises(TypeError, apt_pkg.Cache, 0) def test_proper_invocation(self): - """Invoke it the right way.""" + """Test correct invocation of apt_pkg.DepCache(apt_pkg.Cache()).""" apt_cache = apt_pkg.Cache(apt_pkg.OpProgress()) apt_depcache = apt_pkg.DepCache(apt_cache) -- cgit v1.2.3 From 4ae2f454115f3ab758ef9bf0b1f31e5b04ac934a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 23 Jul 2009 15:09:08 +0200 Subject: tests: Prefix all docstring with the name of the file. --- tests/test_aptsources.py | 11 ++++++----- tests/test_aptsources_ports.py | 2 +- tests/test_cache_invocation.py | 4 ++-- tests/test_hashes.py | 20 ++++++++++---------- 4 files changed, 19 insertions(+), 18 deletions(-) (limited to 'tests/test_cache_invocation.py') diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index e5cd1f5a..0ae05bf3 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -18,7 +18,7 @@ class TestAptSources(unittest.TestCase): apt_pkg.config.set("Dir::Etc::sourceparts", "/xxx") def testIsMirror(self): - """Test mirror detection.""" + """aptsources: Test mirror detection.""" yes = aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", "http://de.archive.ubuntu.com") no = aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", @@ -27,7 +27,7 @@ class TestAptSources(unittest.TestCase): self.assertFalse(no) def testSourcesListReading(self): - """Test sources.list parsing.""" + """aptsources: Test sources.list parsing.""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list") sources = aptsources.sourceslist.SourcesList() @@ -38,7 +38,7 @@ class TestAptSources(unittest.TestCase): self.assertEqual(len(sources.list), 6) def testSourcesListAdding(self): - """Test additions to sources.list""" + """aptsources: Test additions to sources.list""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list") sources = aptsources.sourceslist.SourcesList() @@ -88,7 +88,7 @@ class TestAptSources(unittest.TestCase): self.assertEqual(found_universe, 1) def testMatcher(self): - """Test matcher (detection of what is what in sources.list)""" + """aptsources: Test matcher""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list.testDistribution") sources = aptsources.sourceslist.SourcesList() @@ -101,7 +101,7 @@ class TestAptSources(unittest.TestCase): self.fail("source entry '%s' has no matcher" % s) def testDistribution(self): - """Test distribution detection.""" + """aptsources: Test distribution detection.""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list.testDistribution") sources = aptsources.sourceslist.SourcesList() @@ -152,4 +152,5 @@ class TestAptSources(unittest.TestCase): if __name__ == "__main__": + os.chdir(os.path.dirname(__file__)) unittest.main() diff --git a/tests/test_aptsources_ports.py b/tests/test_aptsources_ports.py index 5594ec0b..f837585b 100644 --- a/tests/test_aptsources_ports.py +++ b/tests/test_aptsources_ports.py @@ -20,7 +20,7 @@ class TestAptSourcesPorts(unittest.TestCase): apt_pkg.config.set("Dir::Etc::sourceparts", "/xxx") def testMatcher(self): - """Test matcher.""" + """aptsources_ports: Test matcher.""" apt_pkg.config.set("Dir::Etc::sourcelist", "sources.list") sources = aptsources.sourceslist.SourcesList() distro = aptsources.distro.get_distro("Ubuntu", "hardy", "desc", diff --git a/tests/test_cache_invocation.py b/tests/test_cache_invocation.py index 39dae8f4..ff86b102 100644 --- a/tests/test_cache_invocation.py +++ b/tests/test_cache_invocation.py @@ -12,7 +12,7 @@ class TestCache(unittest.TestCase): apt_pkg.init_system() def test_wrong_invocation(self): - """Test wrong invocation of apt_pkg.Cache(apt_pkg.Cache())""" + """cache_invocation: Test wrong invocation.""" apt_cache = apt_pkg.Cache(apt_pkg.OpProgress()) if apt_pkg._COMPAT_0_7: self.assertRaises(ValueError, apt_pkg.Cache, apt_cache) @@ -26,7 +26,7 @@ class TestCache(unittest.TestCase): self.assertRaises(TypeError, apt_pkg.Cache, 0) def test_proper_invocation(self): - """Test correct invocation of apt_pkg.DepCache(apt_pkg.Cache()).""" + """cache_invocation: Test correct invocation.""" apt_cache = apt_pkg.Cache(apt_pkg.OpProgress()) apt_depcache = apt_pkg.DepCache(apt_cache) diff --git a/tests/test_hashes.py b/tests/test_hashes.py index 520c4925..e0aabe09 100644 --- a/tests/test_hashes.py +++ b/tests/test_hashes.py @@ -37,34 +37,34 @@ class TestHashes(unittest.TestCase): self.file.close() def test_md5sum(self): - """Test apt_pkg.md5sum()""" + """hashes: Test apt_pkg.md5sum()""" self.assertEqual(apt_pkg.md5sum(self.value), self.md5) self.assertEqual(apt_pkg.md5sum(self.file), self.md5) def test_sha1sum(self): - """Test apt_pkg.sha1sum()""" + """hashes: Test apt_pkg.sha1sum()""" self.assertEqual(apt_pkg.sha1sum(self.value), self.sha1) self.assertEqual(apt_pkg.sha1sum(self.file), self.sha1) def test_sha256sum(self): - """Test apt_pkg.sha256sum()""" + """hashes: Test apt_pkg.sha256sum()""" self.assertEqual(apt_pkg.sha256sum(self.value), self.sha256) self.assertEqual(apt_pkg.sha256sum(self.file), self.sha256) def test_bytes(self): - """Test apt_pkg.Hashes(bytes)""" + """hashes: Test apt_pkg.Hashes(bytes)""" self.assertEqual(self.hashes.md5, self.md5) self.assertEqual(self.hashes.sha1, self.sha1) self.assertEqual(self.hashes.sha256, self.sha256) def test_file(self): - """Test apt_pkg.Hashes(file).""" + """hashes: Test apt_pkg.Hashes(file).""" self.assertEqual(self.hashes.md5, self.fhashes.md5) self.assertEqual(self.hashes.sha1, self.fhashes.sha1) self.assertEqual(self.hashes.sha256, self.fhashes.sha256) def test_unicode(self): - """Test apt_pkg.Hashes(unicode).""" + """hashes: Test apt_pkg.Hashes(unicode).""" if sys.version_info[0] == 3: self.assertRaises(TypeError, apt_pkg.Hashes, "D") self.assertRaises(TypeError, apt_pkg.md5sum, "D") @@ -88,22 +88,22 @@ class TestHashString(unittest.TestCase): self.sha256 = apt_pkg.HashString("SHA256", self.hashes.sha256) def test_md5(self): - """Test apt_pkg.HashString().md5""" + """hashes: Test apt_pkg.HashString().md5""" self.assertEqual("MD5Sum:%s" % self.hashes.md5, str(self.md5)) self.assertTrue(self.md5.verify_file(apt_pkg.__file__)) def test_sha1(self): - """Test apt_pkg.HashString().sha1""" + """hashes: Test apt_pkg.HashString().sha1""" self.assertEqual("SHA1:%s" % self.hashes.sha1, str(self.sha1)) self.assertTrue(self.sha1.verify_file(apt_pkg.__file__)) def test_sha256(self): - """Test apt_pkg.HashString().sha256""" + """hashes: Test apt_pkg.HashString().sha256""" self.assertEqual("SHA256:%s" % self.hashes.sha256, str(self.sha256)) self.assertTrue(self.sha256.verify_file(apt_pkg.__file__)) def test_wrong(self): - """Test wrong invocation of HashString.""" + """hashes: Test apt_pkg.HashString(wrong_type).""" self.assertRaises(TypeError, apt_pkg.HashString, 0) if sys.version_info[0] == 3: self.assertRaises(TypeError, apt_pkg.HashString, bytes()) -- cgit v1.2.3 From 68120a33ecb68da02cfb8124244be79ff5a2fad8 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 3 Aug 2009 18:49:19 +0200 Subject: tests/test_cache_invocation.py: Adapt to new progress API. --- tests/test_cache_invocation.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests/test_cache_invocation.py') diff --git a/tests/test_cache_invocation.py b/tests/test_cache_invocation.py index ff86b102..4245eb50 100644 --- a/tests/test_cache_invocation.py +++ b/tests/test_cache_invocation.py @@ -2,6 +2,7 @@ import unittest import apt_pkg +import apt.progress.base class TestCache(unittest.TestCase): @@ -13,21 +14,21 @@ class TestCache(unittest.TestCase): def test_wrong_invocation(self): """cache_invocation: Test wrong invocation.""" - apt_cache = apt_pkg.Cache(apt_pkg.OpProgress()) + apt_cache = apt_pkg.Cache(apt.progress.base.OpProgress()) if apt_pkg._COMPAT_0_7: self.assertRaises(ValueError, apt_pkg.Cache, apt_cache) self.assertRaises(ValueError, apt_pkg.Cache, - apt_pkg.AcquireProgress()) + apt.progress.base.AcquireProgress()) self.assertRaises(ValueError, apt_pkg.Cache, 0) else: self.assertRaises(TypeError, apt_pkg.Cache, apt_cache) self.assertRaises(TypeError, apt_pkg.Cache, - apt_pkg.AcquireProgress()) + apt.progress.base.AcquireProgress()) self.assertRaises(TypeError, apt_pkg.Cache, 0) def test_proper_invocation(self): """cache_invocation: Test correct invocation.""" - apt_cache = apt_pkg.Cache(apt_pkg.OpProgress()) + apt_cache = apt_pkg.Cache(apt.progress.base.OpProgress()) apt_depcache = apt_pkg.DepCache(apt_cache) if __name__ == "__main__": -- cgit v1.2.3 From e71cab3fc74af481bd55ff4fd22285889a637514 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 18 Aug 2009 15:21:29 +0200 Subject: tests/test_cache_invocation.py: Fix for COMPAT_0_7=0. We dropped the special progress base classes some time ago, but still checked here. --- tests/test_cache_invocation.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'tests/test_cache_invocation.py') diff --git a/tests/test_cache_invocation.py b/tests/test_cache_invocation.py index 4245eb50..6f4014de 100644 --- a/tests/test_cache_invocation.py +++ b/tests/test_cache_invocation.py @@ -15,16 +15,11 @@ class TestCache(unittest.TestCase): def test_wrong_invocation(self): """cache_invocation: Test wrong invocation.""" apt_cache = apt_pkg.Cache(apt.progress.base.OpProgress()) - if apt_pkg._COMPAT_0_7: - self.assertRaises(ValueError, apt_pkg.Cache, apt_cache) - self.assertRaises(ValueError, apt_pkg.Cache, - apt.progress.base.AcquireProgress()) - self.assertRaises(ValueError, apt_pkg.Cache, 0) - else: - self.assertRaises(TypeError, apt_pkg.Cache, apt_cache) - self.assertRaises(TypeError, apt_pkg.Cache, - apt.progress.base.AcquireProgress()) - self.assertRaises(TypeError, apt_pkg.Cache, 0) + + self.assertRaises(ValueError, apt_pkg.Cache, apt_cache) + self.assertRaises(ValueError, apt_pkg.Cache, + apt.progress.base.AcquireProgress()) + self.assertRaises(ValueError, apt_pkg.Cache, 0) def test_proper_invocation(self): """cache_invocation: Test correct invocation.""" -- cgit v1.2.3