@@ -19,6 +19,11 @@ load("//python/private/pypi:pep508_evaluate.bzl", "evaluate", "tokenize") # bui
1919
2020_tests = []
2121
22+ def _check_evaluate (env , expr , expected , values , strict = True ):
23+ env .expect .where (
24+ expression = expr , values = values
25+ ).that_bool (evaluate (expr , env = values , strict = strict )).equals (expected )
26+
2227def _tokenize_tests (env ):
2328 for input , want in {
2429 "" : [],
@@ -82,23 +87,11 @@ def _evaluate_non_version_env_tests(env):
8287 "{} > 'osx'" .format (var_name ): False ,
8388 "{} >= 'osx'" .format (var_name ): True ,
8489 }.items ():
85- got = evaluate (
86- input ,
87- env = marker_env ,
88- )
89- env .expect .where (
90- expr = input ,
91- env = marker_env ,
92- ).that_bool (got ).equals (want )
90+ _check_evaluate (env , input , want , marker_env )
9391
9492 # Check that the non-strict eval gives us back the input when no
9593 # env is supplied.
96- got = evaluate (
97- input ,
98- env = {},
99- strict = False ,
100- )
101- env .expect .that_bool (got ).equals (input .replace ("'" , '"' ))
94+ _check_evaluate (env , input , input .replace ("'" , '"' ), {}, strict = False )
10295
10396_tests .append (_evaluate_non_version_env_tests )
10497
@@ -132,20 +125,11 @@ def _evaluate_version_env_tests(env):
132125 "{} === '3.7.9'" .format (var_name ): True ,
133126 "{} == '3.7.9+rc2'" .format (var_name ): True ,
134127 }.items (): # buildifier: @unsorted-dict-items
135- got = evaluate (
136- input ,
137- env = marker_env ,
138- )
139- env .expect .that_collection ((input , got )).contains_exactly ((input , want ))
128+ _check_evaluate (env , input , want , marker_env )
140129
141130 # Check that the non-strict eval gives us back the input when no
142131 # env is supplied.
143- got = evaluate (
144- input ,
145- env = {},
146- strict = False ,
147- )
148- env .expect .that_bool (got ).equals (input .replace ("'" , '"' ))
132+ _check_evaluate (env , input , input .replace ("'" , '"' ), {}, strict = False )
149133
150134_tests .append (_evaluate_version_env_tests )
151135
@@ -155,29 +139,15 @@ def _evaluate_platform_version_is_special(env):
155139
156140 # When the platform version is not
157141 input = "platform_version == '0'"
158- got = evaluate (
159- input ,
160- env = marker_env ,
161- )
162- env .expect .that_collection ((input , got )).contains_exactly ((input , False ))
142+ _check_evaluate (env , input , False , marker_env )
163143
164144 # And when I compare it as string
165145 input = "'FooBar' in platform_version"
166- got = evaluate (
167- input ,
168- env = marker_env ,
169- )
170- env .expect .that_collection ((input , got )).contains_exactly ((input , True ))
171-
146+ _check_evaluate (env , input , True , marker_env )
172147
173148 # Check that the non-strict eval gives us back the input when no
174149 # env is supplied.
175- got = evaluate (
176- input ,
177- env = {},
178- strict = False ,
179- )
180- env .expect .that_bool (got ).equals (input .replace ("'" , '"' ))
150+ _check_evaluate (env , input , input .replace ("'" , '"' ), {}, strict = False )
181151
182152_tests .append (_evaluate_platform_version_is_special )
183153
@@ -228,13 +198,7 @@ def _logical_expression_tests(env):
228198 "not not os_name == 'foo'" : True ,
229199 "not not not os_name == 'foo'" : False ,
230200 }.items (): # buildifier: @unsorted-dict-items
231- got = evaluate (
232- input ,
233- env = {
234- "os_name" : "foo" ,
235- },
236- )
237- env .expect .that_collection ((input , got )).contains_exactly ((input , want ))
201+ _check_evaluate (env , input , want , {"os_name" : "foo" })
238202
239203 if not input .strip ("()" ):
240204 # These cases will just return True, because they will be evaluated
@@ -243,12 +207,7 @@ def _logical_expression_tests(env):
243207
244208 # Check that the non-strict eval gives us back the input when no env
245209 # is supplied.
246- got = evaluate (
247- input ,
248- env = {},
249- strict = False ,
250- )
251- env .expect .that_bool (got ).equals (input .replace ("'" , '"' ))
210+ _check_evaluate (env , input , input .replace ("'" , '"' ), {}, strict = False )
252211
253212_tests .append (_logical_expression_tests )
254213
@@ -277,6 +236,7 @@ def _evaluate_partial_only_extra(env):
277236 strict = False ,
278237 )
279238 env .expect .that_bool (got ).equals (want )
239+ _check_evaluate (env , input , want , env = {"extra" : extra }, strict = False )
280240
281241_tests .append (_evaluate_partial_only_extra )
282242
@@ -301,11 +261,7 @@ def _evaluate_with_aliases(env):
301261 },
302262 }.items (): # buildifier: @unsorted-dict-items
303263 for input , want in tests .items ():
304- got = evaluate (
305- input ,
306- env = pep508_env (target_platform ),
307- )
308- env .expect .that_bool (got ).equals (want )
264+ _check_evaluate (env , input , want , pep508_env (target_platform ))
309265
310266_tests .append (_evaluate_with_aliases )
311267
0 commit comments