Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions backend/tests/test_ast_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def test_mutable_default_set():
issues = _types("def f(x=set()): pass\ndef g(y={1, 2}): pass")
assert "Mutable Default Argument" in issues

def test_mutable_keyword_only_default_detected():
issues = _types("def f(*, options={}): pass")
assert "Mutable Default Argument" in issues

def test_no_mutable_default_with_none():
issues = _types("def f(x=None): pass")
assert "Mutable Default Argument" not in issues
Expand Down Expand Up @@ -104,6 +108,10 @@ def test_unreachable_after_raise():
code = "def f():\n raise ValueError()\n x = 1"
assert "Unreachable Code" in _types(code)

def test_unreachable_in_async_function_detected():
code = "async def f():\n return 1\n await other()"
assert "Unreachable Code" in _types(code)

def test_reachable_code_not_flagged():
code = "def f():\n x = 1\n return x"
assert "Unreachable Code" not in _types(code)
Expand Down Expand Up @@ -192,6 +200,16 @@ def test_used_alias_not_flagged():
issues = analyze(code)
assert not any(i["type"] == "Unused Import" for i in issues)

def test_used_from_import_alias_not_flagged():
code = "from pathlib import Path as P\nroot = P('.')\n"
issues = analyze(code)
assert not any(i["type"] == "Unused Import" for i in issues)

def test_star_import_not_flagged_as_unused_import():
code = "from math import *\nvalue = sqrt(4)\n"
issues = analyze(code)
assert not any(i["type"] == "Unused Import" for i in issues)

def test_too_many_returns_exact_boundary():
# 3 returns = should NOT flag
code = "def f(x):\n if x==1: return 1\n if x==2: return 2\n return 3\n"
Expand Down