|
| 1 | +from mutmut.type_checking import parse_pyrefly_report |
| 2 | +from inline_snapshot import snapshot |
| 3 | +from mutmut.type_checking import parse_mypy_report |
| 4 | + |
| 5 | +from pathlib import Path |
| 6 | +from mutmut.type_checking import TypeCheckingError |
| 7 | + |
| 8 | + |
| 9 | +def test_mypy_parsing(): |
| 10 | + mypy_output = [ |
| 11 | + { |
| 12 | + "file": "src/type_checking/__init__.py", |
| 13 | + "line": 40, |
| 14 | + "column": 20, |
| 15 | + "message": 'Incompatible types in assignment (expression has type "None", variable has type "str")', |
| 16 | + "hint": None, |
| 17 | + "code": "assignment", |
| 18 | + "severity": "error", |
| 19 | + }, |
| 20 | + { |
| 21 | + "file": "src/type_checking/__init__.py", |
| 22 | + "line": 73, |
| 23 | + "column": 11, |
| 24 | + "message": 'Unsupported left operand type for - ("str")', |
| 25 | + "hint": None, |
| 26 | + "code": "operator", |
| 27 | + "severity": "error", |
| 28 | + }, |
| 29 | + { |
| 30 | + "file": "src/type_checking/__init__.py", |
| 31 | + "line": 114, |
| 32 | + "column": 4, |
| 33 | + "message": "By default the bodies of untyped functions are not checked, consider using --check-untyped-defs", |
| 34 | + "hint": None, |
| 35 | + "code": "annotation-unchecked", |
| 36 | + "severity": "note", |
| 37 | + }, |
| 38 | + ] |
| 39 | + |
| 40 | + parsed = parse_mypy_report(mypy_output) |
| 41 | + |
| 42 | + assert parsed == snapshot( |
| 43 | + [ |
| 44 | + TypeCheckingError( |
| 45 | + file_path=Path( |
| 46 | + "/home/oaie/coding/python/mutmut/src/type_checking/__init__.py" |
| 47 | + ), |
| 48 | + line_number=40, |
| 49 | + error_description='Incompatible types in assignment (expression has type "None", variable has type "str")', |
| 50 | + ), |
| 51 | + TypeCheckingError( |
| 52 | + file_path=Path( |
| 53 | + "/home/oaie/coding/python/mutmut/src/type_checking/__init__.py" |
| 54 | + ), |
| 55 | + line_number=73, |
| 56 | + error_description='Unsupported left operand type for - ("str")', |
| 57 | + ), |
| 58 | + ] |
| 59 | + ) |
| 60 | + |
| 61 | + |
| 62 | +def test_pyrefly_parsing(): |
| 63 | + pyrefly_output = { |
| 64 | + "errors": [ |
| 65 | + { |
| 66 | + "line": 40, |
| 67 | + "column": 21, |
| 68 | + "stop_line": 40, |
| 69 | + "stop_column": 25, |
| 70 | + "path": "src/type_checking/__init__.py", |
| 71 | + "code": -2, |
| 72 | + "name": "bad-assignment", |
| 73 | + "description": "`None` is not assignable to `str`", |
| 74 | + "concise_description": "`None` is not assignable to `str`", |
| 75 | + "severity": "error", |
| 76 | + }, |
| 77 | + { |
| 78 | + "line": 73, |
| 79 | + "column": 12, |
| 80 | + "stop_line": 73, |
| 81 | + "stop_column": 25, |
| 82 | + "path": "src/type_checking/__init__.py", |
| 83 | + "code": -2, |
| 84 | + "name": "unsupported-operation", |
| 85 | + "description": "`-` is not supported between `str` and `Literal['2']`\n Cannot find `__sub__` or `__rsub__`", |
| 86 | + "concise_description": "`-` is not supported between `str` and `Literal['2']`", |
| 87 | + "severity": "error", |
| 88 | + }, |
| 89 | + ] |
| 90 | + } |
| 91 | + |
| 92 | + result = parse_pyrefly_report(pyrefly_output) |
| 93 | + |
| 94 | + assert result == snapshot( |
| 95 | + [ |
| 96 | + TypeCheckingError( |
| 97 | + file_path=Path( |
| 98 | + "/home/oaie/coding/python/mutmut/src/type_checking/__init__.py" |
| 99 | + ), |
| 100 | + line_number=40, |
| 101 | + error_description="`None` is not assignable to `str`", |
| 102 | + ), |
| 103 | + TypeCheckingError( |
| 104 | + file_path=Path( |
| 105 | + "/home/oaie/coding/python/mutmut/src/type_checking/__init__.py" |
| 106 | + ), |
| 107 | + line_number=73, |
| 108 | + error_description="`-` is not supported between `str` and `Literal['2']`", |
| 109 | + ), |
| 110 | + ] |
| 111 | + ) |
0 commit comments