summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2012-05-22 15:19:54 +0200
committerDidier Raboud <odyx@debian.org>2012-05-22 15:19:56 +0200
commitf6bf9ebeac9bae1464bfe6f5278bfc0bc2551658 (patch)
tree899e78b1d19930fc47484ae35901c04b5b2b56b9
parentbfa47108c06cb03f762e9f3eae2833cabb2fcb44 (diff)
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
-rw-r--r--lsb_release.py7
-rw-r--r--test/lsb-release5
-rw-r--r--test/test_lsb_release.py15
3 files changed, 22 insertions, 5 deletions
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()