-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathtest_ql.py
More file actions
154 lines (111 loc) · 4.61 KB
/
test_ql.py
File metadata and controls
154 lines (111 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import sys
from copy import deepcopy
from misc.codegen.lib import ql
from misc.codegen.test.utils import *
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
indefinite_getters = [
("Argument", "getAnArgument"),
("Element", "getAnElement"),
("Integer", "getAnInteger"),
("Operator", "getAnOperator"),
("Unit", "getAUnit"),
("Whatever", "getAWhatever"),
]
@pytest.mark.parametrize("name,expected_getter", indefinite_getters)
def test_property_indefinite_article(name, expected_getter):
prop = ql.Property(name, plural="X")
assert prop.indefinite_getter == expected_getter
@pytest.mark.parametrize("name,expected_getter", indefinite_getters)
def test_property_unordered_getter(name, expected_getter):
prop = ql.Property(name, plural="X", is_unordered=True)
assert prop.getter == expected_getter
@pytest.mark.parametrize("plural,expected", [
(None, False),
("", False),
("X", True),
])
def test_property_is_repeated(plural, expected):
prop = ql.Property("foo", "Foo", "props", ["result"], plural=plural)
assert prop.is_repeated is expected
@pytest.mark.parametrize("plural,unordered,expected", [
(None, False, False),
("", False, False),
("X", False, True),
("X", True, False),
])
def test_property_is_indexed(plural, unordered, expected):
prop = ql.Property("foo", "Foo", "props", ["result"], plural=plural, is_unordered=unordered)
assert prop.is_indexed is expected
@pytest.mark.parametrize("is_optional,is_predicate,plural,expected", [
(False, False, None, True),
(False, False, "", True),
(False, False, "X", False),
(True, False, None, False),
(False, True, None, False),
])
def test_property_is_single(is_optional, is_predicate, plural, expected):
prop = ql.Property("foo", "Foo", "props", ["result"], plural=plural,
is_predicate=is_predicate, is_optional=is_optional)
assert prop.is_single is expected
def test_property_no_plural_no_indefinite_getter():
prop = ql.Property("Prop", "Foo", "props", ["result"])
assert prop.indefinite_getter is None
def test_property_getter():
prop = ql.Property("Prop", "Foo")
assert prop.getter == "getProp"
def test_property_predicate_getter():
prop = ql.Property("prop", is_predicate=True)
assert prop.getter == "prop"
def test_class_processes_bases():
bases = ["B", "Ab", "C", "Aa"]
expected = [ql.Base("B"), ql.Base("Ab", prev="B"), ql.Base("C", prev="Ab"), ql.Base("Aa", prev="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_root_class():
cls = ql.Class("Class")
assert cls.root
def test_non_root_class():
cls = ql.Class("Class", bases=["A"])
assert not cls.root
@pytest.mark.parametrize("prev_child,is_child", [(None, False), ("", True), ("x", True)])
def test_is_child(prev_child, is_child):
p = ql.Property("Foo", "int", prev_child=prev_child)
assert p.is_child is is_child
def test_empty_class_no_children():
cls = ql.Class("Class", properties=[])
assert cls.has_children is False
def test_class_no_children():
cls = ql.Class("Class", properties=[ql.Property("Foo", "int"), ql.Property("Bar", "string")])
assert cls.has_children is False
def test_class_with_children():
cls = ql.Class("Class", properties=[ql.Property("Foo", "int"), ql.Property("Child", "x", prev_child=""),
ql.Property("Bar", "string")])
assert cls.has_children is True
@pytest.mark.parametrize("doc,expected",
[
(["foo", "bar"], True),
(["foo", "bar"], True),
([], False)
])
def test_has_doc(doc, expected):
stub = ql.Stub("Class", base_import="foo", import_prefix="bar", doc=doc)
assert stub.has_qldoc is expected
def test_synth_accessor_has_first_constructor_param_marked():
params = ["a", "b", "c"]
x = ql.SynthUnderlyingAccessor("foo", "bar", params)
assert x.constructorparams[0].first
assert [p.param for p in x.constructorparams] == params
if __name__ == '__main__':
sys.exit(pytest.main([__file__] + sys.argv[1:]))