Skip to content

Commit 665e061

Browse files
committed
Allow specifying test case outputs using comments
1 parent 5043b84 commit 665e061

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
[case testAnnotateNonNativeAttribute]
22
def f(x):
3-
return x.foo
3+
return x.foo # A: Get non-native attribute "foo".
44

55
class C:
66
foo: int
77

88
def g(x: C) -> int:
99
return x.foo
10-
[out]
11-
2: Get non-native attribute "foo".
1210

1311
[case testAnnotateGenericAdd]
1412
def f(x):
15-
return x + 1
13+
return x + 1 # A: Generic "+" operation.
1614

1715
def g(x: int) -> int:
1816
return x + 1
19-
[out]
20-
2: Generic "+" operation.
2117

2218
[case testAnnotateTwoOperationsOnLine]
2319
def f(x):
24-
return x.foo + 1
25-
[out]
26-
2: Get non-native attribute "foo". Generic "+" operation.
20+
return x.foo + 1 # A: Get non-native attribute "foo". Generic "+" operation.

mypyc/test/test_annotate.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
3434
return
3535
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
3636
expected_output = remove_comment_lines(testcase.output)
37+
38+
# Parse "# A: <message>" comments.
39+
for i, line in enumerate(testcase.input):
40+
if "# A:" in line:
41+
msg = line.rpartition("# A:")[2].strip()
42+
expected_output.append(f"{i + 1}: {msg}")
43+
3744
try:
3845
ir, tree = build_ir_for_single_file2(testcase.input, options)
3946
except CompileError as e:
4047
actual = e.messages
4148
else:
4249
annotations = generate_annotations("native.py", tree, ir)
4350
actual = []
44-
for line, line_anns in annotations.annotations.items():
51+
for line_num, line_anns in annotations.annotations.items():
4552
s = " ".join(line_anns)
46-
actual.append(f"{line}: {s}")
53+
actual.append(f"{line_num}: {s}")
4754

4855
assert_test_output(testcase, actual, "Invalid source code output", expected_output)

0 commit comments

Comments
 (0)