@@ -190,7 +190,7 @@ def test_single_property(generate_classes):
190
190
ql .Class (name = "MyObject" , final = True ,
191
191
properties = [
192
192
ql .Property (singular = "Foo" , type = "bar" , tablename = "my_objects" ,
193
- tableparams = ["this" , "result" ], doc = "foo" ),
193
+ tableparams = ["this" , "result" ], doc = "foo of this my object " ),
194
194
])),
195
195
}
196
196
@@ -215,31 +215,31 @@ def test_children(generate_classes):
215
215
ql .Class (name = "MyObject" , final = True ,
216
216
properties = [
217
217
ql .Property (singular = "A" , type = "int" , tablename = "my_objects" ,
218
- tableparams = ["this" , "result" , "_" ], doc = "a" ),
218
+ tableparams = ["this" , "result" , "_" ], doc = "a of this my object " ),
219
219
ql .Property (singular = "Child1" , type = "int" , tablename = "my_objects" ,
220
220
tableparams = ["this" , "_" , "result" ], prev_child = "" ,
221
- doc = "child 1" ),
221
+ doc = "child 1 of this my object " ),
222
222
ql .Property (singular = "B" , plural = "Bs" , type = "int" ,
223
223
tablename = "my_object_bs" ,
224
224
tableparams = ["this" , "index" , "result" ],
225
- doc = "b" , doc_plural = "bs" ),
225
+ doc = "b of this my object " , doc_plural = "bs of this my object " ),
226
226
ql .Property (singular = "Child" , plural = "Children" , type = "int" ,
227
227
tablename = "my_object_children" ,
228
228
tableparams = ["this" , "index" , "result" ], prev_child = "Child1" ,
229
- doc = "child" , doc_plural = "children" ),
229
+ doc = "child of this my object " , doc_plural = "children of this my object " ),
230
230
ql .Property (singular = "C" , type = "int" , tablename = "my_object_cs" ,
231
- tableparams = ["this" , "result" ], is_optional = True , doc = "c" ),
231
+ tableparams = ["this" , "result" ], is_optional = True , doc = "c of this my object " ),
232
232
ql .Property (singular = "Child3" , type = "int" , tablename = "my_object_child_3s" ,
233
233
tableparams = ["this" , "result" ], is_optional = True ,
234
- prev_child = "Child" , doc = "child 3" ),
234
+ prev_child = "Child" , doc = "child 3 of this my object " ),
235
235
ql .Property (singular = "D" , plural = "Ds" , type = "int" ,
236
236
tablename = "my_object_ds" ,
237
237
tableparams = ["this" , "index" , "result" ], is_optional = True ,
238
- doc = "d" , doc_plural = "ds" ),
238
+ doc = "d of this my object " , doc_plural = "ds of this my object " ),
239
239
ql .Property (singular = "Child4" , plural = "Child4s" , type = "int" ,
240
240
tablename = "my_object_child_4s" ,
241
241
tableparams = ["this" , "index" , "result" ], is_optional = True ,
242
- prev_child = "Child3" , doc = "child 4" , doc_plural = "child 4s" ),
242
+ prev_child = "Child3" , doc = "child 4 of this my object " , doc_plural = "child 4s of this my object " ),
243
243
])),
244
244
}
245
245
@@ -256,11 +256,11 @@ def test_single_properties(generate_classes):
256
256
ql .Class (name = "MyObject" , final = True ,
257
257
properties = [
258
258
ql .Property (singular = "One" , type = "x" , tablename = "my_objects" ,
259
- tableparams = ["this" , "result" , "_" , "_" ], doc = "one" ),
259
+ tableparams = ["this" , "result" , "_" , "_" ], doc = "one of this my object " ),
260
260
ql .Property (singular = "Two" , type = "y" , tablename = "my_objects" ,
261
- tableparams = ["this" , "_" , "result" , "_" ], doc = "two" ),
261
+ tableparams = ["this" , "_" , "result" , "_" ], doc = "two of this my object " ),
262
262
ql .Property (singular = "Three" , type = "z" , tablename = "my_objects" ,
263
- tableparams = ["this" , "_" , "_" , "result" ], doc = "three" ),
263
+ tableparams = ["this" , "_" , "_" , "result" ], doc = "three of this my object " ),
264
264
])),
265
265
}
266
266
@@ -278,7 +278,7 @@ def test_optional_property(generate_classes, is_child, prev_child):
278
278
ql .Class (name = "MyObject" , final = True , properties = [
279
279
ql .Property (singular = "Foo" , type = "bar" , tablename = "my_object_foos" ,
280
280
tableparams = ["this" , "result" ],
281
- is_optional = True , prev_child = prev_child , doc = "foo" ),
281
+ is_optional = True , prev_child = prev_child , doc = "foo of this my object " ),
282
282
])),
283
283
}
284
284
@@ -296,7 +296,7 @@ def test_repeated_property(generate_classes, is_child, prev_child):
296
296
ql .Class (name = "MyObject" , final = True , properties = [
297
297
ql .Property (singular = "Foo" , plural = "Foos" , type = "bar" , tablename = "my_object_foos" ,
298
298
tableparams = ["this" , "index" , "result" ], prev_child = prev_child ,
299
- doc = "foo" , doc_plural = "foos" ),
299
+ doc = "foo of this my object " , doc_plural = "foos of this my object " ),
300
300
])),
301
301
}
302
302
@@ -315,7 +315,7 @@ def test_repeated_optional_property(generate_classes, is_child, prev_child):
315
315
ql .Class (name = "MyObject" , final = True , properties = [
316
316
ql .Property (singular = "Foo" , plural = "Foos" , type = "bar" , tablename = "my_object_foos" ,
317
317
tableparams = ["this" , "index" , "result" ], is_optional = True ,
318
- prev_child = prev_child , doc = "foo" , doc_plural = "foos" ),
318
+ prev_child = prev_child , doc = "foo of this my object " , doc_plural = "foos of this my object " ),
319
319
])),
320
320
}
321
321
@@ -346,7 +346,7 @@ def test_single_class_property(generate_classes, is_child, prev_child):
346
346
ql .Property (singular = "Foo" , type = "Bar" , tablename = "my_objects" ,
347
347
tableparams = [
348
348
"this" , "result" ],
349
- prev_child = prev_child , doc = "foo" ),
349
+ prev_child = prev_child , doc = "foo of this my object " ),
350
350
],
351
351
)),
352
352
"Bar.qll" : (ql .Stub (name = "Bar" , base_import = gen_import_prefix + "Bar" ),
@@ -644,7 +644,8 @@ def test_property_description(generate_classes):
644
644
ql .Class (name = "MyObject" , final = True ,
645
645
properties = [
646
646
ql .Property (singular = "Foo" , type = "bar" , tablename = "my_objects" ,
647
- tableparams = ["this" , "result" ], doc = "foo" ,
647
+ tableparams = ["this" , "result" ],
648
+ doc = "foo of this my object" ,
648
649
description = description ),
649
650
])),
650
651
}
@@ -667,20 +668,108 @@ def test_property_doc_override(generate_classes):
667
668
def test_repeated_property_doc_override (generate_classes ):
668
669
assert generate_classes ([
669
670
schema .Class ("MyObject" , properties = [
670
- schema .RepeatedProperty ("x" , "int" , doc = "children" ),
671
- schema .RepeatedOptionalProperty ("y" , "int" , doc = "child" )]),
671
+ schema .RepeatedProperty ("x" , "int" , doc = "children of this " ),
672
+ schema .RepeatedOptionalProperty ("y" , "int" , doc = "child of this " )]),
672
673
]) == {
673
674
"MyObject.qll" : (ql .Stub (name = "MyObject" , base_import = gen_import_prefix + "MyObject" ),
674
675
ql .Class (name = "MyObject" , final = True ,
675
676
properties = [
676
677
ql .Property (singular = "X" , plural = "Xes" , type = "int" ,
677
678
tablename = "my_object_xes" ,
678
679
tableparams = ["this" , "index" , "result" ],
679
- doc = "child" , doc_plural = "children" ),
680
+ doc = "child of this " , doc_plural = "children of this " ),
680
681
ql .Property (singular = "Y" , plural = "Ys" , type = "int" ,
681
682
tablename = "my_object_ies" , is_optional = True ,
682
683
tableparams = ["this" , "index" , "result" ],
683
- doc = "child" , doc_plural = "children" ),
684
+ doc = "child of this" , doc_plural = "children of this" ),
685
+ ])),
686
+ }
687
+
688
+
689
+ @pytest .mark .parametrize ("abbr,expected" , list (qlgen .abbreviations .items ()))
690
+ def test_property_doc_abbreviations (generate_classes , abbr , expected ):
691
+ expected_doc = f"foo { expected } bar of this object"
692
+ assert generate_classes ([
693
+ schema .Class ("Object" , properties = [
694
+ schema .SingleProperty (f"foo_{ abbr } _bar" , "baz" )]),
695
+ ]) == {
696
+ "Object.qll" : (ql .Stub (name = "Object" , base_import = gen_import_prefix + "Object" ),
697
+ ql .Class (name = "Object" , final = True ,
698
+ properties = [
699
+ ql .Property (singular = f"Foo{ abbr .capitalize ()} Bar" , type = "baz" , tablename = "objects" ,
700
+ tableparams = ["this" , "result" ], doc = expected_doc ),
701
+ ])),
702
+ }
703
+
704
+
705
+ @pytest .mark .parametrize ("abbr,expected" , list (qlgen .abbreviations .items ()))
706
+ def test_property_doc_abbreviations_ignored_if_within_word (generate_classes , abbr , expected ):
707
+ expected_doc = f"foo { abbr } acadabra bar of this object"
708
+ assert generate_classes ([
709
+ schema .Class ("Object" , properties = [
710
+ schema .SingleProperty (f"foo_{ abbr } acadabra_bar" , "baz" )]),
711
+ ]) == {
712
+ "Object.qll" : (ql .Stub (name = "Object" , base_import = gen_import_prefix + "Object" ),
713
+ ql .Class (name = "Object" , final = True ,
714
+ properties = [
715
+ ql .Property (singular = f"Foo{ abbr .capitalize ()} acadabraBar" , type = "baz" , tablename = "objects" ,
716
+ tableparams = ["this" , "result" ], doc = expected_doc ),
717
+ ])),
718
+ }
719
+
720
+
721
+ def test_repeated_property_doc_override_with_format (generate_classes ):
722
+ assert generate_classes ([
723
+ schema .Class ("MyObject" , properties = [
724
+ schema .RepeatedProperty ("x" , "int" , doc = "special {children} of this" ),
725
+ schema .RepeatedOptionalProperty ("y" , "int" , doc = "special {child} of this" )]),
726
+ ]) == {
727
+ "MyObject.qll" : (ql .Stub (name = "MyObject" , base_import = gen_import_prefix + "MyObject" ),
728
+ ql .Class (name = "MyObject" , final = True ,
729
+ properties = [
730
+ ql .Property (singular = "X" , plural = "Xes" , type = "int" ,
731
+ tablename = "my_object_xes" ,
732
+ tableparams = ["this" , "index" , "result" ],
733
+ doc = "special child of this" , doc_plural = "special children of this" ),
734
+ ql .Property (singular = "Y" , plural = "Ys" , type = "int" ,
735
+ tablename = "my_object_ies" , is_optional = True ,
736
+ tableparams = ["this" , "index" , "result" ],
737
+ doc = "special child of this" , doc_plural = "special children of this" ),
738
+ ])),
739
+ }
740
+
741
+
742
+ def test_repeated_property_doc_override_with_multiple_formats (generate_classes ):
743
+ assert generate_classes ([
744
+ schema .Class ("MyObject" , properties = [
745
+ schema .RepeatedProperty ("x" , "int" , doc = "{cat} or {dog}" ),
746
+ schema .RepeatedOptionalProperty ("y" , "int" , doc = "{cats} or {dogs}" )]),
747
+ ]) == {
748
+ "MyObject.qll" : (ql .Stub (name = "MyObject" , base_import = gen_import_prefix + "MyObject" ),
749
+ ql .Class (name = "MyObject" , final = True ,
750
+ properties = [
751
+ ql .Property (singular = "X" , plural = "Xes" , type = "int" ,
752
+ tablename = "my_object_xes" ,
753
+ tableparams = ["this" , "index" , "result" ],
754
+ doc = "cat or dog" , doc_plural = "cats or dogs" ),
755
+ ql .Property (singular = "Y" , plural = "Ys" , type = "int" ,
756
+ tablename = "my_object_ies" , is_optional = True ,
757
+ tableparams = ["this" , "index" , "result" ],
758
+ doc = "cat or dog" , doc_plural = "cats or dogs" ),
759
+ ])),
760
+ }
761
+
762
+
763
+ def test_property_doc_override_with_format (generate_classes ):
764
+ assert generate_classes ([
765
+ schema .Class ("MyObject" , properties = [
766
+ schema .SingleProperty ("foo" , "bar" , doc = "special {baz} of this" )]),
767
+ ]) == {
768
+ "MyObject.qll" : (ql .Stub (name = "MyObject" , base_import = gen_import_prefix + "MyObject" ),
769
+ ql .Class (name = "MyObject" , final = True ,
770
+ properties = [
771
+ ql .Property (singular = "Foo" , type = "bar" , tablename = "my_objects" ,
772
+ tableparams = ["this" , "result" ], doc = "special baz of this" ),
684
773
])),
685
774
}
686
775
0 commit comments