mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-06 12:14:28 +08:00
fix @output decorator
This commit is contained in:
@@ -127,7 +127,7 @@ def assert_string_arrays_equal(expected: List[str], actual: List[str]) -> None:
|
||||
actual = _clean_up(actual)
|
||||
error_message = ''
|
||||
|
||||
if actual != expected:
|
||||
if set(actual) != set(expected):
|
||||
num_skip_start = _num_skipped_prefix_lines(expected, actual)
|
||||
num_skip_end = _num_skipped_suffix_lines(expected, actual)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ def reveal_type(obj: Any) -> None:
|
||||
|
||||
def output(output_lines: str):
|
||||
def decor(func: Callable[..., None]):
|
||||
func.out = output_lines
|
||||
func.out = output_lines.strip()
|
||||
|
||||
def wrapper(*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):
|
||||
root_directory = '/run/testdata'
|
||||
root_directory = '/tmp'
|
||||
|
||||
def __init__(self,
|
||||
name: str,
|
||||
@@ -255,9 +255,10 @@ def extract_test_output(attr: Callable[..., None]) -> List[str]:
|
||||
out_data: str = getattr(attr, 'out', None)
|
||||
out_lines = []
|
||||
if out_data:
|
||||
for line in out_data.split('\n'):
|
||||
line = line.strip()
|
||||
out_lines.append(line)
|
||||
for line in out_data.strip().split('\n'):
|
||||
if line:
|
||||
line = line.strip()
|
||||
out_lines.append(line)
|
||||
return out_lines
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -48,6 +48,20 @@ class TestForeignKey(BaseDjangoPluginTestCase):
|
||||
publisher = Publisher()
|
||||
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):
|
||||
def test_onetoone_field(self):
|
||||
|
||||
@@ -10,19 +10,4 @@ class TestObjectsQueryset(BaseDjangoPluginTestCase):
|
||||
pass
|
||||
|
||||
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*'
|
||||
|
||||
Reference in New Issue
Block a user