Codegen: use one generated test file per directory

This collapses all generated test QL sources into a single one per
directory, using query predicates to run the different tests.

This should improve the time required to run generated tests.
This commit is contained in:
Paolo Tranquilli
2025-06-25 11:44:54 +02:00
parent 3d9e2f5438
commit 6bbf1e3bc1
1753 changed files with 7752 additions and 7850 deletions

View File

@@ -372,11 +372,6 @@ def _partition_iter(x, pred):
return filter(pred, x1), itertools.filterfalse(pred, x2)
def _partition(l, pred):
"""partitions a list according to boolean predicate"""
return map(list, _partition_iter(l, pred))
def _is_in_qltest_collapsed_hierarchy(
cls: schema.Class, lookup: typing.Dict[str, schema.Class]
):
@@ -625,29 +620,18 @@ def generate(opts, renderer):
test_dir / missing_test_source_filename,
)
continue
total_props, partial_props = _partition(
_get_all_properties_to_be_tested(c, data.classes),
lambda p: p.is_total,
)
renderer.render(
ql.ClassTester(
class_name=c.name,
properties=total_props,
properties=list(
_get_all_properties_to_be_tested(c, data.classes)
),
elements_module=elements_module,
# in case of collapsed hierarchies we want to see the actual QL class in results
show_ql_class="qltest_collapse_hierarchy" in c.pragmas,
),
test_dir / f"{c.name}.ql",
)
for p in partial_props:
renderer.render(
ql.PropertyTester(
class_name=c.name,
elements_module=elements_module,
property=p,
),
test_dir / f"{c.name}_{p.getter}.ql",
)
final_synth_types = []
non_final_synth_types = []

View File

@@ -245,13 +245,6 @@ class ClassTester(TesterBase):
show_ql_class: bool = False
@dataclass
class PropertyTester(TesterBase):
template: ClassVar = "ql_test_property"
property: PropertyForTest
@dataclass
class MissingTestInstructions:
template: ClassVar = "ql_test_missing"

View File

@@ -3,14 +3,28 @@
import {{elements_module}}
import TestUtils
from {{class_name}} x{{#properties}}, {{#type}}{{.}}{{/type}}{{^type}}string{{/type}} {{getter}}{{/properties}}
where toBeTested(x) and not x.isUnknown()
query predicate instances({{class_name}} x{{#show_ql_class}}, string primaryQlClasses{{/show_ql_class}}{{#properties}}{{#is_total}}, string {{getter}}__label, {{#type}}{{.}}{{/type}}{{^type}}string{{/type}} {{getter}}{{/is_total}}{{/properties}}) {
toBeTested(x) and not x.isUnknown()
{{#show_ql_class}}
and primaryQlClasses = x.getPrimaryQlClasses()
{{/show_ql_class}}
{{#properties}}
{{#is_total}}
and {{getter}}__label = "{{getter}}:"
{{#type}}
and {{getter}} = x.{{getter}}()
{{/type}}
{{^type}}
and if x.{{getter}}() then {{getter}} = "yes" else {{getter}} = "no"
{{/type}}
{{/is_total}}
{{/properties}}
}
{{#properties}}
{{#type}}
and {{getter}} = x.{{getter}}()
{{/type}}
{{^type}}
and if x.{{getter}}() then {{getter}} = "yes" else {{getter}} = "no"
{{/type}}
{{^is_total}}
query predicate {{getter}}({{class_name}} x{{#is_indexed}}, int index{{/is_indexed}}, {{type}} {{getter}}) {
toBeTested(x) and not x.isUnknown() and {{getter}} = x.{{getter}}({{#is_indexed}}index{{/is_indexed}})
}
{{/is_total}}
{{/properties}}
select x{{#show_ql_class}}, x.getPrimaryQlClasses(){{/show_ql_class}}{{#properties}}, "{{getter}}:", {{getter}}{{/properties}}

View File

@@ -1,10 +0,0 @@
// generated by {{generator}}, do not edit
import {{elements_module}}
import TestUtils
{{#property}}
from {{class_name}} x{{#is_indexed}}, int index{{/is_indexed}}
where toBeTested(x) and not x.isUnknown()
select x, {{#is_indexed}}index, {{/is_indexed}}x.{{getter}}({{#is_indexed}}index{{/is_indexed}})
{{/property}}

View File

@@ -960,10 +960,6 @@ def a_ql_class_tester(**kwargs):
return ql.ClassTester(**kwargs, elements_module=stub_import)
def a_ql_property_tester(**kwargs):
return ql.PropertyTester(**kwargs, elements_module=stub_import)
def test_test_source_present(opts, generate_tests):
write(opts.ql_test_output / "A" / "test.swift")
assert generate_tests(
@@ -1041,31 +1037,19 @@ def test_test_partial_properties(opts, generate_tests):
"B/B.ql": a_ql_class_tester(
class_name="B",
properties=[
ql.PropertyForTest(getter="getX", is_total=False, type="string"),
ql.PropertyForTest(getter="hasX"),
ql.PropertyForTest(
getter="getY", is_total=False, is_indexed=True, type="bool"
),
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
ql.PropertyForTest(
getter="getZ", is_total=False, is_indexed=True, type="int"
),
ql.PropertyForTest(getter="getAW", is_total=False, type="string"),
ql.PropertyForTest(getter="getNumberOfWs", type="int"),
],
),
"B/B_getX.ql": a_ql_property_tester(
class_name="B",
property=ql.PropertyForTest(getter="getX", is_total=False, type="string"),
),
"B/B_getY.ql": a_ql_property_tester(
class_name="B",
property=ql.PropertyForTest(
getter="getY", is_total=False, is_indexed=True, type="bool"
),
),
"B/B_getZ.ql": a_ql_property_tester(
class_name="B",
property=ql.PropertyForTest(
getter="getZ", is_total=False, is_indexed=True, type="int"
),
),
"B/B_getAW.ql": a_ql_property_tester(
class_name="B",
property=ql.PropertyForTest(getter="getAW", is_total=False, type="string"),
),
}
@@ -1090,15 +1074,12 @@ def test_test_properties_deduplicated(opts, generate_tests):
class_name="Final",
properties=[
ql.PropertyForTest(getter="getX", type="string"),
ql.PropertyForTest(
getter="getY", is_total=False, is_indexed=True, type="bool"
),
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
],
),
"Final/Final_getY.ql": a_ql_property_tester(
class_name="Final",
property=ql.PropertyForTest(
getter="getY", is_total=False, is_indexed=True, type="bool"
),
),
}