Skip to content

Commit

Permalink
fix: correct ignoring module names
Browse files Browse the repository at this point in the history
and test that using the option works as expected
  • Loading branch information
asfaltboy committed Mar 25, 2024
1 parent 246537c commit 99ef517
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flake8_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BuiltinsChecker:
'credits',
'_',
}
ignored_module_names = {}
ignored_module_names = set()

def __init__(self, tree, filename):
self.tree = tree
Expand Down
22 changes: 21 additions & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def check_code(
expected_codes=None,
ignore_list=None,
builtins=None,
builtins_allowed_modules=None,
filename='/home/script.py',
):
"""Check if the given source code generates the given flake8 errors
Expand All @@ -47,7 +48,13 @@ def check_code(
ignore_list = []
tree = ast.parse(textwrap.dedent(source))
checker = BuiltinsChecker(tree, filename)
checker.parse_options(FakeOptions(ignore_list=ignore_list, builtins=builtins))
checker.parse_options(
FakeOptions(
ignore_list=ignore_list,
builtins=builtins,
builtins_allowed_modules=builtins_allowed_modules,
)
)
return_statements = list(checker.run())

assert len(return_statements) == len(expected_codes)
Expand Down Expand Up @@ -489,6 +496,19 @@ def test_module_name():
check_code(source, expected_codes='A005', filename='./temp/logging.py')


@pytest.mark.skipif(
sys.version_info < (3, 10),
reason='Skip A005, module testing is only supported in Python 3.10 and above',
)
def test_module_name_ignore_module():
source = ''
check_code(
source,
filename='./temp/logging.py',
builtins_allowed_modules=['logging'],
)


def test_module_name_not_builtin():
source = ''
check_code(source, filename='log_config')

0 comments on commit 99ef517

Please sign in to comment.