From 19fdcab7acc03ceb6aaf57f7ccdd754a41aa7b6e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 31 Jul 2008 12:01:43 +0200 Subject: * python/apt_instmodule.cc: - do not change working dir in debExtractArchive() (LP: #184093) --- tests/test_extract_archive.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/test_extract_archive.py (limited to 'tests') diff --git a/tests/test_extract_archive.py b/tests/test_extract_archive.py new file mode 100644 index 00000000..ce202b06 --- /dev/null +++ b/tests/test_extract_archive.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +import apt +import apt_inst +import os +import sys + +print os.getcwd() +apt_inst.debExtractArchive(open(sys.argv[1]), "/tmp/") +print os.getcwd() -- cgit v1.2.3 From 1d96f36591c56798021c4e33d01a781507592add Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 31 Jul 2008 12:20:11 +0200 Subject: add test_debextract.py --- tests/test_debextract.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 tests/test_debextract.py (limited to 'tests') diff --git a/tests/test_debextract.py b/tests/test_debextract.py new file mode 100755 index 00000000..53241e92 --- /dev/null +++ b/tests/test_debextract.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +import apt_inst +import sys + +def Callback(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor): + print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u" % ( + What,Name,Link,Mode,UID,GID,Size, MTime, Major, Minor) + +member = "data.tar.lzma" +if len(sys.argv) > 2: + member = sys.argv[2] +apt_inst.debExtract(open(sys.argv[1]), Callback, member) -- cgit v1.2.3 From 69751ac5d60b35daddfe62219283b535892c7007 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Sep 2008 14:15:59 +0200 Subject: * tests/test_aptsources.py: - make the test work again --- tests/data/sources.list.testDistribution | 20 +++++++++---------- tests/test_aptsources.py | 34 ++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/data/sources.list.testDistribution b/tests/data/sources.list.testDistribution index 1687c504..45c155e9 100644 --- a/tests/data/sources.list.testDistribution +++ b/tests/data/sources.list.testDistribution @@ -1,11 +1,11 @@ -deb http://de.archive.ubuntu.com/ubuntu/ edgy main -deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted -deb http://de.archive.ubuntu.com/ubuntu/ edgy universe -deb http://de.archive.ubuntu.com/ubuntu/ edgy-updates universe multiverse -deb http://de.archive.ubuntu.com/ubuntu/ edgy-updates restricted -deb http://de.archive.ubuntu.com/ubuntu/ edgy-security main -deb http://de.archive.ubuntu.com/ubuntu/ edgy-security multiverse +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 ftp://ubuntu.cs.utah.edu/pub/ubuntu/ubuntu/ breezy main -deb ftp://ubuntu.cs.utah.edu/pub/ubuntu/ubuntu/ breezy-backports main -deb http://archive.ubuntu.com/ubuntu/ hoary 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 diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index 3ee106be..4b2c7965 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -1,27 +1,32 @@ #!/usr/bin/env python -import UpdateManager.Common.aptsources as aptsources 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("Dir::Etc", os.getcwd()) - apt_pkg.Config.Set("Dir::Etc::sourceparts",".") + apt_pkg.Config.Set("Dir::Etc::sourceparts","/xxx") def testIsMirror(self): - self.assertTrue(aptsources.is_mirror("http://archive.ubuntu.com", - "http://de.archive.ubuntu.com")) - self.assertFalse(aptsources.is_mirror("http://archive.ubuntu.com", - "http://ftp.debian.org")) + self.assertTrue(aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", + "http://de.archive.ubuntu.com")) + self.assertFalse(aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", + "http://ftp.debian.org")) def testSourcesListReading(self): apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list") - sources = aptsources.SourcesList() + sources = aptsources.sourceslist.SourcesList() self.assertEqual(len(sources.list), 6) # test load sources.list = [] @@ -30,7 +35,7 @@ class TestAptSources(unittest.TestCase): def testSourcesListAdding(self): apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list") - sources = aptsources.SourcesList() + 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/", @@ -76,10 +81,13 @@ class TestAptSources(unittest.TestCase): self.assertEqual(found_something, 1) self.assertEqual(found_universe, 1) + def testMatcher(self): + apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution") + def testDistribution(self): apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution") - sources = aptsources.SourcesList() - distro = aptsources.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() @@ -87,11 +95,11 @@ class TestAptSources(unittest.TestCase): if s.template: dist_templates.add(s.template.name) #print dist_templates - for d in ["edgy","edgy-security","edgy-updates","hoary","breezy", "breezy-backports"]: + for d in ["hardy","hardy-security","hardy-updates","intrepid","hardy-backports"]: self.assertTrue(d in dist_templates) # test enable comp = "restricted" - distro.enable_component(sources, comp) + distro.enable_component(comp) found = {} for entry in sources: if (entry.type == "deb" and @@ -108,7 +116,7 @@ class TestAptSources(unittest.TestCase): # add a not-already available component comp = "multiverse" - distro.enable_component(sources, comp) + distro.enable_component(comp) found = {} for entry in sources: if (entry.type == "deb" and -- cgit v1.2.3 From d44831bb1d10ac1bc29690fd226209fb71b91b42 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 18 Sep 2008 14:35:14 +0200 Subject: * python/apt_pkgmodule.cc: add "SelState{Unknown,Install,Hold,DeInstall,Purge}" constants - fix detection of cdrom sources and add test for it --- data/templates/Ubuntu.info.in | 9 +++++++++ debian/changelog | 3 +++ tests/data/sources.list.testDistribution | 2 ++ tests/test_aptsources.py | 8 ++++++++ 4 files changed, 22 insertions(+) (limited to 'tests') diff --git a/data/templates/Ubuntu.info.in b/data/templates/Ubuntu.info.in index c3cfe6df..97554fa8 100644 --- a/data/templates/Ubuntu.info.in +++ b/data/templates/Ubuntu.info.in @@ -25,6 +25,7 @@ _CompDescriptionLong: Software restricted by copyright or legal issues Suite: intrepid MatchName: .* BaseURI: cdrom:\[Ubuntu.*8.10 +MatchURI: cdrom:\[Ubuntu.*8.10 _Description: Cdrom with Ubuntu 8.10 'Intrepid Ibex' Available: False Component: main @@ -80,6 +81,7 @@ _CompDescriptionLong: Software restricted by copyright or legal issues Suite: hardy MatchName: .* BaseURI: cdrom:\[Ubuntu.*8.04 +MatchURI: cdrom:\[Ubuntu.*8.04 _Description: Cdrom with Ubuntu 8.04 'Hardy Heron' Available: False Component: main @@ -134,6 +136,7 @@ _CompDescriptionLong: Software restricted by copyright or legal issues Suite: gutsy MatchName: .* BaseURI: cdrom:\[Ubuntu.*7.10 +MatchURI: cdrom:\[Ubuntu.*7.10 _Description: Cdrom with Ubuntu 7.10 'Gutsy Gibbon' Available: False Component: main @@ -186,6 +189,7 @@ _CompDescriptionLong: Software restricted by copyright or legal issues Suite: feisty MatchName: .* BaseURI: cdrom:\[Ubuntu.*7.04 +MatchURI: cdrom:\[Ubuntu.*7.04 _Description: Cdrom with Ubuntu 7.04 'Feisty Fawn' Available: False Component: main @@ -237,6 +241,7 @@ _CompDescriptionLong: Software restricted by copyright or legal issues Suite: edgy MatchName: .* BaseURI: cdrom:\[Ubuntu.*6.10 +MatchURI: cdrom:\[Ubuntu.*6.10 _Description: Cdrom with Ubuntu 6.10 'Edgy Eft' Available: False Component: main @@ -288,6 +293,7 @@ _CompDescriptionLong: Software restricted by copyright or legal issues Suite: dapper MatchName: .* BaseURI: cdrom:\[Ubuntu.*6.06 +MatchURI: cdrom:\[Ubuntu.*6.06 _Description: Cdrom with Ubuntu 6.06 LTS 'Dapper Drake' Available: False Component: main @@ -335,6 +341,7 @@ _CompDescription: Non-free (Multiverse) Suite: breezy MatchName: .* BaseURI: cdrom:\[Ubuntu.*5.10 +MatchURI: cdrom:\[Ubuntu.*5.10 _Description: Cdrom with Ubuntu 5.10 'Breezy Badger' Available: False Component: main @@ -377,6 +384,7 @@ _CompDescription: Non-free (Multiverse) Suite: hoary MatchName: .* BaseURI: cdrom:\[Ubuntu.*5.04 +MatchURI: cdrom:\[Ubuntu.*5.04 _Description: Cdrom with Ubuntu 5.04 'Hoary Hedgehog' Available: False Component: main @@ -418,6 +426,7 @@ _CompDescription: Non-free (Multiverse) Suite: warty MatchName: .* BaseURI: cdrom:\[Ubuntu.*4.10 +MatchURI: cdrom:\[Ubuntu.*4.10 _Description: Cdrom with Ubuntu 4.10 'Warty Warthog' Available: False Component: main diff --git a/debian/changelog b/debian/changelog index a2ae598a..e9d5710c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,9 +12,12 @@ python-apt (0.7.7.2) UNRELEASED; urgency=low * python/progress.cc: - when pulse() does not return a boolean assume "true" (thanks to Martin Pitt for telling me about the problem) + * python/apt_pkgmodule.cc: + add "SelState{Unknown,Install,Hold,DeInstall,Purge}" constants * aptsources/__init__.py, aptsources/distinfo.py: - run apt_pkg.init() when aptsources gets imported and not the distinfo function + - fix detection of cdrom sources and add test for it -- Michael Vogt Wed, 30 Jul 2008 10:24:30 +0200 diff --git a/tests/data/sources.list.testDistribution b/tests/data/sources.list.testDistribution index 45c155e9..0f40e85a 100644 --- a/tests/data/sources.list.testDistribution +++ b/tests/data/sources.list.testDistribution @@ -9,3 +9,5 @@ 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/test_aptsources.py b/tests/test_aptsources.py index 4b2c7965..49fe6afa 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -83,6 +83,14 @@ class TestAptSources(unittest.TestCase): def testMatcher(self): apt_pkg.Config.Set("Dir::Etc::sourcelist","data/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): apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution") -- cgit v1.2.3 From b4fac97986469c356a3b1030c14d600ba333202e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 10 Nov 2008 10:41:45 +0100 Subject: * 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) --- aptsources/distro.py | 19 ++++++++---- data/templates/Ubuntu.info.in | 2 +- debian/changelog | 5 ++++ tests/test-data-ports/sources.list | 59 ++++++++++++++++++++++++++++++++++++++ tests/test_aptsources_ports.py | 37 ++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 tests/test-data-ports/sources.list create mode 100644 tests/test_aptsources_ports.py (limited to 'tests') 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() -- cgit v1.2.3