From: Didier Raboud Date: Tue, 22 May 2012 13:19:54 +0000 (+0200) Subject: PyUT: Implement test for lsb_release.get_lsb_information. X-Git-Tag: archive/raspbian/10.2018112800+rpi1^2~117 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f6bf9ebeac9bae1464bfe6f5278bfc0bc2551658;p=lsb.git PyUT: Implement test for lsb_release.get_lsb_information. This includes a modification of lsb_release.py to enable an overridability with an environment variable LSB_ETC_LSB_RELEASE that can point to another /etc/lsb-release --- diff --git a/lsb_release.py b/lsb_release.py index ed0667b..e7e3cbe 100644 --- a/lsb_release.py +++ b/lsb_release.py @@ -300,9 +300,10 @@ def guess_debian_release(): # Whatever is guessed above can be overridden in /etc/lsb-release def get_lsb_information(): distinfo = {} - if os.path.exists('/etc/lsb-release'): + etc_lsb_release = os.environ.get('LSB_ETC_LSB_RELEASE','/etc/lsb-release') + if os.path.exists(etc_lsb_release): try: - with open('/etc/lsb-release') as lsb_release_file: + with open(etc_lsb_release) as lsb_release_file: for line in lsb_release_file: line = line.strip() if not line: @@ -318,7 +319,7 @@ def get_lsb_information(): if arg: # Ignore empty arguments distinfo[var] = arg.strip() except IOError, msg: - print >> sys.stderr, 'Unable to open /etc/lsb-release:', str(msg) + print >> sys.stderr, 'Unable to open ' + etc_lsb_release , str(msg) return distinfo diff --git a/test/lsb-release b/test/lsb-release new file mode 100644 index 0000000..06d7473 --- /dev/null +++ b/test/lsb-release @@ -0,0 +1,5 @@ +DISTRIB_ID=(Distributor ID) +DISTRIB_DESCRIPTION=(A human-readable description of the release) +DISTRIB_RELEASE=(The release number) +DISTRIB_CODENAME=(The codename for the release) +OTHER_VARIABLE=Not supposed to exist diff --git a/test/test_lsb_release.py b/test/test_lsb_release.py index ef08540..eecd4e8 100644 --- a/test/test_lsb_release.py +++ b/test/test_lsb_release.py @@ -132,9 +132,20 @@ class TestLSBRelease(unittest.TestCase): @unittest.skip('Test not implemented.') def test_guess_debian_release(self): raise NotImplementedError() - @unittest.skip('Test not implemented.') + def test_get_lsb_information(self): - raise NotImplementedError() + # Test that an inexistant /etc/lsb-release leads to empty output + supposed_output = {} + os.environ['LSB_ETC_LSB_RELEASE'] = 'test/inexistant_file_' + rnd_string(2,5) + self.assertEqual(lr.get_lsb_information(),supposed_output) + # Test that a fake /etc/lsb-release leads to output with only the content we want + supposed_output = {'RELEASE': '(The release number)', + 'CODENAME': '(The codename for the release)', + 'ID': '(Distributor ID)', + 'DESCRIPTION': '(A human-readable description of the release)'} + os.environ['LSB_ETC_LSB_RELEASE'] = 'test/lsb-release' + self.assertEqual(lr.get_lsb_information(),supposed_output) + @unittest.skip('Test not implemented.') def test_get_distro_information(self): raise NotImplementedError()