-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathtest_semver.py
More file actions
82 lines (61 loc) · 2.28 KB
/
test_semver.py
File metadata and controls
82 lines (61 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pytest # noqa
from semver import Version
@pytest.mark.parametrize(
"string,expected", [("rc", "rc"), ("rc.1", "rc.2"), ("2x", "3x")]
)
def test_should_private_increment_string(string, expected):
assert Version._increment_string(string) == expected
@pytest.mark.parametrize(
"ver",
[
{"major": -1},
{"major": 1, "minor": -2},
{"major": 1, "minor": 2, "patch": -3},
{"major": 1, "minor": -2, "patch": 3},
],
)
def test_should_not_allow_negative_numbers(ver):
with pytest.raises(ValueError, match=".* is negative. .*"):
Version(**ver)
def test_should_versioninfo_to_dict(version):
resultdict = version.to_dict()
assert isinstance(resultdict, dict), "Got type from to_dict"
assert list(resultdict.keys()) == ["major", "minor", "patch", "prerelease", "build"]
def test_should_versioninfo_to_tuple(version):
result = version.to_tuple()
assert isinstance(result, tuple), "Got type from to_dict"
assert len(result) == 5, "Different length from to_tuple()"
def test_version_info_should_be_iterable(version):
assert tuple(version) == (
version.major,
version.minor,
version.patch,
version.prerelease,
version.build,
)
def test_should_be_able_to_use_strings_as_major_minor_patch():
v = Version("1", "2", "3")
assert isinstance(v.major, int)
assert isinstance(v.minor, int)
assert isinstance(v.patch, int)
assert v.prerelease is None
assert v.build is None
assert Version("1", "2", "3") == Version(1, 2, 3)
def test_using_non_numeric_string_as_major_minor_patch_throws():
with pytest.raises(ValueError):
Version("a")
with pytest.raises(ValueError):
Version(1, "a")
with pytest.raises(ValueError):
Version(1, 2, "a")
def test_should_be_able_to_use_integers_as_prerelease_build():
v = Version(1, 2, 3, 4, 5)
assert isinstance(v.prerelease, str)
assert isinstance(v.build, str)
assert Version(1, 2, 3, 4, 5) == Version(1, 2, 3, "4", "5")
def test_should_versioninfo_isvalid():
assert Version.isvalid("1.0.0") is True
assert Version.isvalid("foo") is False
def test_versioninfo_compare_should_raise_when_passed_invalid_value():
with pytest.raises(TypeError):
Version(1, 2, 3).compare(4)