Skip to content

Commit 81307ec

Browse files
committed
feat(tests): add tests for the new ignore list
1 parent 760030d commit 81307ec

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Diff for: run_tests.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,33 @@
99
from flake8_builtins import BuiltinsChecker
1010

1111

12+
class FakeOptions:
13+
builtins_ignorelist = []
14+
15+
def __init__(self, ignore_list=''):
16+
if ignore_list:
17+
self.builtins_ignorelist = ignore_list
18+
19+
1220
class TestBuiltins(unittest.TestCase):
13-
def check_code(self, source, expected_codes=None):
21+
def check_code(self, source, expected_codes=None, ignore_list=None):
1422
"""Check if the given source code generates the given flake8 errors
1523
1624
If `expected_codes` is a string is converted to a list,
1725
if it is not given, then it is expected to **not** generate any error.
26+
27+
If `ignore_list` is provided, it should be a list of names
28+
that will be ignored if found, as if they were a builtin.
1829
"""
1930
if isinstance(expected_codes, str):
2031
expected_codes = [expected_codes]
2132
elif expected_codes is None:
2233
expected_codes = []
34+
if ignore_list is None:
35+
ignore_list = []
2336
tree = ast.parse(textwrap.dedent(source))
2437
checker = BuiltinsChecker(tree, '/home/script.py')
38+
checker.parse_options(FakeOptions(ignore_list=ignore_list), None)
2539
return_statements = list(checker.run())
2640

2741
self.assertEqual(
@@ -169,13 +183,17 @@ def bla():
169183
"""
170184
self.check_code(source, ['A001', 'A001'])
171185

172-
def test_ignore_whitelisted_names(self):
186+
def test_default_ignored_names(self):
173187
source = """
174188
class MyClass(object):
175189
__name__ = 4
176190
"""
177191
self.check_code(source)
178192

193+
def test_custom_ignored_names(self):
194+
source = 'copyright = 4'
195+
self.check_code(source, ignore_list=('copyright',))
196+
179197
def test_for_loop_variable(self):
180198
source = """
181199
for format in (1, 2, 3):

0 commit comments

Comments
 (0)