PyUT: Implement test for lsb_release.check_modules_installed.
authorDidier Raboud <odyx@debian.org>
Tue, 22 May 2012 13:01:05 +0000 (15:01 +0200)
committerDidier Raboud <odyx@debian.org>
Tue, 22 May 2012 13:01:05 +0000 (15:01 +0200)
test/dpkg-query [new file with mode: 0755]
test/test_lsb_release.py

diff --git a/test/dpkg-query b/test/dpkg-query
new file mode 100755 (executable)
index 0000000..8ff193b
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+
+# Fake dpkg-query  python script to emulate output for test usage
+
+# Python3-compatible print() function
+from __future__ import print_function
+
+import sys
+import os
+import random
+
+if len(sys.argv) < 5:
+       sys.exit("Not enough arguments.")
+
+if sys.argv[1] != '-f' or \
+   sys.argv[2] != '${Version} ${Provides}\n' or \
+   sys.argv[3] != '-W':
+       sys.exit("Wrong input arguments.")
+
+if os.environ.get('TEST_DPKG_QUERY_NONE') == '1':
+       for package in sys.argv[4::]:
+               print('No packages found matching ' + package + '.',file=sys.stderr)
+
+if os.environ.get('TEST_DPKG_QUERY_ALL') == '1':
+       arch = 'TESTarch'
+       for package in sys.argv[4::]:
+               vers_sep = random.choice('-+~')
+               vers = '9.8' + vers_sep + 'Debian7ubuntu6'
+               print(vers + ' ' + package + '-' + arch + ', ' + package + '-noarch')
index 6c9c3a25d057cbe7e0fd97f3d65ec7a0d1873d05..ef085401e7b36d850d122f069952c06568d98b54 100644 (file)
@@ -62,9 +62,18 @@ class TestLSBRelease(unittest.TestCase):
                                                                         [elem for elem in in_versions if int(float(elem)*10) <= int(float(test_v)*10)],
                                                                         assert_text)
 
-       @unittest.skip('Test not implemented.')
        def test_check_modules_installed(self):
-               raise NotImplementedError()
+               # Test that when no packages are available, then we get nothing out.
+               os.environ['TEST_DPKG_QUERY_NONE'] = '1'
+               self.assertEqual(lr.check_modules_installed(),[])
+               os.environ.pop('TEST_DPKG_QUERY_NONE')
+
+               # Test with all packages available.
+               supposed_output = [pkg[4::] + '-9.8-TESTarch' for pkg in lr.PACKAGES.split(' ')]
+               supposed_output += [pkg[4::] + '-9.8-noarch' for pkg in lr.PACKAGES.split(' ')]
+               supposed_output.sort()
+               os.environ['TEST_DPKG_QUERY_ALL'] = '1'
+               self.assertEqual(sorted(lr.check_modules_installed()),supposed_output)
 
        def test_parse_policy_line(self):
                release_line = ''