Skip to content

Commit ab1972d

Browse files
committed
move the pep440 version tests to its own file
1 parent aca2ad8 commit ab1972d

File tree

5 files changed

+162
-149
lines changed

5 files changed

+162
-149
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
55
# To update these lines, execute
66
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
7-
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
8-
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
7+
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
8+
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
99

1010
test --test_output=errors
1111

tests/py_wheel/py_wheel_tests.bzl

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
1717
load("@rules_testing//lib:truth.bzl", "matching")
1818
load("@rules_testing//lib:util.bzl", rt_util = "util")
1919
load("//python:packaging.bzl", "py_wheel")
20-
load("//python/private:version.bzl", "version") # buildifier: disable=bzl-visibility
2120

2221
_basic_tests = []
2322
_tests = []
@@ -168,106 +167,6 @@ def _test_content_type_from_description_impl(env, target):
168167

169168
_tests.append(_test_content_type_from_description)
170169

171-
def _test_pep440_normalization(env):
172-
prefixes = ["v", " v", " \t\r\nv"]
173-
epochs = {
174-
"": ["", "0!", "00!"],
175-
"1!": ["1!", "001!"],
176-
"200!": ["200!", "00200!"],
177-
}
178-
releases = {
179-
"0.1": ["0.1", "0.01"],
180-
"2023.7.19": ["2023.7.19", "2023.07.19"],
181-
}
182-
pres = {
183-
"": [""],
184-
"a0": ["a", ".a", "-ALPHA0", "_alpha0", ".a0"],
185-
"a4": ["alpha4", ".a04"],
186-
"b0": ["b", ".b", "-BETA0", "_beta0", ".b0"],
187-
"b5": ["beta05", ".b5"],
188-
"rc0": ["C", "_c0", "RC", "_rc0", "-preview_0"],
189-
}
190-
explicit_posts = {
191-
"": [""],
192-
".post0": [],
193-
".post1": [".post1", "-r1", "_rev1"],
194-
}
195-
implicit_posts = [[".post1", "-1"], [".post2", "-2"]]
196-
devs = {
197-
"": [""],
198-
".dev0": ["dev", "-DEV", "_Dev-0"],
199-
".dev9": ["DEV9", ".dev09", ".dev9"],
200-
".dev{BUILD_TIMESTAMP}": [
201-
"-DEV{BUILD_TIMESTAMP}",
202-
"_dev_{BUILD_TIMESTAMP}",
203-
],
204-
}
205-
locals = {
206-
"": [""],
207-
"+ubuntu.7": ["+Ubuntu_7", "+ubuntu-007"],
208-
"+ubuntu.r007": ["+Ubuntu_R007"],
209-
}
210-
epochs = [
211-
[normalized_epoch, input_epoch]
212-
for normalized_epoch, input_epochs in epochs.items()
213-
for input_epoch in input_epochs
214-
]
215-
releases = [
216-
[normalized_release, input_release]
217-
for normalized_release, input_releases in releases.items()
218-
for input_release in input_releases
219-
]
220-
pres = [
221-
[normalized_pre, input_pre]
222-
for normalized_pre, input_pres in pres.items()
223-
for input_pre in input_pres
224-
]
225-
explicit_posts = [
226-
[normalized_post, input_post]
227-
for normalized_post, input_posts in explicit_posts.items()
228-
for input_post in input_posts
229-
]
230-
pres_and_posts = [
231-
[normalized_pre + normalized_post, input_pre + input_post]
232-
for normalized_pre, input_pre in pres
233-
for normalized_post, input_post in explicit_posts
234-
] + [
235-
[normalized_pre + normalized_post, input_pre + input_post]
236-
for normalized_pre, input_pre in pres
237-
for normalized_post, input_post in implicit_posts
238-
if input_pre == "" or input_pre[-1].isdigit()
239-
]
240-
devs = [
241-
[normalized_dev, input_dev]
242-
for normalized_dev, input_devs in devs.items()
243-
for input_dev in input_devs
244-
]
245-
locals = [
246-
[normalized_local, input_local]
247-
for normalized_local, input_locals in locals.items()
248-
for input_local in input_locals
249-
]
250-
postfixes = ["", " ", " \t\r\n"]
251-
i = 0
252-
for nepoch, iepoch in epochs:
253-
for nrelease, irelease in releases:
254-
for nprepost, iprepost in pres_and_posts:
255-
for ndev, idev in devs:
256-
for nlocal, ilocal in locals:
257-
prefix = prefixes[i % len(prefixes)]
258-
postfix = postfixes[(i // len(prefixes)) % len(postfixes)]
259-
env.expect.that_str(
260-
version.normalize(
261-
prefix + iepoch + irelease + iprepost +
262-
idev + ilocal + postfix,
263-
),
264-
).equals(
265-
nepoch + nrelease + nprepost + ndev + nlocal,
266-
)
267-
i += 1
268-
269-
_basic_tests.append(_test_pep440_normalization)
270-
271170
def py_wheel_test_suite(name):
272171
test_suite(
273172
name = name,

tests/pypi/pep508/evaluate_tests.bzl

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""Tests for construction of Python version matching config settings."""
1515

1616
load("@rules_testing//lib:test_suite.bzl", "test_suite")
17-
load("//python/private:version.bzl", "version") # buildifier: disable=bzl-visibility
1817
load("//python/private/pypi:pep508_env.bzl", pep508_env = "env") # buildifier: disable=bzl-visibility
1918
load("//python/private/pypi:pep508_evaluate.bzl", "evaluate", "tokenize") # buildifier: disable=bzl-visibility
2019

@@ -318,51 +317,6 @@ def _misc_expressions(env):
318317

319318
_tests.append(_misc_expressions)
320319

321-
def _test_ordering(env):
322-
want = [
323-
# Taken from https://peps.python.org/pep-0440/#summary-of-permitted-suffixes-and-relative-ordering
324-
"1.dev0",
325-
"1.0.dev456",
326-
"1.0a1",
327-
"1.0a2.dev456",
328-
"1.0a12.dev456",
329-
"1.0a12",
330-
"1.0b1.dev456",
331-
"1.0b1.dev457",
332-
"1.0b2",
333-
"1.0b2.post345.dev456",
334-
"1.0b2.post345.dev457",
335-
"1.0b2.post345",
336-
"1.0rc1.dev456",
337-
"1.0rc1",
338-
"1.0",
339-
"1.0+abc.5",
340-
"1.0+abc.7",
341-
"1.0+5",
342-
"1.0.post456.dev34",
343-
"1.0.post456",
344-
"1.0.15",
345-
"1.1.dev1",
346-
"1!0.1",
347-
]
348-
349-
for lower, higher in zip(want[:-1], want[1:]):
350-
lower = version.parse(lower, strict = True)
351-
higher = version.parse(higher, strict = True)
352-
353-
lower_key = version.key(lower)
354-
higher_key = version.key(higher)
355-
356-
if not lower_key < higher_key:
357-
env.fail("Expected '{}'.key() to be smaller than '{}'.key(), but got otherwise: {} > {}".format(
358-
lower.string,
359-
higher.string,
360-
lower_key,
361-
higher_key,
362-
))
363-
364-
_tests.append(_test_ordering)
365-
366320
def evaluate_test_suite(name): # buildifier: disable=function-docstring
367321
test_suite(
368322
name = name,

tests/version/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
load(":version_test.bzl", "version_test_suite")
2+
3+
version_test_suite(name = "version_tests")

tests/version/version_test.bzl

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
""
2+
3+
load("@rules_testing//lib:analysis_test.bzl", "test_suite")
4+
load("//python/private:version.bzl", "version") # buildifier: disable=bzl-visibility
5+
6+
_tests = []
7+
8+
def _test_normalization(env):
9+
prefixes = ["v", " v", " \t\r\nv"]
10+
epochs = {
11+
"": ["", "0!", "00!"],
12+
"1!": ["1!", "001!"],
13+
"200!": ["200!", "00200!"],
14+
}
15+
releases = {
16+
"0.1": ["0.1", "0.01"],
17+
"2023.7.19": ["2023.7.19", "2023.07.19"],
18+
}
19+
pres = {
20+
"": [""],
21+
"a0": ["a", ".a", "-ALPHA0", "_alpha0", ".a0"],
22+
"a4": ["alpha4", ".a04"],
23+
"b0": ["b", ".b", "-BETA0", "_beta0", ".b0"],
24+
"b5": ["beta05", ".b5"],
25+
"rc0": ["C", "_c0", "RC", "_rc0", "-preview_0"],
26+
}
27+
explicit_posts = {
28+
"": [""],
29+
".post0": [],
30+
".post1": [".post1", "-r1", "_rev1"],
31+
}
32+
implicit_posts = [[".post1", "-1"], [".post2", "-2"]]
33+
devs = {
34+
"": [""],
35+
".dev0": ["dev", "-DEV", "_Dev-0"],
36+
".dev9": ["DEV9", ".dev09", ".dev9"],
37+
".dev{BUILD_TIMESTAMP}": [
38+
"-DEV{BUILD_TIMESTAMP}",
39+
"_dev_{BUILD_TIMESTAMP}",
40+
],
41+
}
42+
locals = {
43+
"": [""],
44+
"+ubuntu.7": ["+Ubuntu_7", "+ubuntu-007"],
45+
"+ubuntu.r007": ["+Ubuntu_R007"],
46+
}
47+
epochs = [
48+
[normalized_epoch, input_epoch]
49+
for normalized_epoch, input_epochs in epochs.items()
50+
for input_epoch in input_epochs
51+
]
52+
releases = [
53+
[normalized_release, input_release]
54+
for normalized_release, input_releases in releases.items()
55+
for input_release in input_releases
56+
]
57+
pres = [
58+
[normalized_pre, input_pre]
59+
for normalized_pre, input_pres in pres.items()
60+
for input_pre in input_pres
61+
]
62+
explicit_posts = [
63+
[normalized_post, input_post]
64+
for normalized_post, input_posts in explicit_posts.items()
65+
for input_post in input_posts
66+
]
67+
pres_and_posts = [
68+
[normalized_pre + normalized_post, input_pre + input_post]
69+
for normalized_pre, input_pre in pres
70+
for normalized_post, input_post in explicit_posts
71+
] + [
72+
[normalized_pre + normalized_post, input_pre + input_post]
73+
for normalized_pre, input_pre in pres
74+
for normalized_post, input_post in implicit_posts
75+
if input_pre == "" or input_pre[-1].isdigit()
76+
]
77+
devs = [
78+
[normalized_dev, input_dev]
79+
for normalized_dev, input_devs in devs.items()
80+
for input_dev in input_devs
81+
]
82+
locals = [
83+
[normalized_local, input_local]
84+
for normalized_local, input_locals in locals.items()
85+
for input_local in input_locals
86+
]
87+
postfixes = ["", " ", " \t\r\n"]
88+
i = 0
89+
for nepoch, iepoch in epochs:
90+
for nrelease, irelease in releases:
91+
for nprepost, iprepost in pres_and_posts:
92+
for ndev, idev in devs:
93+
for nlocal, ilocal in locals:
94+
prefix = prefixes[i % len(prefixes)]
95+
postfix = postfixes[(i // len(prefixes)) % len(postfixes)]
96+
env.expect.that_str(
97+
version.normalize(
98+
prefix + iepoch + irelease + iprepost +
99+
idev + ilocal + postfix,
100+
),
101+
).equals(
102+
nepoch + nrelease + nprepost + ndev + nlocal,
103+
)
104+
i += 1
105+
106+
_tests.append(_test_normalization)
107+
108+
def _test_ordering(env):
109+
want = [
110+
# Taken from https://peps.python.org/pep-0440/#summary-of-permitted-suffixes-and-relative-ordering
111+
"1.dev0",
112+
"1.0.dev456",
113+
"1.0a1",
114+
"1.0a2.dev456",
115+
"1.0a12.dev456",
116+
"1.0a12",
117+
"1.0b1.dev456",
118+
"1.0b1.dev457",
119+
"1.0b2",
120+
"1.0b2.post345.dev456",
121+
"1.0b2.post345.dev457",
122+
"1.0b2.post345",
123+
"1.0rc1.dev456",
124+
"1.0rc1",
125+
"1.0",
126+
"1.0+abc.5",
127+
"1.0+abc.7",
128+
"1.0+5",
129+
"1.0.post456.dev34",
130+
"1.0.post456",
131+
"1.0.15",
132+
"1.1.dev1",
133+
"1!0.1",
134+
]
135+
136+
for lower, higher in zip(want[:-1], want[1:]):
137+
lower = version.parse(lower, strict = True)
138+
higher = version.parse(higher, strict = True)
139+
140+
lower_key = version.key(lower)
141+
higher_key = version.key(higher)
142+
143+
if not lower_key < higher_key:
144+
env.fail("Expected '{}'.key() to be smaller than '{}'.key(), but got otherwise: {} > {}".format(
145+
lower.string,
146+
higher.string,
147+
lower_key,
148+
higher_key,
149+
))
150+
151+
_tests.append(_test_ordering)
152+
153+
def version_test_suite(name):
154+
test_suite(
155+
name = name,
156+
basic_tests = _tests,
157+
)

0 commit comments

Comments
 (0)