diff options
author | Didier Raboud <odyx@debian.org> | 2012-05-22 15:01:05 +0200 |
---|---|---|
committer | Didier Raboud <odyx@debian.org> | 2012-05-22 15:01:05 +0200 |
commit | bfa47108c06cb03f762e9f3eae2833cabb2fcb44 (patch) | |
tree | 228ad39a7125f505fd2e900d1e7bc77ed82b7907 /test | |
parent | 6cee73b86db587a12068a732ee9b2b40eb204a20 (diff) |
PyUT: Implement test for lsb_release.check_modules_installed.
Diffstat (limited to 'test')
-rwxr-xr-x | test/dpkg-query | 29 | ||||
-rw-r--r-- | test/test_lsb_release.py | 13 |
2 files changed, 40 insertions, 2 deletions
diff --git a/test/dpkg-query b/test/dpkg-query new file mode 100755 index 0000000..8ff193b --- /dev/null +++ b/test/dpkg-query @@ -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') diff --git a/test/test_lsb_release.py b/test/test_lsb_release.py index 6c9c3a2..ef08540 100644 --- a/test/test_lsb_release.py +++ b/test/test_lsb_release.py @@ -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 = '' |