From fbb6b03f53427fab846a9d2d8ce3dfb1f203480d Mon Sep 17 00:00:00 2001 From: Chad Dombrova Date: Fri, 3 Nov 2017 12:23:06 -0700 Subject: [PATCH] More stub tests --- tests/test_stubs.py | 12 +++++------- tests/test_stubs.test | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/tests/test_stubs.py b/tests/test_stubs.py index ec4c02e40..970d8c957 100644 --- a/tests/test_stubs.py +++ b/tests/test_stubs.py @@ -5,9 +5,7 @@ import subprocess import sys -from typing import Tuple, List, Dict, Set - -from mypy.test.data import parse_test_cases, DataDrivenTestCase, DataSuite +from mypy.test.data import parse_test_cases, DataSuite from mypy.test.helpers import (assert_string_arrays_equal, normalize_error_messages) @@ -21,18 +19,18 @@ class PythonEvaluationSuite(DataSuite): @classmethod - def cases(cls) -> List[DataDrivenTestCase]: + def cases(cls): return parse_test_cases(test_file, _test_python_evaluation, base_path=test_temp_dir, optional_out=True, native_sep=True) - def run_case(self, testcase: DataDrivenTestCase): + def run_case(self, testcase): _test_python_evaluation(testcase) -def _test_python_evaluation(testcase: DataDrivenTestCase) -> None: +def _test_python_evaluation(testcase): assert testcase.old_cwd is not None, "test was not properly set up" # Write the program to a file. program = '_program.py' @@ -61,7 +59,7 @@ def _test_python_evaluation(testcase: DataDrivenTestCase) -> None: testcase.file, testcase.line)) -def parse_args(line: str) -> List[str]: +def parse_args(line): """Parse the first line of the program for the command line. This should have the form diff --git a/tests/test_stubs.test b/tests/test_stubs.test index 7af9cfaa4..027503cee 100644 --- a/tests/test_stubs.test +++ b/tests/test_stubs.test @@ -1,4 +1,4 @@ -[case test_type_annotations] +[case test_type_annotations_pep526] # cmd: mypy a.py [file a.py] import attr @@ -6,15 +6,44 @@ import attr @attr.s class C(object): a : int = attr.ib() - b = attr.ib(type=int) c = C() reveal_type(c.a) -reveal_type(c.b) reveal_type(C.a) -reveal_type(C.b) [out] +a.py:8: error: Revealed type is 'builtins.int' a.py:9: error: Revealed type is 'builtins.int' -a.py:10: error: Revealed type is 'builtins.int' -a.py:11: error: Revealed type is 'builtins.int' -a.py:12: error: Revealed type is 'builtins.int' + + +[case test_type_annotations_arg] +# cmd: mypy a.py +[file a.py] +import attr + +@attr.s +class C(object): + a = attr.ib(type=int) + +c = C() +reveal_type(c.a) +reveal_type(C.a) +[out] +a.py:8: error: Revealed type is 'builtins.int*' +a.py:9: error: Revealed type is 'builtins.int*' + + +[case test_type_annotations_missing] +# cmd: mypy a.py +[file a.py] +import attr + +@attr.s +class C(object): + a = attr.ib() + +c = C() +reveal_type(c.a) +reveal_type(C.a) +[out] +a.py:8: error: Revealed type is 'Any' +a.py:9: error: Revealed type is 'Any'