13
13
# limitations under the License.
14
14
"""Tests for construction of Python version matching config settings."""
15
15
16
+ load ("@//python:versions.bzl" , "MINOR_MAPPING" )
16
17
load ("@rules_testing//lib:analysis_test.bzl" , "analysis_test" )
17
18
load ("@rules_testing//lib:test_suite.bzl" , "test_suite" )
18
19
load ("@rules_testing//lib:truth.bzl" , "subjects" )
@@ -30,6 +31,7 @@ _subject = rule(
30
31
<
8000
span class=pl-s>"match_micro": attr .string (),
31
32
"match_minor" : attr .string (),
32
33
"no_match" : attr .string (),
34
+ "no_match_micro" : attr .string (),
33
35
},
34
36
)
35
37
@@ -74,6 +76,54 @@ def _test_minor_version_matching_impl(env, target):
74
76
75
77
_tests .append (_test_minor_version_matching )
76
78
79
+ def _test_latest_micro_version_matching (name ):
80
+ rt_util .helper_target (
81
+ _subject ,
82
+ name = name + "_subject" ,
83
+ match_minor = select ({
84
+ "//python/config_settings:is_python_3.12" : "matched-3.12" ,
85
+ "//conditions:default" : "matched-default" ,
86
+ }),
87
+ match_micro = select ({
88
+ "//python/config_settings:is_python_" + MINOR_MAPPING ["3.12" ]: "matched-3.12" ,
89
+ "//conditions:default" : "matched-default" ,
90
+ }),
91
+ no_match_micro = select ({
92
+ "//python/config_settings:is_python_3.12.0" : "matched-3.12" ,
93
+ "//conditions:default" : "matched-default" ,
94
+ }),
95
+ no_match = select ({
96
+ "//python/config_settings:is_python_" + MINOR_MAPPING ["3.11" ]: "matched-3.11" ,
97
+ "//conditions:default" : "matched-default" ,
98
+ }),
99
+ )
100
+
101
+ analysis_test (
102
+ name = name ,
103
+ target = name + "_subject" ,
104
+ impl = _test_latest_micro_version_matching_impl ,
105
+ config_settings = {
106
+ str (Label ("//python/config_settings:python_version" )): "3.12" ,
107
+ },
108
+ )
109
+
110
+ def _test_latest_micro_version_matching_impl (env , target ):
111
+ target = env .expect .that_target (target )
112
+ target .attr ("match_minor" , factory = subjects .str ).equals (
113
+ "matched-3.12" ,
114
+ )
115
+ target .attr ("match_micro" , factory = subjects .str ).equals (
116
+ "matched-3.12" ,
117
+ )
118
+ target .attr ("no_match_micro" , factory = subjects .str ).equals (
119
+ "matched-default" ,
120
+ )
121
+ target .attr ("no_match" , factory = subjects .str ).equals (
122
+ "matched-default" ,
123
+ )
124
+
125
+ _tests .append (_test_latest_micro_version_matching )
126
+
77
127
def construct_config_settings_test_suite (name ):
78
128
test_suite (
79
129
name = name ,
0 commit comments