From 0100c7171dd20e0427724acbffb618cfc9598300 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 27 Apr 2022 10:12:28 +0200 Subject: [PATCH] Swift: testing non-trivial dataclass properties --- .gitignore | 3 + swift/codegen/.coverage | Bin 53248 -> 0 bytes swift/codegen/dbschemegen.py | 32 +++--- swift/codegen/lib/dbscheme.py | 34 +++--- swift/codegen/lib/ql.py | 18 +-- swift/codegen/qlgen.py | 18 +-- swift/codegen/test/test_dbscheme.py | 52 +++++++++ swift/codegen/test/test_dbschemegen.py | 153 +++++++++++-------------- swift/codegen/test/test_ql.py | 97 ++++++++++++++++ swift/codegen/test/test_qlgen.py | 93 +++++++-------- 10 files changed, 316 insertions(+), 184 deletions(-) delete mode 100644 swift/codegen/.coverage create mode 100644 swift/codegen/test/test_dbscheme.py create mode 100644 swift/codegen/test/test_ql.py diff --git a/.gitignore b/.gitignore index 33ef1770c95..5642399a5f6 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ # python virtual environment folder .venv/ +# binary files created by pytest-cov +.coverage + # It's useful (though not required) to be able to unpack codeql in the ql checkout itself /codeql/ diff --git a/swift/codegen/.coverage b/swift/codegen/.coverage deleted file mode 100644 index 1f3d1b3104cf46997f405ce745441d169f80f048..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53248 zcmeI5UyK_^9mi+A>pyF+Jqbr}(dmo+k2>}6t#^?Bt)IHy_a)i zdwsj>yIiB>;ua}9(FX()H0tpJ6(I3MkrMSEga;@n5h*GNS`~pxkeZ4>5KtxJ_|2}@ zJ}0@#Zj}Z_-<5B6cV>Pwzu#wmGvnD^?>+kPLlxK5CoQ{XxcVlxf=Lp)SJxS1D*Ywt zFW91VpadthmzEqacc`-5o+C;A7}Fx(VEpmqKAzRSlguZ6ug$1mOFSQaLakB)HV^;- z5C8!X@CdXX)}ravtEH!oxJI#Ry0%d=Z9h!j|H#Ddy%YN0-S<5-q5EAj&3PhY&XX5Mg-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List([v for _, v in sorted(imports.items())]) + all_imports = ql.ImportList([v for _, v in sorted(imports.items())]) renderer.render(all_imports, include_file) renderer.cleanup(existing) diff --git a/swift/codegen/test/test_dbscheme.py b/swift/codegen/test/test_dbscheme.py new file mode 100644 index 00000000000..ca1002aa58e --- /dev/null +++ b/swift/codegen/test/test_dbscheme.py @@ -0,0 +1,52 @@ +import sys +from copy import deepcopy + +from swift.codegen.lib import dbscheme +from swift.codegen.test.utils import * + + +def test_dbcolumn_name(): + assert dbscheme.Column("foo", "some_type").name == "foo" + + +@pytest.mark.parametrize("keyword", dbscheme.dbscheme_keywords) +def test_dbcolumn_keyword_name(keyword): + assert dbscheme.Column(keyword, "some_type").name == keyword + "_" + + +@pytest.mark.parametrize("type,binding,lhstype,rhstype", [ + ("builtin_type", False, "builtin_type", "builtin_type ref"), + ("builtin_type", True, "builtin_type", "builtin_type ref"), + ("@at_type", False, "int", "@at_type ref"), + ("@at_type", True, "unique int", "@at_type"), +]) +def test_dbcolumn_types(type, binding, lhstype, rhstype): + col = dbscheme.Column("foo", type, binding) + assert col.lhstype == lhstype + assert col.rhstype == rhstype + + +def test_keyset_has_first_id_marked(): + ids = ["a", "b", "c"] + ks = dbscheme.KeySet(ids) + assert ks.ids[0].first + assert [id.id for id in ks.ids] == ids + + +def test_table_has_first_column_marked(): + columns = [dbscheme.Column("a", "x"), dbscheme.Column("b", "y", binding=True), dbscheme.Column("c", "z")] + expected = deepcopy(columns) + table = dbscheme.Table("foo", columns) + expected[0].first = True + assert table.columns == expected + + +def test_union_has_first_case_marked(): + rhs = ["a", "b", "c"] + u = dbscheme.Union(lhs="x", rhs=rhs) + assert u.rhs[0].first + assert [c.type for c in u.rhs] == rhs + + +if __name__ == '__main__': + sys.exit(pytest.main()) diff --git a/swift/codegen/test/test_dbschemegen.py b/swift/codegen/test/test_dbschemegen.py index 3fb6f798ae4..d8f0089d863 100644 --- a/swift/codegen/test/test_dbschemegen.py +++ b/swift/codegen/test/test_dbschemegen.py @@ -1,10 +1,10 @@ -import pathlib import sys from swift.codegen import dbschemegen -from swift.codegen.lib import dbscheme, paths +from swift.codegen.lib import dbscheme from swift.codegen.test.utils import * + def generate(opts, renderer): (out, data), = run_generation(dbschemegen.generate, opts, renderer).items() assert out is opts.dbscheme @@ -12,7 +12,7 @@ def generate(opts, renderer): def test_empty(opts, input, renderer): - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[], @@ -25,10 +25,10 @@ def test_includes(opts, input, renderer): for i in includes: write(opts.schema.parent / i, i + " data") - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[ - dbscheme.DbSchemeInclude( + dbscheme.SchemeInclude( src=schema_dir / i, data=i + " data", ) for i in includes @@ -41,14 +41,14 @@ def test_empty_final_class(opts, input, renderer): input.classes = [ schema.Class("Object"), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbTable( + dbscheme.Table( name="objects", columns=[ - dbscheme.DbColumn('id', '@object', binding=True), + dbscheme.Column('id', '@object', binding=True), ] ) ], @@ -62,15 +62,15 @@ def test_final_class_with_single_scalar_field(opts, input, renderer): schema.SingleProperty("foo", "bar"), ]), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbTable( + dbscheme.Table( name="objects", columns=[ - dbscheme.DbColumn('id', '@object', binding=True), - dbscheme.DbColumn('foo', 'bar'), + dbscheme.Column('id', '@object', binding=True), + dbscheme.Column('foo', 'bar'), ] ) ], @@ -83,15 +83,15 @@ def test_final_class_with_single_class_field(opts, input, renderer): schema.SingleProperty("foo", "Bar"), ]), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbTable( + dbscheme.Table( name="objects", columns=[ - dbscheme.DbColumn('id', '@object', binding=True), - dbscheme.DbColumn('foo', '@bar'), + dbscheme.Column('id', '@object', binding=True), + dbscheme.Column('foo', '@bar'), ] ) ], @@ -104,22 +104,22 @@ def test_final_class_with_optional_field(opts, input, renderer): schema.OptionalProperty("foo", "bar"), ]), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbTable( + dbscheme.Table( name="objects", columns=[ - dbscheme.DbColumn('id', '@object', binding=True), + dbscheme.Column('id', '@object', binding=True), ] ), - dbscheme.DbTable( + dbscheme.Table( name="object_foos", - keyset=dbscheme.DbKeySet(["id"]), + keyset=dbscheme.KeySet(["id"]), columns=[ - dbscheme.DbColumn('id', '@object'), - dbscheme.DbColumn('foo', 'bar'), + dbscheme.Column('id', '@object'), + dbscheme.Column('foo', 'bar'), ] ), ], @@ -132,23 +132,23 @@ def test_final_class_with_repeated_field(opts, input, renderer): schema.RepeatedProperty("foo", "bar"), ]), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbTable( + dbscheme.Table( name="objects", columns=[ - dbscheme.DbColumn('id', '@object', binding=True), + dbscheme.Column('id', '@object', binding=True), ] ), - dbscheme.DbTable( + dbscheme.Table( name="object_foos", - keyset=dbscheme.DbKeySet(["id", "index"]), + keyset=dbscheme.KeySet(["id", "index"]), columns=[ - dbscheme.DbColumn('id', '@object'), - dbscheme.DbColumn('index', 'int'), - dbscheme.DbColumn('foo', 'bar'), + dbscheme.Column('id', '@object'), + dbscheme.Column('index', 'int'), + dbscheme.Column('foo', 'bar'), ] ), ], @@ -164,33 +164,33 @@ def test_final_class_with_more_fields(opts, input, renderer): schema.RepeatedProperty("four", "w"), ]), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbTable( + dbscheme.Table( name="objects", columns=[ - dbscheme.DbColumn('id', '@object', binding=True), - dbscheme.DbColumn('one', 'x'), - dbscheme.DbColumn('two', 'y'), + dbscheme.Column('id', '@object', binding=True), + dbscheme.Column('one', 'x'), + dbscheme.Column('two', 'y'), ] ), - dbscheme.DbTable( + dbscheme.Table( name="object_threes", - keyset=dbscheme.DbKeySet(["id"]), + keyset=dbscheme.KeySet(["id"]), columns=[ - dbscheme.DbColumn('id', '@object'), - dbscheme.DbColumn('three', 'z'), + dbscheme.Column('id', '@object'), + dbscheme.Column('three', 'z'), ] ), - dbscheme.DbTable( + dbscheme.Table( name="object_fours", - keyset=dbscheme.DbKeySet(["id", "index"]), + keyset=dbscheme.KeySet(["id", "index"]), columns=[ - dbscheme.DbColumn('id', '@object'), - dbscheme.DbColumn('index', 'int'), - dbscheme.DbColumn('four', 'w'), + dbscheme.Column('id', '@object'), + dbscheme.Column('index', 'int'), + dbscheme.Column('four', 'w'), ] ), ], @@ -203,11 +203,11 @@ def test_empty_class_with_derived(opts, input, renderer): name="Base", derived={"Left", "Right"}), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbUnion( + dbscheme.Union( lhs="@base", rhs=["@left", "@right"], ), @@ -224,20 +224,20 @@ def test_class_with_derived_and_single_property(opts, input, renderer): schema.SingleProperty("single", "Prop"), ]), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbUnion( + dbscheme.Union( lhs="@base", rhs=["@left", "@right"], ), - dbscheme.DbTable( + dbscheme.Table( name="bases", - keyset=dbscheme.DbKeySet(["id"]), + keyset=dbscheme.KeySet(["id"]), columns=[ - dbscheme.DbColumn('id', '@base'), - dbscheme.DbColumn('single', '@prop'), + dbscheme.Column('id', '@base'), + dbscheme.Column('single', '@prop'), ] ) ], @@ -253,20 +253,20 @@ def test_class_with_derived_and_optional_property(opts, input, renderer): schema.OptionalProperty("opt", "Prop"), ]), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbUnion( + dbscheme.Union( lhs="@base", rhs=["@left", "@right"], ), - dbscheme.DbTable( + dbscheme.Table( name="base_opts", - keyset=dbscheme.DbKeySet(["id"]), + keyset=dbscheme.KeySet(["id"]), columns=[ - dbscheme.DbColumn('id', '@base'), - dbscheme.DbColumn('opt', '@prop'), + dbscheme.Column('id', '@base'), + dbscheme.Column('opt', '@prop'), ] ) ], @@ -282,47 +282,26 @@ def test_class_with_derived_and_repeated_property(opts, input, renderer): schema.RepeatedProperty("rep", "Prop"), ]), ] - assert generate(opts, renderer) == dbscheme.DbScheme( + assert generate(opts, renderer) == dbscheme.Scheme( src=schema_file, includes=[], declarations=[ - dbscheme.DbUnion( + dbscheme.Union( lhs="@base", rhs=["@left", "@right"], ), - dbscheme.DbTable( + dbscheme.Table( name="base_reps", - keyset=dbscheme.DbKeySet(["id", "index"]), + keyset=dbscheme.KeySet(["id", "index"]), columns=[ - dbscheme.DbColumn('id', '@base'), - dbscheme.DbColumn('index', 'int'), - dbscheme.DbColumn('rep', '@prop'), + dbscheme.Column('id', '@base'), + dbscheme.Column('index', 'int'), + dbscheme.Column('rep', '@prop'), ] ) ], ) -def test_dbcolumn_name(): - assert dbscheme.DbColumn("foo", "some_type").name == "foo" - - -@pytest.mark.parametrize("keyword", dbscheme.dbscheme_keywords) -def test_dbcolumn_keyword_name(keyword): - assert dbscheme.DbColumn(keyword, "some_type").name == keyword + "_" - - -@pytest.mark.parametrize("type,binding,lhstype,rhstype", [ - ("builtin_type", False, "builtin_type", "builtin_type ref"), - ("builtin_type", True, "builtin_type", "builtin_type ref"), - ("@at_type", False, "int", "@at_type ref"), - ("@at_type", True, "unique int", "@at_type"), -]) -def test_dbcolumn_types(type, binding, lhstype, rhstype): - col = dbscheme.DbColumn("foo", type, binding) - assert col.lhstype == lhstype - assert col.rhstype == rhstype - - if __name__ == '__main__': sys.exit(pytest.main()) diff --git a/swift/codegen/test/test_ql.py b/swift/codegen/test/test_ql.py new file mode 100644 index 00000000000..47b9ff88716 --- /dev/null +++ b/swift/codegen/test/test_ql.py @@ -0,0 +1,97 @@ +import sys +from copy import deepcopy + +from swift.codegen.lib import ql +from swift.codegen.test.utils import * + + +def test_property_has_first_param_marked(): + params = [ql.Param("a", "x"), ql.Param("b", "y"), ql.Param("c", "z")] + expected = deepcopy(params) + expected[0].first = True + prop = ql.Property("Prop", "foo", "props", ["this"], params=params) + assert prop.params == expected + + +def test_property_has_first_table_param_marked(): + tableparams = ["a", "b", "c"] + prop = ql.Property("Prop", "foo", "props", tableparams) + assert prop.tableparams[0].first + assert [p.param for p in prop.tableparams] == tableparams + assert all(p.type is None for p in prop.tableparams) + + +@pytest.mark.parametrize("params,expected_local_var", [ + (["a", "b", "c"], "x"), + (["a", "x", "c"], "x_"), + (["a", "x", "x_", "c"], "x__"), + (["a", "x", "x_", "x__"], "x___"), +]) +def test_property_local_var_avoids_params_collision(params, expected_local_var): + prop = ql.Property("Prop", "foo", "props", ["this"], params=[ql.Param(p) for p in params]) + assert prop.local_var == expected_local_var + + +def test_property_not_a_class(): + tableparams = ["x", "result", "y"] + prop = ql.Property("Prop", "foo", "props", tableparams) + assert not prop.type_is_class + assert [p.param for p in prop.tableparams] == tableparams + + +def test_property_is_a_class(): + tableparams = ["x", "result", "y"] + prop = ql.Property("Prop", "Foo", "props", tableparams) + assert prop.type_is_class + assert [p.param for p in prop.tableparams] == ["x", prop.local_var, "y"] + + +@pytest.mark.parametrize("name,expected_article", [ + ("Argument", "An"), + ("Element", "An"), + ("Integer", "An"), + ("Operator", "An"), + ("Unit", "A"), + ("Whatever", "A"), +]) +def test_property_indefinite_article(name, expected_article): + prop = ql.Property(name, "Foo", "props", ["x"], plural="X") + assert prop.indefinite_article == expected_article + + +def test_property_no_plural_no_indefinite_article(): + prop = ql.Property("Prop", "Foo", "props", ["x"]) + assert prop.indefinite_article is None + + +def test_class_sorts_bases(): + bases = ["B", "Ab", "C", "Aa"] + expected = ["Aa", "Ab", "B", "C"] + cls = ql.Class("Foo", bases=bases) + assert cls.bases == expected + + +def test_class_has_first_property_marked(): + props = [ + ql.Property(f"Prop{x}", f"Foo{x}", f"props{x}", [f"{x}"]) for x in range(4) + ] + expected = deepcopy(props) + expected[0].first = True + cls = ql.Class("Class", properties=props) + assert cls.properties == expected + + +def test_class_db_id(): + cls = ql.Class("ThisIsMyClass") + assert cls.db_id == "@this_is_my_class" + +def test_root_class(): + cls = ql.Class("Class") + assert cls.root + +def test_non_root_class(): + cls = ql.Class("Class", bases=["A"]) + assert not cls.root + +if __name__ == '__main__': + sys.exit(pytest.main()) diff --git a/swift/codegen/test/test_qlgen.py b/swift/codegen/test/test_qlgen.py index 3ff3f5416ef..94cd6641afc 100644 --- a/swift/codegen/test/test_qlgen.py +++ b/swift/codegen/test/test_qlgen.py @@ -12,12 +12,13 @@ def run_mock(): yield ret +# these are lambdas so that they will use patched paths when called stub_path = lambda: paths.swift_dir / "ql/lib/stub/path" ql_output_path = lambda: paths.swift_dir / "ql/lib/other/path" import_file = lambda: stub_path().with_suffix(".qll") stub_import_prefix = "stub.path." gen_import_prefix = "other.path." -index_param = ql.QlParam("index", "int") +index_param = ql.Param("index", "int") def generate(opts, renderer, written=None): @@ -29,7 +30,7 @@ def generate(opts, renderer, written=None): def test_empty(opts, input, renderer): assert generate(opts, renderer) == { - import_file(): ql.QlImportList() + import_file(): ql.ImportList() } @@ -38,9 +39,9 @@ def test_one_empty_class(opts, input, renderer): schema.Class("A") ] assert generate(opts, renderer) == { - import_file(): ql.QlImportList([stub_import_prefix + "A"]), - stub_path() / "A.qll": ql.QlStub(name="A", base_import=gen_import_prefix + "A"), - ql_output_path() / "A.qll": ql.QlClass(name="A", final=True), + import_file(): ql.ImportList([stub_import_prefix + "A"]), + stub_path() / "A.qll": ql.Stub(name="A", base_import=gen_import_prefix + "A"), + ql_output_path() / "A.qll": ql.Class(name="A", final=True), } @@ -52,16 +53,16 @@ def test_hierarchy(opts, input, renderer): schema.Class("A", derived={"B", "C"}), ] assert generate(opts, renderer) == { - import_file(): ql.QlImportList([stub_import_prefix + cls for cls in "ABCD"]), - stub_path() / "A.qll": ql.QlStub(name="A", base_import=gen_import_prefix + "A"), - stub_path() / "B.qll": ql.QlStub(name="B", base_import=gen_import_prefix + "B"), - stub_path() / "C.qll": ql.QlStub(name="C", base_import=gen_import_prefix + "C"), - stub_path() / "D.qll": ql.QlStub(name="D", base_import=gen_import_prefix + "D"), - ql_output_path() / "A.qll": ql.QlClass(name="A"), - ql_output_path() / "B.qll": ql.QlClass(name="B", bases=["A"], imports=[stub_import_prefix + "A"]), - ql_output_path() / "C.qll": ql.QlClass(name="C", bases=["A"], imports=[stub_import_prefix + "A"]), - ql_output_path() / "D.qll": ql.QlClass(name="D", final=True, bases=["B", "C"], - imports=[stub_import_prefix + cls for cls in "BC"]), + import_file(): ql.ImportList([stub_import_prefix + cls for cls in "ABCD"]), + stub_path() / "A.qll": ql.Stub(name="A", base_import=gen_import_prefix + "A"), + stub_path() / "B.qll": ql.Stub(name="B", base_import=gen_import_prefix + "B"), + stub_path() / "C.qll": ql.Stub(name="C", base_import=gen_import_prefix + "C"), + stub_path() / "D.qll": ql.Stub(name="D", base_import=gen_import_prefix + "D"), + ql_output_path() / "A.qll": ql.Class(name="A"), + ql_output_path() / "B.qll": ql.Class(name="B", bases=["A"], imports=[stub_import_prefix + "A"]), + ql_output_path() / "C.qll": ql.Class(name="C", bases=["A"], imports=[stub_import_prefix + "A"]), + ql_output_path() / "D.qll": ql.Class(name="D", final=True, bases=["B", "C"], + imports=[stub_import_prefix + cls for cls in "BC"]), } @@ -71,10 +72,10 @@ def test_single_property(opts, input, renderer): schema.Class("MyObject", properties=[schema.SingleProperty("foo", "bar")]), ] assert generate(opts, renderer) == { - import_file(): ql.QlImportList([stub_import_prefix + "MyObject"]), - stub_path() / "MyObject.qll": ql.QlStub(name="MyObject", base_import=gen_import_prefix + "MyObject"), - ql_output_path() / "MyObject.qll": ql.QlClass(name="MyObject", final=True, properties=[ - ql.QlProperty(singular="Foo", type="bar", tablename="my_objects", tableparams=["this", "result"]), + import_file(): ql.ImportList([stub_import_prefix + "MyObject"]), + stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"), + ql_output_path() / "MyObject.qll": ql.Class(name="MyObject", final=True, properties=[ + ql.Property(singular="Foo", type="bar", tablename="my_objects", tableparams=["this", "result"]), ]) } @@ -88,12 +89,12 @@ def test_single_properties(opts, input, renderer): ]), ] assert generate(opts, renderer) == { - import_file(): ql.QlImportList([stub_import_prefix + "MyObject"]), - stub_path() / "MyObject.qll": ql.QlStub(name="MyObject", base_import=gen_import_prefix + "MyObject"), - ql_output_path() / "MyObject.qll": ql.QlClass(name="MyObject", final=True, properties=[ - ql.QlProperty(singular="One", type="x", tablename="my_objects", tableparams=["this", "result", "_", "_"]), - ql.QlProperty(singular="Two", type="y", tablename="my_objects", tableparams=["this", "_", "result", "_"]), - ql.QlProperty(singular="Three", type="z", tablename="my_objects", tableparams=["this", "_", "_", "result"]), + import_file(): ql.ImportList([stub_import_prefix + "MyObject"]), + stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"), + ql_output_path() / "MyObject.qll": ql.Class(name="MyObject", final=True, properties=[ + ql.Property(singular="One", type="x", tablename="my_objects", tableparams=["this", "result", "_", "_"]), + ql.Property(singular="Two", type="y", tablename="my_objects", tableparams=["this", "_", "result", "_"]), + ql.Property(singular="Three", type="z", tablename="my_objects", tableparams=["this", "_", "_", "result"]), ]) } @@ -103,10 +104,10 @@ def test_optional_property(opts, input, renderer): schema.Class("MyObject", properties=[schema.OptionalProperty("foo", "bar")]), ] assert generate(opts, renderer) == { - import_file(): ql.QlImportList([stub_import_prefix + "MyObject"]), - stub_path() / "MyObject.qll": ql.QlStub(name="MyObject", base_import=gen_import_prefix + "MyObject"), - ql_output_path() / "MyObject.qll": ql.QlClass(name="MyObject", final=True, properties=[ - ql.QlProperty(singular="Foo", type="bar", tablename="my_object_foos", tableparams=["this", "result"]), + import_file(): ql.ImportList([stub_import_prefix + "MyObject"]), + stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"), + ql_output_path() / "MyObject.qll": ql.Class(name="MyObject", final=True, properties=[ + ql.Property(singular="Foo", type="bar", tablename="my_object_foos", tableparams=["this", "result"]), ]) } @@ -116,11 +117,11 @@ def test_repeated_property(opts, input, renderer): schema.Class("MyObject", properties=[schema.RepeatedProperty("foo", "bar")]), ] assert generate(opts, renderer) == { - import_file(): ql.QlImportList([stub_import_prefix + "MyObject"]), - stub_path() / "MyObject.qll": ql.QlStub(name="MyObject", base_import=gen_import_prefix + "MyObject"), - ql_output_path() / "MyObject.qll": ql.QlClass(name="MyObject", final=True, properties=[ - ql.QlProperty(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos", params=[index_param], - tableparams=["this", "index", "result"]), + import_file(): ql.ImportList([stub_import_prefix + "MyObject"]), + stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"), + ql_output_path() / "MyObject.qll": ql.Class(name="MyObject", final=True, properties=[ + ql.Property(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos", params=[index_param], + tableparams=["this", "index", "result"]), ]) } @@ -131,15 +132,15 @@ def test_single_class_property(opts, input, renderer): schema.Class("Bar"), ] assert generate(opts, renderer) == { - import_file(): ql.QlImportList([stub_import_prefix + cls for cls in ("Bar", "MyObject")]), - stub_path() / "MyObject.qll": ql.QlStub(name="MyObject", base_import=gen_import_prefix + "MyObject"), - stub_path() / "Bar.qll": ql.QlStub(name="Bar", base_import=gen_import_prefix + "Bar"), - ql_output_path() / "MyObject.qll": ql.QlClass( + import_file(): ql.ImportList([stub_import_prefix + cls for cls in ("Bar", "MyObject")]), + stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"), + stub_path() / "Bar.qll": ql.Stub(name="Bar", base_import=gen_import_prefix + "Bar"), + ql_output_path() / "MyObject.qll": ql.Class( name="MyObject", final=True, imports=[stub_import_prefix + "Bar"], properties=[ - ql.QlProperty(singular="Foo", type="Bar", tablename="my_objects", tableparams=["this", "result"]), + ql.Property(singular="Foo", type="Bar", tablename="my_objects", tableparams=["this", "result"]), ], ), - ql_output_path() / "Bar.qll": ql.QlClass(name="Bar", final=True) + ql_output_path() / "Bar.qll": ql.Class(name="Bar", final=True) } @@ -150,15 +151,15 @@ def test_class_dir(opts, input, renderer): schema.Class("B", bases={"A"}), ] assert generate(opts, renderer) == { - import_file(): ql.QlImportList([ + import_file(): ql.ImportList([ stub_import_prefix + "another.rel.path.A", stub_import_prefix + "B", ]), - stub_path() / dir / "A.qll": ql.QlStub(name="A", base_import=gen_import_prefix + "another.rel.path.A"), - stub_path() / "B.qll": ql.QlStub(name="B", base_import=gen_import_prefix + "B"), - ql_output_path() / dir / "A.qll": ql.QlClass(name="A", dir=dir), - ql_output_path() / "B.qll": ql.QlClass(name="B", final=True, bases=["A"], - imports=[stub_import_prefix + "another.rel.path.A"]) + stub_path() / dir / "A.qll": ql.Stub(name="A", base_import=gen_import_prefix + "another.rel.path.A"), + stub_path() / "B.qll": ql.Stub(name="B", base_import=gen_import_prefix + "B"), + ql_output_path() / dir / "A.qll": ql.Class(name="A", dir=dir), + ql_output_path() / "B.qll": ql.Class(name="B", final=True, bases=["A"], + imports=[stub_import_prefix + "another.rel.path.A"]) }