From cabfb66ce1cdc518d145dc79647e718b9515887d Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Wed, 23 May 2012 10:08:42 +0200 Subject: PyUT: Implement test for lsb_release.guess_debian_release. This includes a modification of lsb_release.py to enable an overridability with an environment variable LSB_ETC_DEBIAN_VERSION that can point to another /etc/debian_version. --- test/apt-cache | 12 +++++++ test/test_lsb_release.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/apt-cache b/test/apt-cache index 9106a42..a31c998 100755 --- a/test/apt-cache +++ b/test/apt-cache @@ -37,3 +37,15 @@ if os.environ.get('TEST_APT_CACHE_RELEASE') == '512': print(' 512 http://MirRor_is_not_read/folder-either-debian/ exp/main arch Packages') print(' release o=P-or1g1n,a=sid,n=codename-not-read,l=P-l8bel,c=OtherComp') print(' origin MirRor-is-not-read') + +if os.environ.get('TEST_APT_CACHE_UNSTABLE') == '500': + print(' 500 http://MirRor_is_not_read/folder-either-debian/ sid/main arch Packages') + print(' release o=Debian,a=unstable,n=sid,l=Debian,c=main') + print(' origin MirRor-is-not-read') + +if os.environ.get('TEST_APT_CACHE_UNSTABLE_PORTS') == '500': + print(' 500 http://MirRor_is_not_read/folder-either-debian-ports/ sid/main arch Packages') + print(' release o=Debian Ports,a=unstable,n=sid,l=ftp.debian-ports.org,c=main,v=1.0') + print(' origin MirRor-is-not-read') + +print('Pinned packages:') diff --git a/test/test_lsb_release.py b/test/test_lsb_release.py index ccd7ec5..52e69ae 100644 --- a/test/test_lsb_release.py +++ b/test/test_lsb_release.py @@ -142,9 +142,92 @@ class TestLSBRelease(unittest.TestCase): os.environ.pop('TEST_APT_CACHE2') os.environ.pop('TEST_APT_CACHE_RELEASE') - @unittest.skip('Test not implemented.') def test_guess_debian_release(self): - raise NotImplementedError() + # Copied verbatim from guess_debian_release; sucks but unavoidable. + distinfo = {'ID' : 'Debian'} + kern = os.uname()[0] + if kern in ('Linux', 'Hurd', 'NetBSD'): + distinfo['OS'] = 'GNU/'+kern + elif kern == 'FreeBSD': + distinfo['OS'] = 'GNU/k'+kern + elif kern in ('GNU/Linux', 'GNU/kFreeBSD'): + distinfo['OS'] = kern + else: + distinfo['OS'] = 'GNU' + + # Test "stable releases" with numeric debian_versions + for rno in lr.RELEASE_CODENAME_LOOKUP: + distinfo['RELEASE'] = rno + random.choice('.r') + str(random.randint(0,9)) + distinfo['CODENAME'] = lr.RELEASE_CODENAME_LOOKUP[rno] + distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s (%(CODENAME)s)' % distinfo + fn = 'test/debian_version_' + rnd_string(5,5) + f = open(fn,'w') + f.write(distinfo['RELEASE']) + f.close() + os.environ['LSB_ETC_DEBIAN_VERSION'] = fn + self.assertEqual(lr.guess_debian_release(),distinfo) + os.remove(fn) + os.environ.pop('LSB_ETC_DEBIAN_VERSION') + + # Remove the CODENAME from the supposed output + distinfo.pop('CODENAME') + # Test "stable releases" with string debian_versions, go read invalid apt-cache policy + for rno in lr.RELEASE_CODENAME_LOOKUP: + distinfo['RELEASE'] = lr.RELEASE_CODENAME_LOOKUP[rno] + distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s' % distinfo + fn = 'test/debian_version_' + rnd_string(5,12) + f = open(fn,'w') + f.write(distinfo['RELEASE']) + f.close() + os.environ['LSB_ETC_DEBIAN_VERSION'] = fn + self.assertEqual(lr.guess_debian_release(),distinfo) + os.remove(fn) + os.environ.pop('LSB_ETC_DEBIAN_VERSION') + + # Test "unstable releases" that end in /sid, go read invalid apt-cache policy + distinfo['RELEASE'] = 'testing/unstable' + distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s' % distinfo + for rno in lr.RELEASE_CODENAME_LOOKUP: + fn = 'test/debian_version_' + rnd_string(5,12) + f = open(fn,'w') + f.write(lr.RELEASE_CODENAME_LOOKUP[rno] + '/sid') + f.close() + os.environ['LSB_ETC_DEBIAN_VERSION'] = fn + self.assertEqual(lr.guess_debian_release(),distinfo) + os.remove(fn) + os.environ.pop('LSB_ETC_DEBIAN_VERSION') + + # Test "unstable releases" that end in /sid, go read valid apt-cache policy + os.environ['TEST_APT_CACHE_UNSTABLE'] = '500' + distinfo['CODENAME'] = 'sid' + distinfo['RELEASE'] = 'unstable' + distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s (%(CODENAME)s)' % distinfo + for rno in lr.RELEASE_CODENAME_LOOKUP: + fn = 'test/debian_version_' + rnd_string(5,12) + f = open(fn,'w') + f.write(lr.RELEASE_CODENAME_LOOKUP[rno] + '/sid') + f.close() + os.environ['LSB_ETC_DEBIAN_VERSION'] = fn + self.assertEqual(lr.guess_debian_release(),distinfo) + os.remove(fn) + os.environ.pop('LSB_ETC_DEBIAN_VERSION') + + # Test "unstable releases with Debian Ports" that end in /sid, go read valid apt-cache policy + os.environ['TEST_APT_CACHE_UNSTABLE_PORTS'] = '500' + distinfo['CODENAME'] = 'sid' + distinfo['RELEASE'] = 'unstable' + distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s (%(CODENAME)s)' % distinfo + for rno in lr.RELEASE_CODENAME_LOOKUP: + fn = 'test/debian_version_' + rnd_string(5,12) + f = open(fn,'w') + f.write(lr.RELEASE_CODENAME_LOOKUP[rno] + '/sid') + f.close() + os.environ['LSB_ETC_DEBIAN_VERSION'] = fn + self.assertEqual(lr.guess_debian_release(),distinfo) + os.remove(fn) + os.environ.pop('LSB_ETC_DEBIAN_VERSION') + os.environ.pop('TEST_APT_CACHE_UNSTABLE_PORTS') + os.environ.pop('TEST_APT_CACHE_UNSTABLE') def test_get_lsb_information(self): # Test that an inexistant /etc/lsb-release leads to empty output -- cgit v1.2.3