-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest_check_min_required_version.py
More file actions
192 lines (165 loc) · 6.49 KB
/
test_check_min_required_version.py
File metadata and controls
192 lines (165 loc) · 6.49 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
"""Tests for check_min_required_version.py."""
from unittest import mock
from check_min_required_version import (
check_min_versions,
main,
parse_min_version,
)
class TestParseMinVersion:
def test_extracts_min_version(self):
assert parse_min_version("uipath-core>=0.5.4, <0.6.0", "uipath-core") == "0.5.4"
def test_extracts_min_version_no_upper_bound(self):
assert parse_min_version("uipath-core>=0.5.4", "uipath-core") == "0.5.4"
def test_returns_none_for_different_package(self):
assert parse_min_version("uipath-core>=0.5.4", "uipath-platform") is None
def test_returns_none_for_no_min_version(self):
assert parse_min_version("uipath-core==0.5.4", "uipath-core") is None
def test_handles_whitespace(self):
assert (
parse_min_version(" uipath-core>=1.2.3, <2.0.0 ", "uipath-core")
== "1.2.3"
)
class TestCheckMinVersions:
def _make_pyproject(self, name, version, dependencies=None):
data = {"project": {"name": name, "version": version}}
if dependencies is not None:
data["project"]["dependencies"] = dependencies
return data
def test_passes_when_min_version_matches(self, tmp_path):
core = self._make_pyproject("uipath-core", "0.5.7")
platform = self._make_pyproject(
"uipath-platform", "0.1.4", ["uipath-core>=0.5.7, <0.6.0"]
)
with (
mock.patch(
"check_min_required_version.read_pyproject",
side_effect=lambda d: {
"uipath-core": core,
"uipath-platform": platform,
}.get(d),
),
mock.patch(
"check_min_required_version.PACKAGES_DIR",
tmp_path,
),
):
# Create fake package dirs
(tmp_path / "uipath-core").mkdir()
(tmp_path / "uipath-core" / "pyproject.toml").touch()
(tmp_path / "uipath-platform").mkdir()
(tmp_path / "uipath-platform" / "pyproject.toml").touch()
errors = check_min_versions({"uipath-core", "uipath-platform"})
assert errors == []
def test_fails_when_min_version_outdated(self, tmp_path):
core = self._make_pyproject("uipath-core", "0.5.7")
platform = self._make_pyproject(
"uipath-platform", "0.1.4", ["uipath-core>=0.5.4, <0.6.0"]
)
with (
mock.patch(
"check_min_required_version.read_pyproject",
side_effect=lambda d: {
"uipath-core": core,
"uipath-platform": platform,
}.get(d),
),
mock.patch(
"check_min_required_version.PACKAGES_DIR",
tmp_path,
),
):
(tmp_path / "uipath-core").mkdir()
(tmp_path / "uipath-core" / "pyproject.toml").touch()
(tmp_path / "uipath-platform").mkdir()
(tmp_path / "uipath-platform" / "pyproject.toml").touch()
errors = check_min_versions({"uipath-core", "uipath-platform"})
assert len(errors) == 1
assert "uipath-core>=0.5.4" in errors[0]
assert "uipath-core>=0.5.7" in errors[0]
def test_skips_when_dependency_not_changed(self, tmp_path):
core = self._make_pyproject("uipath-core", "0.5.7")
platform = self._make_pyproject(
"uipath-platform", "0.1.4", ["uipath-core>=0.5.4, <0.6.0"]
)
with (
mock.patch(
"check_min_required_version.read_pyproject",
side_effect=lambda d: {
"uipath-core": core,
"uipath-platform": platform,
}.get(d),
),
mock.patch(
"check_min_required_version.PACKAGES_DIR",
tmp_path,
),
):
(tmp_path / "uipath-core").mkdir()
(tmp_path / "uipath-core" / "pyproject.toml").touch()
(tmp_path / "uipath-platform").mkdir()
(tmp_path / "uipath-platform" / "pyproject.toml").touch()
# Only platform changed, core not changed — should pass
errors = check_min_versions({"uipath-platform"})
assert errors == []
def test_multiple_violations(self, tmp_path):
core = self._make_pyproject("uipath-core", "0.5.7")
platform = self._make_pyproject(
"uipath-platform", "0.1.4", ["uipath-core>=0.5.2, <0.6.0"]
)
uipath = self._make_pyproject(
"uipath",
"2.10.26",
["uipath-core>=0.5.2, <0.6.0", "uipath-platform>=0.1.0, <0.2.0"],
)
pyprojects = {
"uipath-core": core,
"uipath-platform": platform,
"uipath": uipath,
}
with (
mock.patch(
"check_min_required_version.read_pyproject",
side_effect=lambda d: pyprojects.get(d),
),
mock.patch(
"check_min_required_version.PACKAGES_DIR",
tmp_path,
),
):
for name in pyprojects:
(tmp_path / name).mkdir()
(tmp_path / name / "pyproject.toml").touch()
errors = check_min_versions({"uipath-core", "uipath-platform", "uipath"})
# platform has outdated core dep, uipath has outdated core and platform deps
assert len(errors) == 3
class TestMain:
def test_no_changed_packages(self):
with mock.patch(
"check_min_required_version.get_changed_packages", return_value=set()
):
assert main() == 0
def test_passes_when_versions_correct(self):
with (
mock.patch(
"check_min_required_version.get_changed_packages",
return_value={"uipath-core", "uipath-platform"},
),
mock.patch(
"check_min_required_version.check_min_versions",
return_value=[],
),
):
assert main() == 0
def test_fails_when_versions_outdated(self):
with (
mock.patch(
"check_min_required_version.get_changed_packages",
return_value={"uipath-core", "uipath-platform"},
),
mock.patch(
"check_min_required_version.check_min_versions",
return_value=["some error"],
),
):
assert main() == 1