Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 3 additions & 23 deletions misc/codegen/generators/qlgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,13 @@ def _get_all_properties_to_be_tested(
type=p.type if not p.is_predicate else None,
is_indexed=p.is_indexed,
)
if p.is_repeated and not p.is_optional:
yield ql.PropertyForTest(f"getNumberOf{p.plural}", type="int")
elif p.is_optional and not p.is_repeated:
yield ql.PropertyForTest(f"has{p.singular}")


def _partition_iter(x, pred):
x1, x2 = itertools.tee(x)
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]
):
Expand Down Expand Up @@ -625,29 +616,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 = []
Expand Down
7 changes: 0 additions & 7 deletions misc/codegen/lib/ql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 23 additions & 9 deletions misc/codegen/templates/ql_test_class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
10 changes: 0 additions & 10 deletions misc/codegen/templates/ql_test_property.mustache

This file was deleted.

45 changes: 11 additions & 34 deletions misc/codegen/test/test_qlgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -1041,31 +1037,16 @@ def test_test_partial_properties(opts, generate_tests):
"B/B.ql": a_ql_class_tester(
class_name="B",
properties=[
ql.PropertyForTest(getter="hasX"),
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
ql.PropertyForTest(getter="getNumberOfWs", type="int"),
ql.PropertyForTest(getter="getX", is_total=False, type="string"),
ql.PropertyForTest(
getter="getY", is_total=False, is_indexed=True, type="bool"
),
ql.PropertyForTest(
getter="getZ", is_total=False, is_indexed=True, type="int"
),
ql.PropertyForTest(getter="getAW", is_total=False, type="string"),
],
),
"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"),
),
}


Expand All @@ -1090,15 +1071,11 @@ def test_test_properties_deduplicated(opts, generate_tests):
class_name="Final",
properties=[
ql.PropertyForTest(getter="getX", type="string"),
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
ql.PropertyForTest(
getter="getY", is_total=False, is_indexed=True, type="bool"
),
],
),
"Final/Final_getY.ql": a_ql_property_tester(
class_name="Final",
property=ql.PropertyForTest(
getter="getY", is_total=False, is_indexed=True, type="bool"
),
),
}


Expand Down
Loading
Loading