Skip to content

Commit ec006ee

Browse files
committed
add unit tests and refine
1 parent c5a43f4 commit ec006ee

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

python/private/python.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ def parse_modules(*, module_ctx, _fail = fail):
250250
other_toolchains = []
251251
minor_mapping = list(config.minor_mapping.values())
252252
for t in toolchains:
253-
# TODO @aignas 2025-04-04: I am getting lost here when unit testing
253+
# FIXME @aignas 2025-04-04: How can we unit test that this ordering is
254+
# consistent with what would actually work?
254255
if config.minor_mapping.get(t.python_version, t.python_version) in minor_mapping:
255256
minor_version_toolchains.append(t)
256257
else:

tests/python/python_tests.bzl

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,16 @@ def _test_toolchain_ordering(env):
288288
py = parse_modules(
289289
module_ctx = _mock_mctx(
290290
_mod(
291-
name = "my_module",
292-
toolchain = [
293-
_toolchain("3.10"),
294-
_toolchain("3.10.15"),
295-
_toolchain("3.10.16"),
296-
_toolchain("3.10.11"),
297-
_toolchain("3.11.1"),
298-
_toolchain("3.11.10"),
299-
_toolchain("3.11.11", is_default = True),
300-
],
291+
name = "my_module",
292+
toolchain = [
293+
_toolchain("3.10"),
294+
_toolchain("3.10.15"),
295+
_toolchain("3.10.16"),
296+
_toolchain("3.10.11"),
297+
_toolchain("3.11.1"),
298+
_toolchain("3.11.10"),
299+
_toolchain("3.11.11", is_default = True),
300+
],
301301
),
302302
_mod(name = "rules_python", toolchain = [_toolchain("3.11")]),
303303
),
@@ -309,25 +309,29 @@ def _test_toolchain_ordering(env):
309309

310310
env.expect.that_str(py.default_python_version).equals("3.11")
311311
env.expect.that_dict(py.config.minor_mapping).contains_exactly({
312-
"3.10": "3.10.16",
313-
"3.11": "3.11.11",
314-
"3.12": "3.12.9",
315-
"3.13": "3.13.2",
316-
"3.8": "3.8.20",
317-
"3.9": "3.9.21",
312+
"3.10": "3.10.16",
313+
"3.11": "3.11.11",
314+
"3.12": "3.12.9",
315+
"3.13": "3.13.2",
316+
"3.8": "3.8.20",
317+
"3.9": "3.9.21",
318318
})
319319
env.expect.that_collection(got_versions).contains_exactly([
320-
# First the full-version toolchains that are in minor_mapping
321-
# so that they get matched first if only the `python_version` is in MINOR_MAPPING
322-
"3.10.16",
323-
# Next, the rest, where we will match things based on the `python_version` being
324-
# the same
325-
"3.10",
326-
"3.10.15",
327-
"3.10.11",
328-
"3.11.1",
329-
"3.11.10",
330-
"3.11.11",
320+
# First the full-version toolchains that are in minor_mapping
321+
# so that they get matched first if only the `python_version` is in MINOR_MAPPING
322+
#
323+
# The default version is always set in the `python_version` flag, so know, that
324+
# the default match will be somewhere in the first bunch.
325+
"3.10",
326+
"3.10.16",
327+
"3.11",
328+
"3.11.11",
329+
# Next, the rest, where we will match things based on the `python_version` being
330+
# the same
331+
"3.10.15",
332+
"3.10.11",
333+
"3.11.1",
334+
"3.11.10",
331335
]).in_order()
332336

333337
_tests.append(_test_toolchain_ordering)

0 commit comments

Comments
 (0)