diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2006-09-06 13:37:56 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2006-09-06 13:37:56 +0200 |
| commit | d754e704d6e42bff9f1f8485e134fd4d04cb3a24 (patch) | |
| tree | cee5ed5bbc75cedd1de1fbc141a0a132ec834612 | |
| parent | eafcfb0385b7183f8ad02b4d258549975ed5e350 (diff) | |
| download | python-apt-d754e704d6e42bff9f1f8485e134fd4d04cb3a24.tar.gz | |
* tests/test_aptsources.py:
- added another test for the "Distribution()" class
| -rw-r--r-- | UpdateManager/Common/aptsources.py | 5 | ||||
| -rw-r--r-- | tests/data/sources.list.testDistribution | 14 | ||||
| -rw-r--r-- | tests/test_aptsources.py | 34 |
3 files changed, 42 insertions, 11 deletions
diff --git a/UpdateManager/Common/aptsources.py b/UpdateManager/Common/aptsources.py index f8ce474b..8963fd15 100644 --- a/UpdateManager/Common/aptsources.py +++ b/UpdateManager/Common/aptsources.py @@ -635,12 +635,15 @@ class Distribution: def enable_component(self, sourceslist, comp): """ - Disable a component in all main, child and source code sources + Enable a component in all main, child and source code sources (excluding cdrom based sources) sourceslist: an aptsource.sources_list comp: the component that should be enabled """ + # FIXME: we can't just unconditionally add stuff to each line, + # otherwise we need up with multiple components for the + # same repository (see tests/test_aptsources.py for details) sources = [] sources.extend(self.main_sources) sources.extend(self.child_sources) diff --git a/tests/data/sources.list.testDistribution b/tests/data/sources.list.testDistribution new file mode 100644 index 00000000..dd900645 --- /dev/null +++ b/tests/data/sources.list.testDistribution @@ -0,0 +1,14 @@ +# 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 +# comment 4 +deb http://de.archive.ubuntu.com/ubuntu/ edgy-updates universe multiverse +# comment 5 +deb http://de.archive.ubuntu.com/ubuntu/ edgy-security main +# comment 6 +deb http://ftp.debian.org/debian sid main +# comment 7 +deb http://de.archive.ubuntu.com/ubuntu/ breezy main
\ No newline at end of file diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index e8b97263..0479076c 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -10,9 +10,8 @@ class TestAptSources(unittest.TestCase): def __init__(self, methodName): unittest.TestCase.__init__(self, methodName) apt_pkg.init() - - def testAddComponent(self): - pass + apt_pkg.Config.Set("Dir::Etc", os.getcwd()) + apt_pkg.Config.Set("Dir::Etc::sourceparts",".") def testIsMirror(self): self.assertTrue(aptsources.is_mirror("http://archive.ubuntu.com", @@ -21,17 +20,17 @@ class TestAptSources(unittest.TestCase): "http://ftp.debian.org")) def testSourcesListReading(self): - sources = aptsources.SourcesList() - # test refresh - apt_pkg.Config.Set("Dir::Etc", os.getcwd()) apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list") - apt_pkg.Config.Set("Dir::Etc::sourceparts",".") - sources.refresh() + sources = aptsources.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() # test to add something that is already there (main) before = copy.deepcopy(sources) sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", @@ -69,7 +68,6 @@ class TestAptSources(unittest.TestCase): entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and entry.dist == "edgy"): for c in entry.comps: - print c if c == "universe": found_universe += 1 if c == "something": @@ -78,7 +76,23 @@ class TestAptSources(unittest.TestCase): self.assertEqual(found_something, 1) self.assertEqual(found_universe, 1) - + def testDistribution(self): + apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution") + sources = aptsources.SourcesList() + distro = aptsources.Distribution() + distro.get_sources(sources) + comp = "restricted" + distro.enable_component(sources, comp) + found = 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 == comp: + found += 1 + print "".join([s.str() for s in sources]) + assertEqual(found, 1) if __name__ == "__main__": |
