Skip to content

Commit

Permalink
bug 1312560: handling unparsable versions as BadDataError (#199). r=b…
Browse files Browse the repository at this point in the history
…hearsum
  • Loading branch information
dpaks authored and bhearsum committed Dec 22, 2016
1 parent e65508b commit 530e5c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
17 changes: 9 additions & 8 deletions auslib/test/util/test_versions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest

from auslib.errors import BadDataError
from auslib.util.versions import MozillaVersion


Expand Down Expand Up @@ -32,11 +33,11 @@ def test_prerelease(self):

def test_cmp_strict(self):
versions = (('1.5.1', '1.5.2b2', -1),
('161', '3.10a', ValueError),
('161', '3.10a', BadDataError),
('8.02', '8.02', 0),
('3.4j', '1996.07.12', ValueError),
('3.2.pl0', '3.1.1.6', ValueError),
('2g6', '11g', ValueError),
('3.4j', '1996.07.12', BadDataError),
('3.2.pl0', '3.1.1.6', BadDataError),
('2g6', '11g', BadDataError),
('0.9', '2.2', -1),
('1.2.1', '1.2', 1),
('1.1', '1.2.2', -1),
Expand All @@ -45,17 +46,17 @@ def test_cmp_strict(self):
('1.2.2', '1.2', 1),
('1.2', '1.2.2', -1),
('0.4.0', '0.4', 0),
('1.13++', '5.5.kw', ValueError))
('1.13++', '5.5.kw', BadDataError))

for v1, v2, wanted in versions:
try:
res = MozillaVersion(v1).__cmp__(MozillaVersion(v2))
except ValueError:
if wanted is ValueError:
except BadDataError:
if wanted is BadDataError:
continue
else:
raise AssertionError(("cmp(%s, %s) "
"shouldn't raise ValueError")
"shouldn't raise BadDataError")
% (v1, v2))
self.assertEqual(res, wanted,
'cmp(%s, %s) should be %s, got %s' %
Expand Down
9 changes: 7 additions & 2 deletions auslib/util/versions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from distutils.version import StrictVersion
import re

from auslib.errors import BadDataError


class ModernMozillaVersion(StrictVersion):
"""A version class that is slightly less restrictive than StrictVersion.
Expand All @@ -26,7 +28,10 @@ def MozillaVersion(version):
try:
return ModernMozillaVersion(version)
except ValueError:
pass
try:
if version.count('.') == 3:
return AncientMozillaVersion(version)
else:
raise
except ValueError:
pass
raise BadDataError("Version number %s is invalid." % version)

0 comments on commit 530e5c4

Please sign in to comment.