fix @output decorator

This commit is contained in:
Maxim Kurnikov
2018-11-28 00:43:28 +03:00
parent ba058e340e
commit 96a265348b
4 changed files with 22 additions and 22 deletions

View File

@@ -127,7 +127,7 @@ def assert_string_arrays_equal(expected: List[str], actual: List[str]) -> None:
actual = _clean_up(actual) actual = _clean_up(actual)
error_message = '' error_message = ''
if actual != expected: if set(actual) != set(expected):
num_skip_start = _num_skipped_prefix_lines(expected, actual) num_skip_start = _num_skipped_prefix_lines(expected, actual)
num_skip_end = _num_skipped_suffix_lines(expected, actual) num_skip_end = _num_skipped_suffix_lines(expected, actual)

View File

@@ -24,7 +24,7 @@ def reveal_type(obj: Any) -> None:
def output(output_lines: str): def output(output_lines: str):
def decor(func: Callable[..., None]): def decor(func: Callable[..., None]):
func.out = output_lines func.out = output_lines.strip()
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
return func(*args, **kwargs) return func(*args, **kwargs)
@@ -123,7 +123,7 @@ def fname_to_module(fpath: Path, root_path: Path) -> Optional[str]:
class MypyTypecheckItem(pytest.Item): class MypyTypecheckItem(pytest.Item):
root_directory = '/run/testdata' root_directory = '/tmp'
def __init__(self, def __init__(self,
name: str, name: str,
@@ -255,9 +255,10 @@ def extract_test_output(attr: Callable[..., None]) -> List[str]:
out_data: str = getattr(attr, 'out', None) out_data: str = getattr(attr, 'out', None)
out_lines = [] out_lines = []
if out_data: if out_data:
for line in out_data.split('\n'): for line in out_data.strip().split('\n'):
line = line.strip() if line:
out_lines.append(line) line = line.strip()
out_lines.append(line)
return out_lines return out_lines

View File

@@ -1,4 +1,4 @@
from test.pytest_plugin import reveal_type from test.pytest_plugin import reveal_type, output
from test.pytest_tests.base import BaseDjangoPluginTestCase from test.pytest_tests.base import BaseDjangoPluginTestCase
@@ -48,6 +48,20 @@ class TestForeignKey(BaseDjangoPluginTestCase):
publisher = Publisher() publisher = Publisher()
reveal_type(publisher.books) # E: Revealed type is 'django.db.models.query.QuerySet[main.Book]' reveal_type(publisher.books) # E: Revealed type is 'django.db.models.query.QuerySet[main.Book]'
@output(
"""
main:4: warning: to= parameter type Instance is not supported
"""
)
def test_to_parameter_as_string_fallbacks_to_any(self):
from django.db import models
class Book(models.Model):
publisher = models.ForeignKey(to='Publisher', on_delete=models.CASCADE)
book = Book()
reveal_type(book.publisher) # E: Revealed type is 'Any'
class TestOneToOneField(BaseDjangoPluginTestCase): class TestOneToOneField(BaseDjangoPluginTestCase):
def test_onetoone_field(self): def test_onetoone_field(self):

View File

@@ -10,19 +10,4 @@ class TestObjectsQueryset(BaseDjangoPluginTestCase):
pass pass
reveal_type(User.objects) # E: Revealed type is 'django.db.models.query.QuerySet[main.User]' reveal_type(User.objects) # E: Revealed type is 'django.db.models.query.QuerySet[main.User]'
@output("""
main:10: error: Revealed type is 'Any'
main:10: error: "Type[ModelMixin]" has no attribute "objects"
""")
def test_objects_get_returns_model_instance(self):
from django.db import models
class ModelMixin(models.Model):
class Meta:
abstract = True
class User(ModelMixin):
pass
reveal_type(User.objects.get()) # E: Revealed type is 'main.User*' reveal_type(User.objects.get()) # E: Revealed type is 'main.User*'