summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lsb_release.py7
-rwxr-xr-xtest/apt-cache12
-rw-r--r--test/test_lsb_release.py87
3 files changed, 101 insertions, 5 deletions
diff --git a/lsb_release.py b/lsb_release.py
index e7e3cbe..611737c 100644
--- a/lsb_release.py
+++ b/lsb_release.py
@@ -242,12 +242,13 @@ def guess_debian_release():
distinfo['DESCRIPTION'] = '%(ID)s %(OS)s' % distinfo
- if os.path.exists('/etc/debian_version'):
+ etc_debian_version = os.environ.get('LSB_ETC_DEBIAN_VERSION','/etc/debian_version')
+ if os.path.exists(etc_debian_version):
try:
- with open('/etc/debian_version') as debian_version:
+ with open(etc_debian_version) as debian_version:
release = debian_version.read().strip()
except IOError, msg:
- print >> sys.stderr, 'Unable to open /etc/debian_version:', str(msg)
+ print >> sys.stderr, 'Unable to open ' + etc_debian_version + ':', str(msg)
release = 'unknown'
if not release[0:1].isalpha():
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