Skip to content

Commit e56de71

Browse files
committed
Add tests for is_dunder_function.
1 parent 86e5c81 commit e56de71

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test_unused_arguments.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,30 @@ def test_function_finder(only_top_level, expected):
446446
assert names == expected
447447

448448

449+
@pytest.mark.parametrize(
450+
"code, expected_value",
451+
[
452+
("def foo(): pass", False),
453+
("def __foo(): pass", False),
454+
("def foo__(): pass", False),
455+
("def __foo__(): pass", True),
456+
("async def foo(): pass", False),
457+
("async def __foo(): pass", False),
458+
("async def foo__(): pass", False),
459+
("async def __foo__(): pass", True),
460+
("lambda: None", False),
461+
]
462+
)
463+
def test_is_dunder_method(code, expected_value):
464+
from flake8_unused_arguments import is_dunder_method
465+
func = ast.parse(textwrap.dedent(code)).body[0]
466+
467+
if isinstance(func, ast.Expr):
468+
func = func.value
469+
470+
assert is_dunder_method(func) == expected_value
471+
472+
449473
def get_most_recent_tag() -> str:
450474
return (
451475
re.sub("^v", "", subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"], text=True)

0 commit comments

Comments
 (0)