PyUT: Add a unittest for lookup_codename.
authorDidier Raboud <odyx@debian.org>
Fri, 4 May 2012 12:23:25 +0000 (14:23 +0200)
committerDidier Raboud <odyx@debian.org>
Mon, 7 May 2012 19:04:24 +0000 (21:04 +0200)
test/test_lsb_release.py

index bc927f87c56981640b5ba991f3d3cf61a8db4732..2ae7a6832e137a28926783f399965351bd066f4d 100644 (file)
@@ -8,8 +8,16 @@ import string
 
 class TestLSBRelease(unittest.TestCase):
 
-       def test_void(self):
-               self.assertTrue('Void test')
+       def test_lookup_codename(self):
+               # Test all versions
+               for rno in lr.RELEASE_CODENAME_LOOKUP:
+                       cdn = lr.RELEASE_CODENAME_LOOKUP[rno]
+                       # Test that 1.1, 1.1r0 and 1.1.8 lead to buzz. Default is picked randomly and is not supposed to go trough
+                       badDefault = ''.join( [random.choice(string.letters) for i in xrange(random.randint(0,9))])
+                       self.assertEqual(lr.lookup_codename(rno,badDefault),cdn,'Release name `' + rno + '` is not recognized.')
+                       self.assertEqual(lr.lookup_codename(rno + 'r' + str(random.randint(0,9)),badDefault),cdn,'Release name `' + rno + 'r*` is not recognized.')
+                       self.assertEqual(lr.lookup_codename(rno + '.' + str(random.randint(0,9)),badDefault),cdn,'Release name `' + rno + '.*` is not recognized.')
+                       self.assertEqual(lr.lookup_codename('inexistent_release' + str(random.randint(0,9)),badDefault),badDefault,'Default release codename is not accepted.')
 
 if __name__ == '__main__':
        unittest.main()