-
-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathtest_tags.py
More file actions
101 lines (67 loc) · 2.05 KB
/
test_tags.py
File metadata and controls
101 lines (67 loc) · 2.05 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from commitizen.git import GitTag
from commitizen.tags import TagRules
def _git_tag(name: str) -> GitTag:
return GitTag(name, "rev", "2024-01-01")
def test_find_tag_for_partial_version_returns_latest_match():
tags = [
_git_tag("1.2.0"),
_git_tag("1.2.2"),
_git_tag("1.2.1"),
_git_tag("1.3.0"),
]
rules = TagRules()
found = rules.find_tag_for(tags, "1.2")
assert found is not None
assert found.name == "1.2.2"
def test_find_tag_for_full_version_remains_exact():
tags = [
_git_tag("1.2.0"),
_git_tag("1.2.2"),
_git_tag("1.2.1"),
]
rules = TagRules()
found = rules.find_tag_for(tags, "1.2.1")
assert found is not None
assert found.name == "1.2.1"
def test_find_tag_for_partial_version_with_prereleases_prefers_latest_version():
tags = [
_git_tag("1.2.0b1"),
_git_tag("1.2.0"),
_git_tag("1.2.1b1"),
]
rules = TagRules()
found = rules.find_tag_for(tags, "1.2")
assert found is not None
# 1.2.1b1 > 1.2.0 so it should be selected
assert found.name == "1.2.1b1"
def test_find_tag_for_partial_version_respects_tag_format():
tags = [
_git_tag("v1.2.0"),
_git_tag("v1.2.1"),
_git_tag("v1.3.0"),
]
rules = TagRules(tag_format="v$version")
found = rules.find_tag_for(tags, "1.2")
assert found is not None
assert found.name == "v1.2.1"
found = rules.find_tag_for(tags, "1")
assert found is not None
assert found.name == "v1.3.0"
def test_find_tag_for_partial_version_returns_none_when_no_match():
tags = [
_git_tag("2.0.0"),
_git_tag("2.1.0"),
]
rules = TagRules()
found = rules.find_tag_for(tags, "1.2")
assert found is None
def test_find_tag_for_partial_version_ignores_invalid_tags():
tags = [
_git_tag("not-a-version"),
_git_tag("1.2.0"),
_git_tag("1.2.1"),
]
rules = TagRules()
found = rules.find_tag_for(tags, "1.2")
assert found is not None
assert found.name == "1.2.1"