def _check_warning(w): assert issubclass(w.category, UserWarning) warning_match = _WARNING_RE.match(str(w.message)) assert warning_match is not None (detect_ver_str, older_newer, used_ver_str) = warning_match.groups() return (older_newer, Version(detect_ver_str), Version(used_ver_str))
def test_unsupported_old(): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") assert Version.nearest("1.0") == Version("2.0") # Check we got a warning for that old crusty version. assert len(w) == 1 (older_newer, detect_ver, used_ver) = _check_warning(w[-1]) assert older_newer == 'newer' assert used_ver == Version('2.0')
def test_unsupported_bleedingedge(): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") assert Version.nearest("9999.9999") == Version("3.0") # Check we got a warning for that bleeding edge version. assert len(w) == 1 (older_newer, detect_ver, used_ver) = _check_warning(w[-1]) assert older_newer == 'older' assert used_ver == Version('3.0')
def test_grid_append_nover_list(): g = Grid() assert g.version == Version('2.0') g.column['test'] = {} row_1 = {'test': 'This is a test'} row_2 = {'test': ['This should fail']} g.append(row_1) assert g.version == Version('2.0') g.append(row_2) assert g.version == Version('3.0')
def test_unsupported_newer(): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") assert Version.nearest("2.5") == Version("3.0") # Work around Python 2.7 bug (https://stackoverflow.com/questions/56821539/warnings-simplefilteralways-is-not-forcing-warnings-to-be-made-in-python-2-7) if sys.version_info[0:2] != (2, 7): # Check we got a warning for that oddball newer version. assert len(w) == 1 (older_newer, detect_ver, used_ver) = _check_warning(w[-1]) assert older_newer == 'newer' assert used_ver == Version('3.0')
def test_version_gt(): assert Version('1.0') > Version('0.9') assert Version('1.0a') > Version('1.0') assert Version('1.0b') > Version('1.0a')
def test_version_ge(): assert Version('1.0') >= Version('1.0') assert Version('1.0') >= Version('0.9')
def test_version_le(): assert Version('1.0') <= Version('1.0') assert Version('1.0') <= Version('1.5')
def test_version_lt(): assert Version('1.0') < Version('1.1') assert Version('1.9') < Version('1.10') assert Version('1.0') < Version('1.0a') assert Version('1.0a') < Version('1.0b')
def test_version_ne(): assert Version('1.1') != Version('2.2') assert Version('1.0a') != Version('1.0')
def test_version_eq(): assert Version('1') == Version('1.0') assert Version('1.0') == Version('1.0.0') assert Version('1.0a') == Version('1.0.0a')
def test_str_cmp(): assert Version('1.0') == '1.0'
def test_str(): assert str(Version('1.0')) == '1.0' assert str(Version('1.0a')) == '1.0a'
def test_malformed(): try: Version('this is not a valid string') assert False, 'Accepted a bogus version string' except ValueError: pass