| 
1 | 1 | load("@rules_testing//lib:analysis_test.bzl", "analysis_test")  | 
2 | 2 | load("@rules_testing//lib:test_suite.bzl", "test_suite")  | 
 | 3 | +load("@rules_testing//lib:util.bzl", "TestingAspectInfo")  | 
3 | 4 | load("//python/private/pypi:dependency_specifier_flag.bzl", "depspec_flag")  | 
4 | 5 | load("//python/private/pypi:pep508_env.bzl", pep508_env = "env")  # buildifier: disable=bzl-visibility  | 
5 | 6 | load("//python/private/pypi:pep508_evaluate.bzl", "evaluate", "tokenize")  # buildifier: disable=bzl-visibility  | 
6 | 7 | load("//tests/support:support.bzl", "PYTHON_VERSION")  | 
7 | 8 | 
 
  | 
8 | 9 | _tests = []  | 
9 | 10 | 
 
  | 
10 |  | -def _test_whatever(name):  | 
 | 11 | +def _test_expr(name):  | 
11 | 12 |     def impl(env, target):  | 
 | 13 | +        attrs = target[TestingAspectInfo].attrs  | 
 | 14 | + | 
12 | 15 |         # todo: create FeatureFlagInfo subject  | 
13 | 16 |         actual = target[config_common.FeatureFlagInfo].value  | 
14 |  | -        env.expect.that_str(actual).equals("yes")  | 
 | 17 | +        env.expect.where(  | 
 | 18 | +            expression = attrs.expression,  | 
 | 19 | +        ).that_str(actual).equals("yes")  | 
15 | 20 | 
 
  | 
16 |  | -    depspec_flag(  | 
17 |  | -        name = name + "_subject",  | 
18 |  | -        expression = "python_version >= '3.12.0'",  | 
19 |  | -    )  | 
20 |  | -    analysis_test(  | 
21 |  | -        name = name,  | 
22 |  | -        impl = impl,  | 
23 |  | -        target = name + "_subject",  | 
24 |  | -        config_settings = {  | 
25 |  | -            PYTHON_VERSION: "3.12.0",  | 
 | 21 | +    cases = {  | 
 | 22 | +        "python_version_gte": {  | 
 | 23 | +            "expression": "python_version >= '3.12.0'",  | 
 | 24 | +            "config_settings": {  | 
 | 25 | +                PYTHON_VERSION: "3.12.0",  | 
 | 26 | +            },  | 
26 | 27 |         },  | 
 | 28 | +    }  | 
 | 29 | + | 
 | 30 | +    tests = []  | 
 | 31 | +    for case_name, case in cases.items():  | 
 | 32 | +        test_name = name + "_" + case_name  | 
 | 33 | +        tests.append(test_name)  | 
 | 34 | +        depspec_flag(  | 
 | 35 | +            name = test_name + "_subject",  | 
 | 36 | +            expression = case["expression"],  | 
 | 37 | +        )  | 
 | 38 | +        analysis_test(  | 
 | 39 | +            name = test_name,  | 
 | 40 | +            impl = impl,  | 
 | 41 | +            target = test_name + "_subject",  | 
 | 42 | +            config_settings = case["config_settings"],  | 
 | 43 | +        )  | 
 | 44 | +    native.test_suite(  | 
 | 45 | +        name = name,  | 
 | 46 | +        tests = tests,  | 
27 | 47 |     )  | 
28 | 48 | 
 
  | 
29 |  | -_tests.append(_test_whatever)  | 
 | 49 | +_tests.append(_test_expr)  | 
30 | 50 | 
 
  | 
31 | 51 | def depspec_flag_test_suite(name):  | 
32 | 52 |     test_suite(  | 
 | 
0 commit comments