| 1 |
-- Test cases for `--output=json`. |
| 2 |
-- These cannot be run by the usual unit test runner because of the backslashes |
| 3 |
-- in the output, which get normalized to forward slashes by the test suite on |
| 4 |
-- Windows. |
| 5 |
|
| 6 |
[case testOutputJsonNoIssues] |
| 7 |
# flags: --output=json |
| 8 |
def foo() -> None: |
| 9 |
pass |
| 10 |
|
| 11 |
foo() |
| 12 |
[out] |
| 13 |
|
| 14 |
[case testOutputJsonSimple] |
| 15 |
# flags: --output=json |
| 16 |
def foo() -> None: |
| 17 |
pass |
| 18 |
|
| 19 |
foo(1) |
| 20 |
[out] |
| 21 |
{"file": "main", "line": 5, "column": 0, "end_line": 5, "end_column": 6, "message": "Too many arguments for \"foo\"", "hint": null, "code": "call-arg", "severity": "error"} |
| 22 |
|
| 23 |
[case testOutputJsonWithHint] |
| 24 |
# flags: --output=json |
| 25 |
from typing import Optional, overload |
| 26 |
|
| 27 |
@overload |
| 28 |
def foo() -> None: ... |
| 29 |
@overload |
| 30 |
def foo(x: int) -> None: ... |
| 31 |
|
| 32 |
def foo(x: Optional[int] = None) -> None: |
| 33 |
... |
| 34 |
|
| 35 |
reveal_type(foo) |
| 36 |
|
| 37 |
foo('42') |
| 38 |
|
| 39 |
def bar() -> None: ... |
| 40 |
bar('42') |
| 41 |
[out] |
| 42 |
{"file": "main", "line": 12, "column": 12, "end_line": 12, "end_column": 15, "message": "Revealed type is \"Overload(def (), def (x: int))\"", "hint": null, "code": "misc", "severity": "note"} |
| 43 |
{"file": "main", "line": 14, "column": 0, "end_line": 14, "end_column": 9, "message": "No overload variant of \"foo\" matches argument type \"str\"", "hint": "Possible overload variants:\n def foo() -> None\n def foo(x: int) -> None", "code": "call-overload", "severity": "error"} |
| 44 |
{"file": "main", "line": 17, "column": 0, "end_line": 17, "end_column": 9, "message": "Too many arguments for \"bar\"", "hint": null, "code": "call-arg", "severity": "error"} |
| 45 |
|
| 46 |
[case testOutputJsonParallel] |
| 47 |
# flags: --output=json --num-workers=2 |
| 48 |
def foo() -> None: |
| 49 |
pass |
| 50 |
|
| 51 |
foo(1) |
| 52 |
[out] |
| 53 |
{"file": "main", "line": 5, "column": 0, "end_line": 5, "end_column": 6, "message": "Too many arguments for \"foo\"", "hint": null, "code": "call-arg", "severity": "error"} |
| 54 |
|
| 55 |
[case testOutputJsonSyntaxError] |
| 56 |
# flags: --output=json |
| 57 |
klass foo |
| 58 |
[out] |
| 59 |
{"file": "main", "line": 2, "column": 7, "end_line": 2, "end_column": 8, "message": "Invalid syntax", "hint": null, "code": "syntax", "severity": "error"} |
| 60 |
!!! Mypy crashed !!! |
| 61 |
|
| 62 |
[case testOutputJsonSyntaxErrorParallel] |
| 63 |
# flags: --output=json --num-workers=2 |
| 64 |
break |
| 65 |
[out] |
| 66 |
{"file": "main", "line": 2, "column": 0, "end_line": 2, "end_column": 5, "message": "\"break\" outside loop", "hint": null, "code": null, "severity": "error"} |
| 67 |
!!! Mypy crashed !!! |