PyUT: Implement test for lsb_release.parse_apt_policy.
authorDidier Raboud <odyx@debian.org>
Tue, 22 May 2012 09:48:32 +0000 (11:48 +0200)
committerDidier Raboud <odyx@debian.org>
Tue, 22 May 2012 09:48:32 +0000 (11:48 +0200)
test/apt-cache
test/test_lsb_release.py

index f6cc88ffa9246ea12431adcd7566a613700ce4c7..17c7c5e5c73a5483e60c3bef100ac6d54735df09 100755 (executable)
@@ -6,6 +6,7 @@
 from __future__ import print_function
 
 import sys
+import os
 
 if len(sys.argv) <= 1 or sys.argv[1] != 'policy':
        sys.exit("Shall only be run with exactly one argument: 'policy'")
@@ -13,3 +14,13 @@ if len(sys.argv) <= 1 or sys.argv[1] != 'policy':
 print("Package files:")
 print(" 100 /var/lib/dpkg/status")
 print("     release a=now")
+
+if os.environ.get('TEST_APT_CACHE1') == '132':
+       print(' 132 http://Mirror_is_not_read/folder-either-debian/ sid/main arch Packages')
+       print('     release o=oRigIn,a=SuiTe,n=codename-not-read,l=lABel,c=C0mp0nent')
+       print('     origin Mirror-is-not-read')
+
+if os.environ.get('TEST_APT_CACHE2') == '35':
+       print(' 35  http://MirRor_is_not_read/folder-either-debian/ sid/main arch Packages')
+       print('     release o=0RigIn,a=5uiTe,n=codename-not-read,l=1ABel,c=C03p0nent')
+       print('     origin MirRor-is-not-read')
index 0292f4a98ab3916a73ceb0ece4e4488e5211cd53..6c9c3a25d057cbe7e0fd97f3d65ec7a0d1873d05 100644 (file)
@@ -6,6 +6,8 @@ import lsb_release as lr
 import random
 import string
 
+import os
+
 def rnd_string(min_l,max_l):
        return ''.join( [random.choice(string.letters) for i in xrange(random.randint(min_l,max_l))])
 
@@ -102,9 +104,19 @@ class TestLSBRelease(unittest.TestCase):
                                 supposed_output,
                                 'compare_release(' + x[1]['suite'] + ',' + y[1]['suite'] + ') =? ' + str(supposed_output))
 
-       @unittest.skip('Test not implemented.')
        def test_parse_apt_policy(self):
-               raise NotImplementedError()
+               # Test almost-empty apt-cache policy
+               supposed_output = [(100, {'suite': 'now'})]
+               self.assertEqual(lr.parse_apt_policy(),supposed_output)
+               # Add one fake entry
+               os.environ['TEST_APT_CACHE1'] = '132'
+               supposed_output.append((132, {'origin': 'oRigIn', 'suite': 'SuiTe', 'component': 'C0mp0nent', 'label': 'lABel'}))
+               self.assertEqual(lr.parse_apt_policy(),supposed_output)
+               # Add a second fake entry, unordered
+               os.environ['TEST_APT_CACHE2'] = '35'
+               supposed_output.append((35, {'origin': '0RigIn', 'suite': '5uiTe', 'component': 'C03p0nent', 'label': '1ABel'}))
+               self.assertEqual(lr.parse_apt_policy(),supposed_output)
+
        @unittest.skip('Test not implemented.')
        def test_guess_release_from_apt(self):
                raise NotImplementedError()