# 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:
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
--- /dev/null
+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
@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()