forked from NVIDIA/cuda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_check_release_notes.py
More file actions
164 lines (124 loc) · 6.06 KB
/
Copy pathtest_check_release_notes.py
File metadata and controls
164 lines (124 loc) · 6.06 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
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from check_release_notes import (
check_release_notes,
is_post_release,
main,
parse_version_from_tag,
)
class TestParseVersionFromTag:
def test_plain_tag_bindings(self):
assert parse_version_from_tag("v13.1.0", "cuda-bindings") == "13.1.0"
def test_plain_tag_python(self):
assert parse_version_from_tag("v13.1.0", "cuda-python") == "13.1.0"
def test_component_prefix_core(self):
assert parse_version_from_tag("cuda-core-v0.7.0", "cuda-core") == "0.7.0"
def test_component_prefix_pathfinder(self):
assert parse_version_from_tag("cuda-pathfinder-v1.5.2", "cuda-pathfinder") == "1.5.2"
def test_post_release(self):
assert parse_version_from_tag("v12.6.2.post1", "cuda-bindings") == "12.6.2.post1"
def test_invalid_tag(self):
assert parse_version_from_tag("not-a-tag", "cuda-core") is None
def test_no_v_prefix(self):
assert parse_version_from_tag("13.1.0", "cuda-bindings") is None
def test_component_prefix_mismatch(self):
# cuda-core-v* must not be accepted for component=cuda-pathfinder
assert parse_version_from_tag("cuda-core-v0.7.0", "cuda-pathfinder") is None
def test_bare_v_rejected_for_core(self):
# bare v* belongs to cuda-bindings/cuda-python, not cuda-core
assert parse_version_from_tag("v0.7.0", "cuda-core") is None
def test_unknown_component(self):
assert parse_version_from_tag("v13.1.0", "bogus") is None
def test_path_traversal_rejected(self):
assert parse_version_from_tag("v1.0.0/../evil", "cuda-bindings") is None
def test_path_separator_rejected(self):
assert parse_version_from_tag("v1/2/3", "cuda-bindings") is None
def test_leading_dot_rejected(self):
assert parse_version_from_tag("v.1.0", "cuda-bindings") is None
def test_whitespace_rejected(self):
assert parse_version_from_tag("v1.0.0 ", "cuda-bindings") is None
def test_trailing_suffix_rejected(self):
# \w permits alphanumerics + underscore only; hyphens and shell meta-chars are out
assert parse_version_from_tag("v1.0.0-extra", "cuda-bindings") is None
class TestIsPostRelease:
def test_normal(self):
assert not is_post_release("13.1.0")
def test_post(self):
assert is_post_release("12.6.2.post1")
def test_post_no_number(self):
assert is_post_release("1.0.0.post")
class TestCheckReleaseNotes:
def _make_notes(self, tmp_path, pkg, version, content="Release notes."):
d = tmp_path / pkg / "docs" / "source" / "release"
d.mkdir(parents=True, exist_ok=True)
f = d / f"{version}-notes.rst"
f.write_text(content)
return f
def test_present_and_nonempty(self, tmp_path):
self._make_notes(tmp_path, "cuda_core", "0.7.0")
problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path))
assert problems == []
def test_missing(self, tmp_path):
problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path))
assert len(problems) == 1
assert problems[0][1] == "missing"
def test_empty(self, tmp_path):
self._make_notes(tmp_path, "cuda_core", "0.7.0", content="")
problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path))
assert len(problems) == 1
assert problems[0][1] == "empty"
def test_post_release_skipped(self, tmp_path):
problems = check_release_notes("v12.6.2.post1", "cuda-bindings", str(tmp_path))
assert problems == []
def test_invalid_tag(self, tmp_path):
problems = check_release_notes("not-a-tag", "cuda-core", str(tmp_path))
assert len(problems) == 1
assert "cannot parse" in problems[0][1]
def test_component_prefix_mismatch(self, tmp_path):
# Pass a cuda-core tag with component=cuda-pathfinder; must be rejected.
problems = check_release_notes("cuda-core-v0.7.0", "cuda-pathfinder", str(tmp_path))
assert len(problems) == 1
assert "cannot parse" in problems[0][1]
def test_unknown_component(self, tmp_path):
problems = check_release_notes("v13.1.0", "bogus", str(tmp_path))
assert len(problems) == 1
assert "unknown component" in problems[0][1]
def test_plain_v_tag(self, tmp_path):
self._make_notes(tmp_path, "cuda_python", "13.1.0")
problems = check_release_notes("v13.1.0", "cuda-python", str(tmp_path))
assert problems == []
class TestMain:
def test_success(self, tmp_path):
d = tmp_path / "cuda_core" / "docs" / "source" / "release"
d.mkdir(parents=True)
(d / "0.7.0-notes.rst").write_text("Notes here.")
rc = main(["--git-tag", "cuda-core-v0.7.0", "--component", "cuda-core", "--repo-root", str(tmp_path)])
assert rc == 0
def test_failure(self, tmp_path):
rc = main(["--git-tag", "cuda-core-v0.7.0", "--component", "cuda-core", "--repo-root", str(tmp_path)])
assert rc == 1
def test_post_skip(self, tmp_path):
rc = main(["--git-tag", "v12.6.2.post1", "--component", "cuda-bindings", "--repo-root", str(tmp_path)])
assert rc == 0
def test_unparsable_tag_returns_2(self, tmp_path):
rc = main(["--git-tag", "not-a-tag", "--component", "cuda-core", "--repo-root", str(tmp_path)])
assert rc == 2
def test_path_traversal_returns_2(self, tmp_path):
rc = main(["--git-tag", "v1.0.0/../evil", "--component", "cuda-bindings", "--repo-root", str(tmp_path)])
assert rc == 2
def test_component_prefix_mismatch_returns_2(self, tmp_path):
rc = main(
[
"--git-tag",
"cuda-core-v0.7.0",
"--component",
"cuda-pathfinder",
"--repo-root",
str(tmp_path),
]
)
assert rc == 2