Skip to content

Commit

Permalink
test: allow specifying name to the check_code helper
Browse files Browse the repository at this point in the history
+ update test_stdin to make use of the updated helper
  • Loading branch information
asfaltboy committed Feb 20, 2024
1 parent f57ff16 commit 5bd1537
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, ignore_list='', builtins=None):
self.builtins = builtins


def check_code(source, expected_codes=None, ignore_list=None, builtins=None):
def check_code(source, expected_codes=None, ignore_list=None, builtins=None, filename='/home/script.py'):
"""Check if the given source code generates the given flake8 errors
If `expected_codes` is a string is converted to a list,
Expand All @@ -37,7 +37,7 @@ def check_code(source, expected_codes=None, ignore_list=None, builtins=None):
if ignore_list is None:
ignore_list = []
tree = ast.parse(textwrap.dedent(source))
checker = BuiltinsChecker(tree, '/home/script.py')
checker = BuiltinsChecker(tree, filename)
checker.parse_options(FakeOptions(ignore_list=ignore_list, builtins=builtins))
return_statements = list(checker.run())

Expand Down Expand Up @@ -463,12 +463,11 @@ async def bla():
def test_stdin(stdin_get_value):
source = 'max = 4'
stdin_get_value.return_value = source
checker = BuiltinsChecker('', 'stdin')
checker.parse_options(FakeOptions())
ret = list(checker.run())
assert len(ret) == 1
check_code('', expected_codes='A001', filename='stdin')


def test_tuple_unpacking():
source = 'a, *(b, c) = 1, 2, 3'
check_code(source)


0 comments on commit 5bd1537

Please sign in to comment.