Skip to content

Commit

Permalink
Update CHANGES
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Dec 22, 2022
1 parent f192d99 commit e4c87b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Expand Up @@ -6,8 +6,8 @@ Changelog
2.0.2 (unreleased)
------------------

- Nothing changed yet.

- Honor `--builtins` option from flake8 #73.
[gforcada]

2.0.1 (2022-11-01)
------------------
Expand Down
17 changes: 14 additions & 3 deletions run_tests.py
Expand Up @@ -10,20 +10,26 @@

class FakeOptions:
builtins_ignorelist = []
builtins = None

def __init__(self, ignore_list=''):
def __init__(self, ignore_list='', builtins=None):
if ignore_list:
self.builtins_ignorelist = ignore_list
if builtins:
self.builtins = builtins


def check_code(source, expected_codes=None, ignore_list=None):
def check_code(source, expected_codes=None, ignore_list=None, builtins=None):
"""Check if the given source code generates the given flake8 errors
If `expected_codes` is a string is converted to a list,
if it is not given, then it is expected to **not** generate any error.
If `ignore_list` is provided, it should be a list of names
that will be ignored if found, as if they were a builtin.
If `builtins` is provided, it should be a list of names
that will be reported if found, as if they were a builtin.
"""
if isinstance(expected_codes, str):
expected_codes = [expected_codes]
Expand All @@ -33,7 +39,7 @@ def check_code(source, expected_codes=None, ignore_list=None):
ignore_list = []
tree = ast.parse(textwrap.dedent(source))
checker = BuiltinsChecker(tree, '/home/script.py')
checker.parse_options(FakeOptions(ignore_list=ignore_list))
checker.parse_options(FakeOptions(ignore_list=ignore_list, builtins=builtins))
return_statements = list(checker.run())

assert len(return_statements) == len(expected_codes)
Expand Down Expand Up @@ -212,6 +218,11 @@ def test_custom_ignored_names():
check_code(source, ignore_list=('copyright',))


def test_flake8_builtins():
source = 'consider_this_builtin = 4'
check_code(source, ['A001'], builtins=('consider_this_builtin',))


def test_for_loop_variable():
source = """
for format in (1, 2, 3):
Expand Down

0 comments on commit e4c87b5

Please sign in to comment.