Skip to content

Commit ae1129f

Browse files
committed
Add more parsing tests for (bad) doctypes
1 parent 59ffa6a commit ae1129f

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

tests/test_docstrings.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,48 @@ def test_unexpected_value(self):
3434

3535

3636
class Test_DoctypeTransformer:
37+
@pytest.mark.parametrize(
38+
"doctype",
39+
[
40+
"((float))",
41+
"(float,)",
42+
"(, )",
43+
"...",
44+
"(..., ...)",
45+
"{}",
46+
"{:}",
47+
"{a:}",
48+
"{:b}",
49+
"{'a',}",
50+
"a or (b or c)",
51+
",, optional",
52+
],
53+
)
54+
def test_edge_case_errors(self, doctype):
55+
transformer = DoctypeTransformer()
56+
with pytest.raises(lark.exceptions.UnexpectedInput):
57+
transformer.doctype_to_annotation(doctype)
58+
59+
@pytest.mark.parametrize("doctype", DoctypeTransformer.blacklisted_qualnames)
60+
def test_reserved_keywords(self, doctype):
61+
assert DoctypeTransformer.blacklisted_qualnames
62+
63+
transformer = DoctypeTransformer()
64+
with pytest.raises(lark.exceptions.VisitError):
65+
transformer.doctype_to_annotation(doctype)
66+
67+
@pytest.mark.parametrize(
68+
("doctype", "expected"),
69+
[
70+
("int or float", "int | float"),
71+
("int or float or str", "int | float | str"),
72+
],
73+
)
74+
def test_natlang_union(self, doctype, expected):
75+
transformer = DoctypeTransformer()
76+
annotation, _ = transformer.doctype_to_annotation(doctype)
77+
assert annotation.value == expected
78+
3779
@pytest.mark.parametrize(
3880
("doctype", "expected"),
3981
[
@@ -91,7 +133,7 @@ def test_natlang_container(self, doctype, expected):
91133
"doctype",
92134
[
93135
"list of int (s)",
94-
"list of (float)",
136+
"list of ((float))",
95137
"list of (float,)",
96138
"list of (, )",
97139
"list of ...",

0 commit comments

Comments
 (0)