Fix lsb_release to correctly work with stable release updates incrementing the second...
authorDidier Raboud <odyx@debian.org>
Wed, 5 Jun 2013 10:27:33 +0000 (12:27 +0200)
committerDidier Raboud <odyx@debian.org>
Wed, 5 Jun 2013 10:30:21 +0000 (12:30 +0200)
Also fix the test cases to cover that.

Closes: #711174
lsb_release.py
test/test_lsb_release.py

index d36eeb670aa9012d5373b1e07b67436a25cdb1d5..ecf46e3ebbcf6b67aae5e2e226d3ba5a6df369cf 100644 (file)
@@ -41,8 +41,8 @@ RELEASE_CODENAME_LOOKUP = {
     '4.0' : 'etch',
     '5.0' : 'lenny',
     '6.0' : 'squeeze',
-    '7.0' : 'wheezy',
-    '8.0' : 'jessie',
+    '7'   : 'wheezy',
+    '8'   : 'jessie',
     }
 
 TESTING_CODENAME = 'unknown.new.testing'
@@ -57,7 +57,10 @@ def lookup_codename(release, unknown=None):
     if not m:
         return unknown
 
-    shortrelease = '%s.%s' % m.group(1,2)
+    if int(m.group(1)) < 7:
+        shortrelease = '%s.%s' % m.group(1,2)
+    else:
+        shortrelease = '%s' % m.group(1)
     return RELEASE_CODENAME_LOOKUP.get(shortrelease, unknown)
 
 # LSB compliance packages... may grow eventually
index d100c219a66e618c347242e31d7c4ad5d852d132..c449a4b33905aae650cddf84614fb81b2cbeb1e8 100644 (file)
@@ -40,6 +40,9 @@ class TestLSBRelease(unittest.TestCase):
                        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 = rnd_string(0,9)
+                       # From Wheezy on, the codename is defined by the first number but a dot-revision is mandatory
+                       if float(rno) >= 7:
+                               rno = rno + '.' + str(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.')
@@ -241,7 +244,11 @@ class TestLSBRelease(unittest.TestCase):
 
                # Test "stable releases" with numeric debian_versions
                for rno in lr.RELEASE_CODENAME_LOOKUP:
-                       distinfo['RELEASE'] = rno + random.choice('.r') + str(random.randint(0,9))
+                       # From Wheezy on, the codename is defined by the first number but a dot-revision is mandatory
+                       if float(rno) >= 7:
+                               distinfo['RELEASE'] = rno + '.' + str(random.randint(0,9))
+                       else:
+                               distinfo['RELEASE'] = rno + random.choice('.r') + str(random.randint(0,9))
                        distinfo['CODENAME'] = lr.RELEASE_CODENAME_LOOKUP[rno]
                        distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s (%(CODENAME)s)' % distinfo
                        fn = 'test/debian_version_' + rnd_string(5,5)