diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2008-11-10 10:41:45 +0100 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2008-11-10 10:41:45 +0100 |
| commit | b4fac97986469c356a3b1030c14d600ba333202e (patch) | |
| tree | 5bab0ea87b8e61833305e4341e5b3d7721e09bc9 | |
| parent | 46abf8f70e4ec1c520cd2bcf1a9493f2869193a1 (diff) | |
| download | python-apt-b4fac97986469c356a3b1030c14d600ba333202e.tar.gz | |
* aptsources/distro.py:
- add parameter to get_distro() to make unit testing easier
* tests/test_aptsources_ports.py:
- add test for arch specific handling (when sub arch is on
a different mirror than "main" arches)
| -rw-r--r-- | aptsources/distro.py | 19 | ||||
| -rw-r--r-- | data/templates/Ubuntu.info.in | 2 | ||||
| -rw-r--r-- | debian/changelog | 5 | ||||
| -rw-r--r-- | tests/test-data-ports/sources.list | 59 | ||||
| -rw-r--r-- | tests/test_aptsources_ports.py | 37 |
5 files changed, 115 insertions, 7 deletions
diff --git a/aptsources/distro.py b/aptsources/distro.py index 6d3b453f..f271bbc4 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -414,15 +414,22 @@ class UbuntuDistribution(Distribution): Distribution.get_mirrors(self, mirror_template="http://%s.archive.ubuntu.com/ubuntu/") -def get_distro(): - ''' Check the currently used distribution and return the corresponding - distriubtion class that supports distro specific features. ''' - lsb_info = [] - for lsb_option in ["-i", "-c", "-d", "-r"]: +def get_distro(id=None,codename=None,description=None,release=None): + """ + Check the currently used distribution and return the corresponding + distriubtion class that supports distro specific features. + + If no paramter are given the distro will be auto detected via + a call to lsb-release + """ + # make testing easier + if not (id and codename and description and release): + lsb_info = [] + for lsb_option in ["-i", "-c", "-d", "-r"]: pipe = os.popen("lsb_release %s -s" % lsb_option) lsb_info.append(pipe.read().strip()) del pipe - (id, codename, description, release) = lsb_info + (id, codename, description, release) = lsb_info if id == "Ubuntu": return UbuntuDistribution(id, codename, description, release) diff --git a/data/templates/Ubuntu.info.in b/data/templates/Ubuntu.info.in index 3b8f05c4..c3ebe052 100644 --- a/data/templates/Ubuntu.info.in +++ b/data/templates/Ubuntu.info.in @@ -116,7 +116,7 @@ RepositoryType: deb BaseURI: http://archive.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu BaseURI-powerpc: http://ports.ubuntu.com/ -MatchURI-powerpc: ports.ubuntu.com +MatchURI-powerpc: ports.ubuntu.com|archive.ubuntu.com MirrorsFile-amd64: /usr/share/python-apt/templates/Ubuntu.mirrors MirrorsFile-i386: /usr/share/python-apt/templates/Ubuntu.mirrors _Description: Ubuntu 8.04 'Hardy Heron' diff --git a/debian/changelog b/debian/changelog index ac775f9c..f16964f4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -25,6 +25,11 @@ python-apt (0.7.8) UNRELEASED; urgency=low - fix crash when incorrect attribute is given * data/templates/Ubuntu.info.in: - updated + * aptsources/distro.py: + - add parameter to get_distro() to make unit testing easier + * tests/test_aptsources_ports.py: + - add test for arch specific handling (when sub arch is on + a different mirror than "main" arches) [ Julian Andres Klode ] * python/acquire.cc (GetPkgAcqFile): Support DestDir and DestFilename. diff --git a/tests/test-data-ports/sources.list b/tests/test-data-ports/sources.list new file mode 100644 index 00000000..a6b2f6ed --- /dev/null +++ b/tests/test-data-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/test_aptsources_ports.py b/tests/test_aptsources_ports.py new file mode 100644 index 00000000..203721c7 --- /dev/null +++ b/tests/test_aptsources_ports.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import unittest +import apt_pkg +import os +import copy + +import sys +sys.path.insert(0, "../") +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.join(os.getcwd(),"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() |
