run_unittests: rewrite version test to not call private methods
We really should be testing using the operators themselves, not the internal implementations, ie we should use a > b not a.__cmp__(b) == 1 in our tests, because __cmp__ is just an implementation detail.
This commit is contained in:
parent
5678468c2c
commit
397ac5921a
204
run_unittests.py
204
run_unittests.py
|
@ -28,6 +28,7 @@ import platform
|
|||
import pickle
|
||||
import functools
|
||||
import io
|
||||
import operator
|
||||
from itertools import chain
|
||||
from unittest import mock
|
||||
from configparser import ConfigParser
|
||||
|
@ -856,107 +857,120 @@ class InternalTests(unittest.TestCase):
|
|||
]:
|
||||
self.assertEqual(comparefunc(a, b)[0], result)
|
||||
|
||||
for (a, b, result) in [
|
||||
for (a, b, op) in [
|
||||
# examples from https://fedoraproject.org/wiki/Archive:Tools/RPM/VersionComparison
|
||||
("1.0010", "1.9", 1),
|
||||
("1.05", "1.5", 0),
|
||||
("1.0", "1", 1),
|
||||
("2.50", "2.5", 1),
|
||||
("fc4", "fc.4", 0),
|
||||
("FC5", "fc4", -1),
|
||||
("2a", "2.0", -1),
|
||||
("1.0", "1.fc4", 1),
|
||||
("3.0.0_fc", "3.0.0.fc", 0),
|
||||
("1.0010", "1.9", operator.gt),
|
||||
("1.05", "1.5", operator.eq),
|
||||
("1.0", "1", operator.gt),
|
||||
("2.50", "2.5", operator.gt),
|
||||
("fc4", "fc.4", operator.eq),
|
||||
("FC5", "fc4", operator.lt),
|
||||
("2a", "2.0", operator.lt),
|
||||
("1.0", "1.fc4", operator.gt),
|
||||
("3.0.0_fc", "3.0.0.fc", operator.eq),
|
||||
# from RPM tests
|
||||
("1.0", "1.0", 0),
|
||||
("1.0", "2.0", -1),
|
||||
("2.0", "1.0", 1),
|
||||
("2.0.1", "2.0.1", 0),
|
||||
("2.0", "2.0.1", -1),
|
||||
("2.0.1", "2.0", 1),
|
||||
("2.0.1a", "2.0.1a", 0),
|
||||
("2.0.1a", "2.0.1", 1),
|
||||
("2.0.1", "2.0.1a", -1),
|
||||
("5.5p1", "5.5p1", 0),
|
||||
("5.5p1", "5.5p2", -1),
|
||||
("5.5p2", "5.5p1", 1),
|
||||
("5.5p10", "5.5p10", 0),
|
||||
("5.5p1", "5.5p10", -1),
|
||||
("5.5p10", "5.5p1", 1),
|
||||
("10xyz", "10.1xyz", -1),
|
||||
("10.1xyz", "10xyz", 1),
|
||||
("xyz10", "xyz10", 0),
|
||||
("xyz10", "xyz10.1", -1),
|
||||
("xyz10.1", "xyz10", 1),
|
||||
("xyz.4", "xyz.4", 0),
|
||||
("xyz.4", "8", -1),
|
||||
("8", "xyz.4", 1),
|
||||
("xyz.4", "2", -1),
|
||||
("2", "xyz.4", 1),
|
||||
("5.5p2", "5.6p1", -1),
|
||||
("5.6p1", "5.5p2", 1),
|
||||
("5.6p1", "6.5p1", -1),
|
||||
("6.5p1", "5.6p1", 1),
|
||||
("6.0.rc1", "6.0", 1),
|
||||
("6.0", "6.0.rc1", -1),
|
||||
("10b2", "10a1", 1),
|
||||
("10a2", "10b2", -1),
|
||||
("1.0aa", "1.0aa", 0),
|
||||
("1.0a", "1.0aa", -1),
|
||||
("1.0aa", "1.0a", 1),
|
||||
("10.0001", "10.0001", 0),
|
||||
("10.0001", "10.1", 0),
|
||||
("10.1", "10.0001", 0),
|
||||
("10.0001", "10.0039", -1),
|
||||
("10.0039", "10.0001", 1),
|
||||
("4.999.9", "5.0", -1),
|
||||
("5.0", "4.999.9", 1),
|
||||
("20101121", "20101121", 0),
|
||||
("20101121", "20101122", -1),
|
||||
("20101122", "20101121", 1),
|
||||
("2_0", "2_0", 0),
|
||||
("2.0", "2_0", 0),
|
||||
("2_0", "2.0", 0),
|
||||
("a", "a", 0),
|
||||
("a+", "a+", 0),
|
||||
("a+", "a_", 0),
|
||||
("a_", "a+", 0),
|
||||
("+a", "+a", 0),
|
||||
("+a", "_a", 0),
|
||||
("_a", "+a", 0),
|
||||
("+_", "+_", 0),
|
||||
("_+", "+_", 0),
|
||||
("_+", "_+", 0),
|
||||
("+", "_", 0),
|
||||
("_", "+", 0),
|
||||
("1.0", "1.0", operator.eq),
|
||||
("1.0", "2.0", operator.lt),
|
||||
("2.0", "1.0", operator.gt),
|
||||
("2.0.1", "2.0.1", operator.eq),
|
||||
("2.0", "2.0.1", operator.lt),
|
||||
("2.0.1", "2.0", operator.gt),
|
||||
("2.0.1a", "2.0.1a", operator.eq),
|
||||
("2.0.1a", "2.0.1", operator.gt),
|
||||
("2.0.1", "2.0.1a", operator.lt),
|
||||
("5.5p1", "5.5p1", operator.eq),
|
||||
("5.5p1", "5.5p2", operator.lt),
|
||||
("5.5p2", "5.5p1", operator.gt),
|
||||
("5.5p10", "5.5p10", operator.eq),
|
||||
("5.5p1", "5.5p10", operator.lt),
|
||||
("5.5p10", "5.5p1", operator.gt),
|
||||
("10xyz", "10.1xyz", operator.lt),
|
||||
("10.1xyz", "10xyz", operator.gt),
|
||||
("xyz10", "xyz10", operator.eq),
|
||||
("xyz10", "xyz10.1", operator.lt),
|
||||
("xyz10.1", "xyz10", operator.gt),
|
||||
("xyz.4", "xyz.4", operator.eq),
|
||||
("xyz.4", "8", operator.lt),
|
||||
("8", "xyz.4", operator.gt),
|
||||
("xyz.4", "2", operator.lt),
|
||||
("2", "xyz.4", operator.gt),
|
||||
("5.5p2", "5.6p1", operator.lt),
|
||||
("5.6p1", "5.5p2", operator.gt),
|
||||
("5.6p1", "6.5p1", operator.lt),
|
||||
("6.5p1", "5.6p1", operator.gt),
|
||||
("6.0.rc1", "6.0", operator.gt),
|
||||
("6.0", "6.0.rc1", operator.lt),
|
||||
("10b2", "10a1", operator.gt),
|
||||
("10a2", "10b2", operator.lt),
|
||||
("1.0aa", "1.0aa", operator.eq),
|
||||
("1.0a", "1.0aa", operator.lt),
|
||||
("1.0aa", "1.0a", operator.gt),
|
||||
("10.0001", "10.0001", operator.eq),
|
||||
("10.0001", "10.1", operator.eq),
|
||||
("10.1", "10.0001", operator.eq),
|
||||
("10.0001", "10.0039", operator.lt),
|
||||
("10.0039", "10.0001", operator.gt),
|
||||
("4.999.9", "5.0", operator.lt),
|
||||
("5.0", "4.999.9", operator.gt),
|
||||
("20101121", "20101121", operator.eq),
|
||||
("20101121", "20101122", operator.lt),
|
||||
("20101122", "20101121", operator.gt),
|
||||
("2_0", "2_0", operator.eq),
|
||||
("2.0", "2_0", operator.eq),
|
||||
("2_0", "2.0", operator.eq),
|
||||
("a", "a", operator.eq),
|
||||
("a+", "a+", operator.eq),
|
||||
("a+", "a_", operator.eq),
|
||||
("a_", "a+", operator.eq),
|
||||
("+a", "+a", operator.eq),
|
||||
("+a", "_a", operator.eq),
|
||||
("_a", "+a", operator.eq),
|
||||
("+_", "+_", operator.eq),
|
||||
("_+", "+_", operator.eq),
|
||||
("_+", "_+", operator.eq),
|
||||
("+", "_", operator.eq),
|
||||
("_", "+", operator.eq),
|
||||
# other tests
|
||||
('0.99.beta19', '0.99.beta14', 1),
|
||||
("1.0.0", "2.0.0", -1),
|
||||
(".0.0", "2.0.0", -1),
|
||||
("alpha", "beta", -1),
|
||||
("1.0", "1.0.0", -1),
|
||||
("2.456", "2.1000", -1),
|
||||
("2.1000", "3.111", -1),
|
||||
("2.001", "2.1", 0),
|
||||
("2.34", "2.34", 0),
|
||||
("6.1.2", "6.3.8", -1),
|
||||
("1.7.3.0", "2.0.0", -1),
|
||||
("2.24.51", "2.25", -1),
|
||||
("2.1.5+20120813+gitdcbe778", "2.1.5", 1),
|
||||
("3.4.1", "3.4b1", 1),
|
||||
("041206", "200090325", -1),
|
||||
("0.6.2+git20130413", "0.6.2", 1),
|
||||
("2.6.0+bzr6602", "2.6.0", 1),
|
||||
("2.6.0", "2.6b2", 1),
|
||||
("2.6.0+bzr6602", "2.6b2x", 1),
|
||||
("0.6.7+20150214+git3a710f9", "0.6.7", 1),
|
||||
("15.8b", "15.8.0.1", -1),
|
||||
("1.2rc1", "1.2.0", -1),
|
||||
('0.99.beta19', '0.99.beta14', operator.gt),
|
||||
("1.0.0", "2.0.0", operator.lt),
|
||||
(".0.0", "2.0.0", operator.lt),
|
||||
("alpha", "beta", operator.lt),
|
||||
("1.0", "1.0.0", operator.lt),
|
||||
("2.456", "2.1000", operator.lt),
|
||||
("2.1000", "3.111", operator.lt),
|
||||
("2.001", "2.1", operator.eq),
|
||||
("2.34", "2.34", operator.eq),
|
||||
("6.1.2", "6.3.8", operator.lt),
|
||||
("1.7.3.0", "2.0.0", operator.lt),
|
||||
("2.24.51", "2.25", operator.lt),
|
||||
("2.1.5+20120813+gitdcbe778", "2.1.5", operator.gt),
|
||||
("3.4.1", "3.4b1", operator.gt),
|
||||
("041206", "200090325", operator.lt),
|
||||
("0.6.2+git20130413", "0.6.2", operator.gt),
|
||||
("2.6.0+bzr6602", "2.6.0", operator.gt),
|
||||
("2.6.0", "2.6b2", operator.gt),
|
||||
("2.6.0+bzr6602", "2.6b2x", operator.gt),
|
||||
("0.6.7+20150214+git3a710f9", "0.6.7", operator.gt),
|
||||
("15.8b", "15.8.0.1", operator.lt),
|
||||
("1.2rc1", "1.2.0", operator.lt),
|
||||
]:
|
||||
ver_a = Version(a)
|
||||
ver_b = Version(b)
|
||||
self.assertEqual(ver_a.__cmp__(ver_b), result)
|
||||
self.assertEqual(ver_b.__cmp__(ver_a), -result)
|
||||
if op is operator.eq:
|
||||
inverse = None
|
||||
name = 'eq'
|
||||
if op is operator.lt:
|
||||
inverse = operator.ge
|
||||
inv_name = 'ge'
|
||||
name = 'lt'
|
||||
if op is operator.gt:
|
||||
inverse = operator.le
|
||||
inv_name = 'le'
|
||||
name = 'gt'
|
||||
|
||||
self.assertTrue(op(ver_a, ver_b), '{} {} {}'.format(ver_a, name, ver_b))
|
||||
if inverse is not None:
|
||||
self.assertTrue(inverse(ver_b, ver_a), '{} {} {}'.format(ver_a, inv_name, ver_b))
|
||||
|
||||
def test_msvc_toolset_version(self):
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue