Skip to content

Commit

Permalink
3.10: Do some simple test updates.
Browse files Browse the repository at this point in the history
Updates some tests in cases where it was obvious to me that the problem was in
the test and not the functionality under test.

Only 21 failures in 5 test modules left.

For #1022.

PiperOrigin-RevId: 438635996
  • Loading branch information
rchen152 committed Apr 1, 2022
1 parent d98d573 commit ea9be67
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
17 changes: 16 additions & 1 deletion pytype/tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def foo(x: str, y: str) -> int:
self.assertErrorRegexes(errors, {"e1": r"Expected.*int.*Actual.*str",
"e2": r"Expected.*int.*Actual.*complex"})

def test_ambiguous_return(self):
@test_utils.skipFromPy((3, 10), "Logs one error for all bad returns pre-3.10")
def test_ambiguous_return_pre310(self):
_, errors = self.InferWithErrors("""
def foo(x: str) -> int:
if x:
Expand All @@ -220,6 +221,20 @@ def foo(x: str) -> int:
self.assertErrorRegexes(
errors, {"e": r"Expected.*int.*Actual.*Union(?=.*complex).*str"})

@test_utils.skipBeforePy((3, 10), "Logs one error per bad return in 3.10+")
def test_ambiguous_return(self):
_, errors = self.InferWithErrors("""
def foo(x: str) -> int:
if x:
y = "foo"
else:
y = 3j
return y # bad-return-type[e1] # bad-return-type[e2]
""")
self.assertErrorSequences(
errors, {"e1": ["Expected: int", "Actually returned: str"],
"e2": ["Expected: int", "Actually returned: complex"]})

def test_default_return(self):
ty = self.Infer("""
class Foo:
Expand Down
8 changes: 6 additions & 2 deletions pytype/tests/test_flow1.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,13 @@ def f():
while b:
b = False
""")
self.assertTypesMatchPytd(ty, """
if self.python_version >= (3, 10):
expected_return_type = "None"
else:
expected_return_type = "Any"
self.assertTypesMatchPytd(ty, f"""
from typing import Any
def f() -> Any: ...
def f() -> {expected_return_type}: ...
""")

def test_independent_calls(self):
Expand Down
12 changes: 10 additions & 2 deletions pytype/tests/test_type_comments1.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ def foo(x):
# type: (abc def) -> int # invalid-function-type-comment[e]
return x
""")
self.assertErrorRegexes(errors, {"e": r"abc def.*unexpected EOF"})
if self.python_version >= (3, 10):
error_reason = "invalid syntax"
else:
error_reason = "unexpected EOF"
self.assertErrorRegexes(errors, {"e": rf"abc def.*{error_reason}"})

def test_ambiguous_annotation(self):
_, errors = self.InferWithErrors("""
Expand Down Expand Up @@ -344,7 +348,11 @@ def test_bad_comment(self):
ty, errors = self.InferWithErrors("""
X = None # type: abc def # invalid-annotation[e]
""", deep=True)
self.assertErrorRegexes(errors, {"e": r"abc def.*unexpected EOF"})
if self.python_version >= (3, 10):
error_reason = "invalid syntax"
else:
error_reason = "unexpected EOF"
self.assertErrorRegexes(errors, {"e": rf"abc def.*{error_reason}"})
self.assertTypesMatchPytd(ty, """
from typing import Any
X = ... # type: Any
Expand Down

0 comments on commit ea9be67

Please sign in to comment.