1414
1515""
1616
17+ load ("@pythons_hub//:versions.bzl" , "MINOR_MAPPING" , "DEFAULT_PYTHON_VERSION" )
1718load ("//python:versions.bzl" , "PLATFORMS" , "TOOL_VERSIONS" )
19+ load ("//python/private:full_version.bzl" , "full_version" )
1820load ("//tests/support:sh_py_run_test.bzl" , "py_reconfig_test" )
1921
2022def define_toolchain_tests (name ):
@@ -30,7 +32,41 @@ def define_toolchain_tests(name):
3032 constraint_values = platform_info .compatible_with ,
3133 )
3234
33- for python_version , meta in TOOL_VERSIONS .items ():
35+ # First we expect the transitions with a specific version to always
36+ # give us that specific version
37+ exact_version_tests = {
38+ (v , v ): "python_{}_test" .format (v )
39+ for v in TOOL_VERSIONS
40+ }
41+ native .test_suite (
42+ name = "exact_version_tests" ,
43+ tests = exact_version_tests .values (),
44+ )
45+
46+ # Then we expect to get the version in the MINOR_MAPPING if we provide
47+ # the version from the MINOR_MAPPING
48+ minor_mapping_tests = {
49+ (minor , full ): "python_{}_test" .format (minor )
50+ for minor , full in MINOR_MAPPING .items ()
51+ }
52+ native .test_suite (
53+ name = "minor_mapping_tests" ,
54+ tests = minor_mapping_tests .values (),
55+ )
56+
57+ # Lastly, if we don't provide any version to the transition, we should
58+ # get the default version
59+ default_version = full_version (
60+ version = DEFAULT_PYTHON_VERSION ,
61+ minor_mapping = MINOR_MAPPING ,
62+ )
63+ default_version_tests = {
64+ (None , default_version ): "default_version_test"
65+ }
66+ tests = exact_version_tests | minor_mapping_tests | default_version_tests
67+
68+ for (input_python_version , expect_python_version ), test_name in tests .items ():
69+ meta = TOOL_VERSIONS [expect_python_version ]
3470 target_compatible_with = {
3571 "//conditions:default" : ["@platforms//:incompatible" ],
3672 }
@@ -39,12 +75,12 @@ def define_toolchain_tests(name):
3975 target_compatible_with [is_platform ] = []
4076
4177 py_reconfig_test (
42- name = "python_{}_test" . format ( python_version ) ,
78+ name = test_name ,
4379 srcs = ["python_toolchain_test.py" ],
4480 main = "python_toolchain_test.py" ,
45- python_version = python_version ,
81+ python_version = input_python_version ,
4682 env = {
47- "EXPECT_PYTHON_VERSION" : python_version ,
83+ "EXPECT_PYTHON_VERSION" : expect_python_version ,
4884 },
4985 deps = ["//python/runfiles" ],
5086 data = ["//tests/support:current_build_settings" ],
0 commit comments