|
| 1 | +import pytest |
| 2 | +from full_match import match |
| 3 | + |
| 4 | +from printo import describe_call, not_none |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.mypy_testing |
| 8 | +def test_describe_call_basic(): |
| 9 | + """mypy accepts the basic call signature and infers str return type.""" |
| 10 | + _: str = describe_call('MyClass', (1, 2, 'text'), {'key': 1}) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.mypy_testing |
| 14 | +def test_describe_call_with_list_args(): |
| 15 | + """mypy accepts a list for the args parameter, not only tuple.""" |
| 16 | + _: str = describe_call('MyClass', [1, 2, 'text'], {'key': 1}) |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.mypy_testing |
| 20 | +def test_describe_call_with_filters(): |
| 21 | + """mypy accepts a filters dict with int and str keys and callable values.""" |
| 22 | + _: str = describe_call('MyClass', (1, 2), {'key': 1}, filters={1: lambda x: x != 2, 'key': lambda _: True}) |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.mypy_testing |
| 26 | +def test_describe_call_with_not_none_filter(): |
| 27 | + """mypy accepts not_none as a valid filter value.""" |
| 28 | + _: str = describe_call('MyClass', (1, None), {}, filters={1: not_none}) |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.mypy_testing |
| 32 | +def test_describe_call_with_serializer(): |
| 33 | + """mypy accepts a Callable[[Any], str] for the serializer parameter.""" |
| 34 | + _: str = describe_call('MyClass', (1, 2), {'key': 'val'}, serializer=lambda x: repr(x).upper()) |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.mypy_testing |
| 38 | +def test_describe_call_with_placeholders(): |
| 39 | + """mypy accepts a placeholders dict with str and int keys and str values.""" |
| 40 | + _: str = describe_call('MyClass', (1, 2), {'password': 'secret'}, placeholders={0: '***', 'password': '***'}) |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.mypy_testing |
| 44 | +def test_describe_call_with_item_limit(): |
| 45 | + """mypy accepts an int for the item_limit parameter.""" |
| 46 | + _: str = describe_call('MyClass', (123456789,), {'name': 'a very long string'}, item_limit=5) |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.mypy_testing |
| 50 | +def test_describe_call_with_total_limit(): |
| 51 | + """mypy accepts an int for the total_limit parameter.""" |
| 52 | + _: str = describe_call('MyClass', (), {'a': 1, 'b': 2, 'c': 3}, total_limit=20) |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.mypy_testing |
| 56 | +def test_describe_call_invalid_class_name_type(): |
| 57 | + """mypy rejects int as class_name — expected str.""" |
| 58 | + describe_call(42, [], {}) # E: [arg-type] |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.mypy_testing |
| 62 | +def test_describe_call_invalid_args_type(): |
| 63 | + """mypy rejects dict as args — expected Tuple or List.""" |
| 64 | + describe_call('MyClass', {}, {}) # E: [arg-type] |
| 65 | + |
| 66 | + |
| 67 | +@pytest.mark.mypy_testing |
| 68 | +def test_describe_call_invalid_kwargs_key_type(): |
| 69 | + """mypy rejects int as a kwargs key — expected str.""" |
| 70 | + describe_call('MyClass', (), {1: 'val'}) # E: [dict-item] |
| 71 | + |
| 72 | + |
| 73 | +@pytest.mark.mypy_testing |
| 74 | +def test_describe_call_invalid_kwargs_type(): |
| 75 | + """mypy rejects list as kwargs — expected Dict[str, Any].""" |
| 76 | + with pytest.raises(AttributeError, match=match("'list' object has no attribute 'items'")): |
| 77 | + describe_call('MyClass', [], []) # E: [arg-type] |
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.mypy_testing |
| 81 | +def test_describe_call_invalid_serializer_type(): |
| 82 | + """mypy rejects int as serializer — expected Callable[[Any], str].""" |
| 83 | + with pytest.raises(ValueError, match=match('It is impossible to determine the signature of an object that is not being callable.')): |
| 84 | + describe_call('MyClass', [], {}, serializer=42) # E: [arg-type] |
| 85 | + |
| 86 | + |
| 87 | +@pytest.mark.mypy_testing |
| 88 | +def test_describe_call_invalid_filters_key_type(): |
| 89 | + """mypy rejects float as a filters key — expected str or int.""" |
| 90 | + describe_call('MyClass', [], {}, filters={1.5: not_none}) # E: [dict-item] |
| 91 | + |
| 92 | + |
| 93 | +@pytest.mark.mypy_testing |
| 94 | +def test_describe_call_invalid_filters_value_type(): |
| 95 | + """mypy rejects int as a filters value — expected Callable[[Any], bool].""" |
| 96 | + describe_call('MyClass', [], {}, filters={'x': 42}) # E: [dict-item] |
| 97 | + |
| 98 | + |
| 99 | +@pytest.mark.mypy_testing |
| 100 | +def test_describe_call_invalid_placeholders_key_type(): |
| 101 | + """mypy rejects float as a placeholders key — expected str or int.""" |
| 102 | + describe_call('MyClass', [], {}, placeholders={1.5: '***'}) # E: [dict-item] |
| 103 | + |
| 104 | + |
| 105 | +@pytest.mark.mypy_testing |
| 106 | +def test_describe_call_invalid_placeholders_value_type(): |
| 107 | + """mypy rejects int as a placeholders value — expected str.""" |
| 108 | + describe_call('MyClass', [], {}, placeholders={'x': 42}) # E: [dict-item] |
| 109 | + |
| 110 | + |
| 111 | +@pytest.mark.mypy_testing |
| 112 | +def test_describe_call_invalid_item_limit_type(): |
| 113 | + """mypy rejects str as item_limit — expected int.""" |
| 114 | + with pytest.raises(TypeError, match=match("'<' not supported between instances of 'str' and 'int'")): |
| 115 | + describe_call('MyClass', [], {}, item_limit='5') # E: [arg-type] |
| 116 | + |
| 117 | + |
| 118 | +@pytest.mark.mypy_testing |
| 119 | +def test_describe_call_invalid_total_limit_type(): |
| 120 | + """mypy rejects str as total_limit — expected int.""" |
| 121 | + with pytest.raises(TypeError, match=match("'<' not supported between instances of 'str' and 'int'")): |
| 122 | + describe_call('MyClass', [], {}, total_limit='15') # E: [arg-type] |
0 commit comments