Skip to content

Commit

Permalink
support python version specific mypy outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Apr 2, 2022
1 parent 00c95d0 commit 0c126e8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
39 changes: 39 additions & 0 deletions tests/mypy/outputs/python3.10/plugin-fail-strict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
24: error: Unexpected keyword argument "z" for "Model" [call-arg]
25: error: Missing named argument "y" for "Model" [call-arg]
26: error: Property "y" defined in "Model" is read-only [misc]
27: error: "Model" does not have orm_mode=True [pydantic-orm]
36: error: Unexpected keyword argument "x" for "ForbidExtraModel" [call-arg]
47: error: Unexpected keyword argument "x" for "ForbidExtraModel2" [call-arg]
53: error: Invalid value for "Config.extra" [pydantic-config]
58: error: Invalid value for "Config.orm_mode" [pydantic-config]
63: error: Invalid value for "Config.orm_mode" [pydantic-config]
74: error: Incompatible types in assignment (expression has type "ellipsis", variable has type "int") [assignment]
77: error: Untyped fields disallowed [pydantic-field]
84: error: Untyped fields disallowed [pydantic-field]
87: error: Missing named argument "a" for "DefaultTestingModel" [call-arg]
87: error: Missing named argument "b" for "DefaultTestingModel" [call-arg]
87: error: Missing named argument "c" for "DefaultTestingModel" [call-arg]
87: error: Missing named argument "d" for "DefaultTestingModel" [call-arg]
87: error: Missing named argument "e" for "DefaultTestingModel" [call-arg]
91: error: Name "Undefined" is not defined [name-defined]
94: error: Missing named argument "undefined" for "UndefinedAnnotationModel" [call-arg]
101: error: Missing named argument "y" for "construct" of "Model" [call-arg]
103: error: Argument "x" to "construct" of "Model" has incompatible type "str"; expected "int" [arg-type]
108: error: Argument "x" to "InheritingModel" has incompatible type "str"; expected "int" [arg-type]
109: error: Argument "x" to "Settings" has incompatible type "str"; expected "int" [arg-type]
110: error: Argument "x" to "Model" has incompatible type "str"; expected "int" [arg-type]
127: error: Argument "data" to "Response" has incompatible type "int"; expected "Model" [arg-type]
135: error: Argument "y" to "AliasModel" has incompatible type "int"; expected "str" [arg-type]
141: error: Required dynamic aliases disallowed [pydantic-alias]
145: error: Argument "z" to "DynamicAliasModel" has incompatible type "str"; expected "int" [arg-type]
156: error: Unexpected keyword argument "y" for "DynamicAliasModel2" [call-arg]
163: error: Required dynamic aliases disallowed [pydantic-alias]
181: error: Untyped fields disallowed [pydantic-field]
185: error: Unexpected keyword argument "x" for "AliasGeneratorModel2" [call-arg]
186: error: Unexpected keyword argument "z" for "AliasGeneratorModel2" [call-arg]
189: error: Name "Missing" is not defined [name-defined]
197: error: No overload variant of "dataclass" matches argument type "Dict[<nothing>, <nothing>]" [call-overload]
197: note: Possible overload variants:
197: note: def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., config: Optional[Type[Any]] = ..., kw_only: bool = ...) -> Callable[[Type[Any]], Type[Dataclass]]
197: note: def dataclass(_cls: Type[Any], *, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., config: Optional[Type[Any]] = ..., kw_only: bool = ...) -> Type[Dataclass]
219: error: Property "y" defined in "FrozenModel" is read-only [misc]
28 changes: 28 additions & 0 deletions tests/mypy/outputs/python3.10/plugin-fail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
24: error: Unexpected keyword argument "z" for "Model" [call-arg]
25: error: Missing named argument "y" for "Model" [call-arg]
26: error: Property "y" defined in "Model" is read-only [misc]
27: error: "Model" does not have orm_mode=True [pydantic-orm]
36: error: Unexpected keyword argument "x" for "ForbidExtraModel" [call-arg]
47: error: Unexpected keyword argument "x" for "ForbidExtraModel2" [call-arg]
53: error: Invalid value for "Config.extra" [pydantic-config]
58: error: Invalid value for "Config.orm_mode" [pydantic-config]
63: error: Invalid value for "Config.orm_mode" [pydantic-config]
74: error: Incompatible types in assignment (expression has type "ellipsis", variable has type "int") [assignment]
87: error: Missing named argument "a" for "DefaultTestingModel" [call-arg]
87: error: Missing named argument "b" for "DefaultTestingModel" [call-arg]
87: error: Missing named argument "c" for "DefaultTestingModel" [call-arg]
87: error: Missing named argument "d" for "DefaultTestingModel" [call-arg]
87: error: Missing named argument "e" for "DefaultTestingModel" [call-arg]
91: error: Name "Undefined" is not defined [name-defined]
94: error: Missing named argument "undefined" for "UndefinedAnnotationModel" [call-arg]
101: error: Missing named argument "y" for "construct" of "Model" [call-arg]
103: error: Argument "x" to "construct" of "Model" has incompatible type "str"; expected "int" [arg-type]
156: error: Missing named argument "x" for "DynamicAliasModel2" [call-arg]
175: error: Unused "type: ignore" comment
182: error: Unused "type: ignore" comment
189: error: Name "Missing" is not defined [name-defined]
197: error: No overload variant of "dataclass" matches argument type "Dict[<nothing>, <nothing>]" [call-overload]
197: note: Possible overload variants:
197: note: def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., config: Optional[Type[Any]] = ..., kw_only: bool = ...) -> Callable[[Type[Any]], Type[Dataclass]]
197: note: def dataclass(_cls: Type[Any], *, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., config: Optional[Type[Any]] = ..., kw_only: bool = ...) -> Type[Dataclass]
219: error: Property "y" defined in "FrozenModel" is read-only [misc]
22 changes: 21 additions & 1 deletion tests/mypy/test_mypy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib
import os
import re
import sys
from pathlib import Path

import pytest
Expand Down Expand Up @@ -49,7 +50,26 @@
def test_mypy_results(config_filename: str, python_filename: str, output_filename: str) -> None:
full_config_filename = f'tests/mypy/configs/{config_filename}'
full_filename = f'tests/mypy/modules/{python_filename}'
output_path = None if output_filename is None else Path(f'tests/mypy/outputs/{output_filename}')

if output_filename is None:
output_path = None
else:
# check for python version specific output files
# eg. if there's an "outputs/plugin-fail.txt" and a "outputs/python3.10/plugin-fail.txt" then use the 3.10 one
# if the current python version is >= 3.10
root_output_dir = 'tests/mypy/outputs'
for child in os.listdir(root_output_dir):
output_dir = os.path.join(root_output_dir, child)
if (
os.path.isdir(output_dir)
and sys.version_info >= tuple(map(int, re.match(r'^python(\d+)\.(\d+)$', child).groups()))
and Path(output_dir, output_filename).exists()
):
break
else:
output_dir = root_output_dir

output_path = Path(f'{output_dir}/{output_filename}')

# Specifying a different cache dir for each configuration dramatically speeds up subsequent execution
# It also prevents cache-invalidation-related bugs in the tests
Expand Down

0 comments on commit 0c126e8

Please sign in to comment.