Hello all,
I have written some tests for LooseVersion from which some seem to be failing unexpectedly.
Code:
I really stared at the code for some time, but I cannot find the reason.
See https://github.com/python/cpython/blob/m...version.py for how the regex etc. looks like.
I also tried StrictVersion, which fails with:
Can anyone help me please?
Kawu
I have written some tests for LooseVersion from which some seem to be failing unexpectedly.
Code:
from distutils.version import LooseVersion
failed_tests = []
# the tests at hand: the bool at the end is the expected result
# 3 < 3.0: False
# 3 == 3.0: True
# 3 >= 3.0: True
# 3.0 <= 3 : True
# 3.0 == 3 : True
# 3.0 > 3 : False
# must invert the boolean logic with not for the tests in the middle...
if (LooseVersion('3') < LooseVersion('3.0')):
failed_tests.append(('3 < 3.0', False))
if not (LooseVersion('3') == LooseVersion('3.0')):
failed_tests.append(('3 == 3.0', True))
if not (LooseVersion('3') >= LooseVersion('3.0')):
failed_tests.append(('3 >= 3.0', True))
if not (LooseVersion('3.0') <= LooseVersion('3')):
failed_tests.append(('3.0 <= 3', True))
if not (LooseVersion('3.0') == LooseVersion('3')):
failed_tests.append(('3.0 == 3', True))
if (LooseVersion('3.0') > LooseVersion('3')):
failed_tests.append(('3.0 > 3', False))
if failed_tests:
print
print 'Failed tests: ' + str(len(failed_tests))
for test_string, expected_result in failed_tests:
print test_string + ': ' + str(expected_result)
print
raise ValueError('Some tests failed!')The above tests should not be failing, but they do:Error:12:43:59 [INF][ print]: Failed tests: 6
12:43:59 [INF][ print]: 3 < 3.0: False
12:43:59 [INF][ print]: 3 == 3.0: True
12:43:59 [INF][ print]: 3 >= 3.0: True
12:43:59 [INF][ print]: 3.0 <= 3: True
12:43:59 [INF][ print]: 3.0 == 3: True
12:43:59 [INF][ print]: 3.0 > 3: FalseWhy is this happening and how do you fix this? Is this a bug? Are my tests bugged?I really stared at the code for some time, but I cannot find the reason.
See https://github.com/python/cpython/blob/m...version.py for how the regex etc. looks like.
I also tried StrictVersion, which fails with:
Error:13:03:26 [ERR][ python]: File "C:\Users\Kawu\AppData\Roaming\MySQL\Workbench\modules\jpa_export_plugin_grt.py", line 267, in export_jpa_annotated_classes
13:03:26 [ERR][ python]: if (StrictVersion('3') < StrictVersion('3.0')):
13:03:26 [ERR][ python]: File "C:\Program Files\MySQL\MySQL Workbench 8.0 CE\Python\Lib\distutils\version.py", line 40, in __init__
13:03:26 [ERR][ python]: self.parse(vstring)
13:03:26 [ERR][ python]: File "C:\Program Files\MySQL\MySQL Workbench 8.0 CE\Python\Lib\distutils\version.py", line 107, in parse
13:03:26 [ERR][ python]: raise ValueError, "invalid version number '%s'" % vstring
13:03:26 [ERR][ python]: ValueError: invalid version number '3'StrictVersion considers simple numbers as invalid, so I cannot go with StrictVersion anyway, because I need to compare version numbers without minor/sub numbers.Can anyone help me please?
Kawu
