summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2020-10-21 01:06:02 +0200
committerBas van Beek <b.f.van.beek@vu.nl>2020-10-21 01:06:02 +0200
commit30adfe2db06060fdbe60d0cd73b892aa8fa29977 (patch)
tree82e420fbe77c9c64aad584e6902c85b3ceeff4f3
parent32f1359fc2d11014b240dee2270acea1784a34bb (diff)
downloadnumpy-30adfe2db06060fdbe60d0cd73b892aa8fa29977.tar.gz
TST: Clean up the errors of the typing tests
-rw-r--r--numpy/typing/tests/test_typing.py47
1 files changed, 42 insertions, 5 deletions
diff --git a/numpy/typing/tests/test_typing.py b/numpy/typing/tests/test_typing.py
index cba1dc1be..f5cc29c2a 100644
--- a/numpy/typing/tests/test_typing.py
+++ b/numpy/typing/tests/test_typing.py
@@ -3,6 +3,7 @@ import itertools
import os
import re
from collections import defaultdict
+from typing import Optional
import pytest
try:
@@ -55,6 +56,8 @@ def test_success(path):
@pytest.mark.skipif(NO_MYPY, reason="Mypy is not installed")
@pytest.mark.parametrize("path", get_test_cases(FAIL_DIR))
def test_fail(path):
+ __tracebackhide__ = True
+
stdout, stderr, exitcode = api.run([
"--config-file",
MYPY_INI,
@@ -95,16 +98,37 @@ def test_fail(path):
target_line = lines[lineno - 1]
if "# E:" in target_line:
marker = target_line.split("# E:")[-1].strip()
- assert lineno in errors, f'Extra error "{marker}"'
- assert marker in errors[lineno]
+ expected_error = errors.get(lineno)
+ _test_fail(path, marker, expected_error, lineno)
else:
pytest.fail(f"Error {repr(errors[lineno])} not found")
+_FAIL_MSG1 = """Extra error at line {}
+
+Extra error: {!r}
+"""
+
+_FAIL_MSG2 = """Error mismatch at line {}
+
+Expected error: {!r}
+Observed error: {!r}
+"""
+
+
+def _test_fail(path: str, error: str, expected_error: Optional[str], lineno: int) -> None:
+ if expected_error is None:
+ raise AssertionError(_FAIL_MSG1.format(lineno, error))
+ elif error not in expected_error:
+ raise AssertionError(_FAIL_MSG2.format(lineno, expected_error, error))
+
+
@pytest.mark.slow
@pytest.mark.skipif(NO_MYPY, reason="Mypy is not installed")
@pytest.mark.parametrize("path", get_test_cases(REVEAL_DIR))
def test_reveal(path):
+ __tracebackhide__ = True
+
stdout, stderr, exitcode = api.run([
"--config-file",
MYPY_INI,
@@ -127,10 +151,23 @@ def test_reveal(path):
)
if match is None:
raise ValueError(f"Unexpected reveal line format: {error_line}")
- lineno = int(match.group('lineno'))
+ lineno = int(match.group('lineno')) - 1
assert "Revealed type is" in error_line
- marker = lines[lineno - 1].split("# E:")[-1].strip()
- assert marker in error_line
+
+ marker = lines[lineno].split("# E:")[-1].strip()
+ _test_reveal(path, marker, error_line, lineno)
+
+
+_REVEAL_MSG = """Reveal mismatch at line {}
+
+Expected reveal: {!r}
+Observed reveal: {!r}
+"""
+
+
+def _test_reveal(path: str, reveal: str, expected_reveal: str, lineno: int) -> None:
+ if reveal not in expected_reveal:
+ raise AssertionError(_REVEAL_MSG.format(lineno, expected_reveal, reveal))
@pytest.mark.slow