Skip to content

Commit 491bac9

Browse files
committed
Follow review
* remove redundant type declarartions * comment about aliasing * s/AssertionFailure/AssertionError/g * Fix comment in pytest.ini
1 parent 0cb5798 commit 491bac9

File tree

10 files changed

+31
-34
lines changed

10 files changed

+31
-34
lines changed

mypy/test/data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,12 @@ def repr_failure(self, excinfo: Any) -> str:
658658
class DataSuite:
659659
# option fields - class variables
660660
files = None # type: List[str]
661-
base_path = '.' # type: str
662-
optional_out = False # type: bool
663-
native_sep = False # type: bool
661+
base_path = '.'
662+
optional_out = False
663+
native_sep = False
664664

665665
# Assigned from MypyDataCase.runtest
666-
update_data = False # type: bool
666+
update_data = False
667667

668668
def setup(self) -> None:
669669
"""Setup fixtures (ad-hoc)"""

mypy/test/helpers.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from mypy import defaults
99

1010
import pytest # type: ignore # no pytest in typeshed
11+
12+
# Exporting Suite as alias to TestCase for backwards compatibility
13+
# TODO: avoid aliasing - import and subclass TestCase directly
1114
from unittest import TestCase as Suite
1215

1316
from mypy.main import process_options
@@ -89,7 +92,7 @@ def assert_string_arrays_equal(expected: List[str], actual: List[str],
8992
# long lines.
9093
show_align_message(expected[first_diff], actual[first_diff])
9194

92-
raise AssertionFailure(msg)
95+
raise AssertionError(msg)
9396

9497

9598
def update_testcase_output(testcase: DataDrivenTestCase, output: List[str]) -> None:
@@ -254,24 +257,17 @@ def retry_on_error(func: Callable[[], Any], max_wait: float = 1.0) -> None:
254257
raise
255258
time.sleep(wait_time)
256259

257-
258-
class AssertionFailure(Exception):
259-
"""Exception used to signal failed test cases."""
260-
def __init__(self, s: Optional[str] = None) -> None:
261-
if s:
262-
super().__init__(s)
263-
else:
264-
super().__init__()
260+
# TODO: assert_true and assert_false are redundant - use plain assert
265261

266262

267263
def assert_true(b: bool, msg: Optional[str] = None) -> None:
268264
if not b:
269-
raise AssertionFailure(msg)
265+
raise AssertionError(msg)
270266

271267

272268
def assert_false(b: bool, msg: Optional[str] = None) -> None:
273269
if b:
274-
raise AssertionFailure(msg)
270+
raise AssertionError(msg)
275271

276272

277273
def good_repr(obj: object) -> str:
@@ -288,7 +284,7 @@ def good_repr(obj: object) -> str:
288284

289285
def assert_equal(a: object, b: object, fmt: str = '{} != {}') -> None:
290286
if a != b:
291-
raise AssertionFailure(fmt.format(good_repr(a), good_repr(b)))
287+
raise AssertionError(fmt.format(good_repr(a), good_repr(b)))
292288

293289

294290
def typename(t: type) -> str:
@@ -300,7 +296,7 @@ def typename(t: type) -> str:
300296

301297
def assert_type(typ: type, value: object) -> None:
302298
if type(value) != typ:
303-
raise AssertionFailure('Invalid type {}, expected {}'.format(
299+
raise AssertionError('Invalid type {}, expected {}'.format(
304300
typename(type(value)), typename(typ)))
305301

306302

mypy/test/testcheck.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from mypy.test.config import test_temp_dir
1212
from mypy.test.data import DataDrivenTestCase, DataSuite
1313
from mypy.test.helpers import (
14-
assert_string_arrays_equal, normalize_error_messages, AssertionFailure,
14+
assert_string_arrays_equal, normalize_error_messages,
1515
retry_on_error, update_testcase_output, parse_options
1616
)
1717
from mypy.errors import CompileError
@@ -245,8 +245,8 @@ def verify_cache(self, module_data: List[Tuple[str, str, str]], a: List[str],
245245
modules.update({module_name: path for module_name, path, text in module_data})
246246
missing_paths = self.find_missing_cache_files(modules, manager)
247247
if not missing_paths.issubset(error_paths):
248-
raise AssertionFailure("cache data discrepancy %s != %s" %
249-
(missing_paths, error_paths))
248+
raise AssertionError("cache data discrepancy %s != %s" %
249+
(missing_paths, error_paths))
250250

251251
def find_error_paths(self, a: List[str]) -> Set[str]:
252252
hits = set()

mypy/test/testcmdline.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from typing import List
1313

14-
from mypy.test.helpers import AssertionFailure
1514
from mypy.test.config import test_temp_dir
1615
from mypy.test.data import fix_cobertura_filename
1716
from mypy.test.data import DataDrivenTestCase, DataSuite
@@ -65,7 +64,7 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
6564
if testcase.output_files:
6665
for path, expected_content in testcase.output_files:
6766
if not os.path.exists(path):
68-
raise AssertionFailure(
67+
raise AssertionError(
6968
'Expected file {} was not produced by test case'.format(path))
7069
with open(path, 'r') as output_file:
7170
actual_output_content = output_file.read().splitlines()

mypy/test/testdmypy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from mypy.test.config import test_temp_dir
1414
from mypy.test.data import DataDrivenTestCase, DataSuite, has_stable_flags, is_incremental
1515
from mypy.test.helpers import (
16-
assert_string_arrays_equal, normalize_error_messages, AssertionFailure,
16+
assert_string_arrays_equal, normalize_error_messages,
1717
retry_on_error, testcase_pyversion, update_testcase_output,
1818
)
1919
from mypy.options import Options
@@ -194,8 +194,8 @@ def verify_cache(self, module_data: List[Tuple[str, str, Optional[str]]], a: Lis
194194
modules.update({module_name: path for module_name, path, text in module_data})
195195
missing_paths = self.find_missing_cache_files(modules, manager)
196196
if not missing_paths.issubset(error_paths):
197-
raise AssertionFailure("cache data discrepancy %s != %s" %
198-
(missing_paths, error_paths))
197+
raise AssertionError("cache data discrepancy %s != %s" %
198+
(missing_paths, error_paths))
199199

200200
def find_error_paths(self, a: List[str]) -> Set[str]:
201201
hits = set()

mypy/test/testerrorstream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from mypy import defaults, build
77
from mypy.test.config import test_temp_dir
8-
from mypy.test.helpers import assert_string_arrays_equal, AssertionFailure
8+
from mypy.test.helpers import assert_string_arrays_equal
99
from mypy.test.data import DataDrivenTestCase, DataSuite
1010
from mypy.build import BuildSource
1111
from mypy.errors import CompileError

mypy/test/testparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for the mypy parser."""
22

33
from mypy import defaults
4-
from mypy.test.helpers import assert_string_arrays_equal, AssertionFailure
4+
from mypy.test.helpers import assert_string_arrays_equal
55
from mypy.test.data import DataDrivenTestCase, DataSuite
66
from mypy.parse import parse
77
from mypy.errors import CompileError
@@ -59,7 +59,7 @@ def test_parse_error(testcase: DataDrivenTestCase) -> None:
5959
# Compile temporary file. The test file contains non-ASCII characters.
6060
parse(bytes('\n'.join(testcase.input), 'utf-8'), INPUT_FILE_NAME, '__main__', None,
6161
Options())
62-
raise AssertionFailure('No errors reported')
62+
raise AssertionError('No errors reported')
6363
except CompileError as e:
6464
assert e.module_with_blocker == '__main__'
6565
# Verify that there was a compile error and that the error messages

mypy/test/testtransform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_transform(testcase: DataDrivenTestCase) -> None:
6363
and not os.path.basename(f.path).startswith('_')
6464
and not os.path.splitext(
6565
os.path.basename(f.path))[0].endswith('_')):
66-
t = TestTransformVisitor()
66+
t = TypeAssertTransformVisitor()
6767
f = t.mypyfile(f)
6868
a += str(f).split('\n')
6969
except CompileError as e:
@@ -75,7 +75,7 @@ def test_transform(testcase: DataDrivenTestCase) -> None:
7575
testcase.line))
7676

7777

78-
class TestTransformVisitor(TransformVisitor):
78+
class TypeAssertTransformVisitor(TransformVisitor):
7979
def type(self, type: Type) -> Type:
8080
assert type is not None
8181
return type

pytest.ini

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ python_files = test*.py
1212
# and invokes it at the relevant moment. See
1313
# http://doc.pytest.org/en/latest/writing_plugins.html#collection-hooks
1414

15-
# Because we provide our own collection logic, disable the default
16-
# python collector by giving it empty patterns to search for.
17-
python_classes = *Suite
15+
# Both our plugin and unittest provide their own collection logic,
16+
# So we can disable the default python collector by giving it empty
17+
# patterns to search for.
18+
# Note that unittest requires that no "Test*" classes exist.
19+
python_classes =
1820
python_functions =
1921

2022
# always run in parallel (requires pytest-xdist, see test-requirements.txt)

0 commit comments

Comments
 (0)