Make version_from_string() more tolerant

This commit is contained in:
Laurent Monin
2014-01-02 11:50:51 +01:00
parent 69f59348c1
commit 81ec25afcd
2 changed files with 5 additions and 1 deletions

View File

@@ -48,7 +48,7 @@ def version_to_string(version, short=False):
def version_from_string(version_str):
g = re.match(r"^(\d+).(\d+).(\d+)(dev|final)(\d+)$", version_str).groups()
g = re.match(r"^(\d+)[._](\d+)[._](\d+)[._]?(dev|final)[._]?(\d+)$", version_str).groups()
return (int(g[0]), int(g[1]), int(g[2]), g[3], int(g[4]))

View File

@@ -54,3 +54,7 @@ class VersionsTest(unittest.TestCase):
def test_version_conv_11(self):
l, s = ('1', '1', '0', 'dev', '0'), '1.1.0dev0'
self.assertEqual(version_to_string(l), s)
def test_version_conv_12(self):
l, s = (1, 1, 0, 'dev', 0), '1_1_0_dev_0'
self.assertEqual(l, version_from_string(s))