Fixes #66 RedHat version parsing issue

This commit is contained in:
gholt 2014-06-17 13:35:31 +00:00
parent b21ca97e4a
commit 11aa56cc08
1 changed files with 54 additions and 34 deletions

View File

@ -1,3 +1,4 @@
from sys import stderr
import swift
@ -17,7 +18,7 @@ def parse(value):
major = int(parts.pop(0))
minor = int(parts.pop(0))
if parts:
revision = int(parts.pop(0))
revision = int(parts.pop(0).split('-', 1)[0])
else:
revision = 0
return major, minor, revision, final
@ -25,6 +26,7 @@ def parse(value):
def newer_than(value):
global MAJOR, MINOR, REVISION, FINAL
try:
major, minor, revision, final = parse(value)
if MAJOR is None:
MAJOR, MINOR, REVISION, FINAL = parse(swift.__version__)
@ -39,12 +41,21 @@ def newer_than(value):
elif REVISION == revision:
if not FINAL or final:
return False
except Exception as err:
stderr.write(
"Unable to automatically detect if %r is newer_than(%r) so just "
"assuming it is: %s\n" % (
getattr(swift, "__version__", "no swift.__version__"),
value, err))
return True
def run_tests():
global MAJOR, MINOR, REVISION, FINAL
MAJOR, MINOR, REVISION, FINAL = parse('1.3')
global MAJOR
orig_version = swift.__version__
try:
swift.__version__ = '1.3'
MAJOR = None
assert(newer_than('1.2'))
assert(newer_than('1.2.9'))
assert(newer_than('1.3-dev'))
@ -55,7 +66,8 @@ def run_tests():
assert(not newer_than('1.3.1'))
assert(not newer_than('1.4'))
assert(not newer_than('2.0'))
MAJOR, MINOR, REVISION, FINAL = parse('1.7.7-dev')
swift.__version__ = '1.7.7-dev'
MAJOR = None
assert(newer_than('1.6'))
assert(newer_than('1.7'))
assert(newer_than('1.7.6-dev'))
@ -65,6 +77,14 @@ def run_tests():
assert(not newer_than('1.7.8'))
assert(not newer_than('1.8.0'))
assert(not newer_than('2.0'))
swift.__version__ = '1.10.0-2.el6'
MAJOR = None
assert(not newer_than('2.0'))
swift.__version__ = 'garbage'
MAJOR = None
assert(newer_than('2.0'))
finally:
swift.__version__ = orig_version
if __name__ == '__main__':