-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_100_rules.py
101 lines (82 loc) 路 1.81 KB
/
test_100_rules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import pytest
from tests import _results
def test_scr119():
results = _results(
"""
class FooBar:
def __init__(self, a, b):
self.a = a
self.b = b
"""
)
assert results == {"2:0 SCR119 Use a dataclass for 'class FooBar'"}
def test_scr119_ignored_dunder_methods():
"""
Dunder methods do not make a class not be a dataclass candidate.
Examples for dunder (double underscore) methods are:
* __str__
* __eq__
* __hash__
"""
results = _results(
"""
class FooBar:
def __init__(self, a, b):
self.a = a
self.b = b
def __str__(self):
return "FooBar"
"""
)
assert results == {"2:0 SCR119 Use a dataclass for 'class FooBar'"}
@pytest.mark.xfail(
reason="https://github.com/MartinThoma/flake8-simplify/issues/63"
)
def test_scr119_false_positive():
results = _results(
'''class OfType:
"""
>>> 3 == OfType(int, str, bool)
True
>>> 'txt' == OfType(int)
False
"""
def __init__(self, *types):
self.types = types
def __eq__(self, other):
return isinstance(other, self.types)'''
)
for el in results:
assert "SCR119" not in el
def test_scr119_async():
results = _results(
"""
class FooBar:
def __init__(self, a, b):
self.a = a
self.b = b
async def foo(self):
return "FooBar"
"""
)
assert results == set()
def test_scr119_constructor_processing():
results = _results(
"""
class FooBar:
def __init__(self, a):
self.a = a + 5
"""
)
assert results == set()
def test_scr119_pydantic():
results = _results(
"""
from pydantic import BaseModel
class FooBar(BaseModel):
foo : str
class Config:
extra = "allow"
"""
)
assert results == set()