Skip to content

Commit

Permalink
More stub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chadrik committed Nov 3, 2017
1 parent 7588878 commit fbb6b03
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
12 changes: 5 additions & 7 deletions tests/test_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down
43 changes: 36 additions & 7 deletions tests/test_stubs.test
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
[case test_type_annotations]
[case test_type_annotations_pep526]
# cmd: mypy a.py
[file a.py]
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'

0 comments on commit fbb6b03

Please sign in to comment.