Skip to content

Commit 77decbc

Browse files
committed
parameterize test
1 parent d1b9c0d commit 77decbc

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

tests/pypi/pep508/depspec_flag_tests.bzl

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
11
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
22
load("@rules_testing//lib:test_suite.bzl", "test_suite")
3+
load("@rules_testing//lib:util.bzl", "TestingAspectInfo")
34
load("//python/private/pypi:dependency_specifier_flag.bzl", "depspec_flag")
45
load("//python/private/pypi:pep508_env.bzl", pep508_env = "env") # buildifier: disable=bzl-visibility
56
load("//python/private/pypi:pep508_evaluate.bzl", "evaluate", "tokenize") # buildifier: disable=bzl-visibility
67
load("//tests/support:support.bzl", "PYTHON_VERSION")
78

89
_tests = []
910

10-
def _test_whatever(name):
11+
def _test_expr(name):
1112
def impl(env, target):
13+
attrs = target[TestingAspectInfo].attrs
14+
1215
# todo: create FeatureFlagInfo subject
1316
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")
1520

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+
},
2627
},
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,
2747
)
2848

29-
_tests.append(_test_whatever)
49+
_tests.append(_test_expr)
3050

3151
def depspec_flag_test_suite(name):
3252
test_suite(

0 commit comments

Comments
 (0)