Skip to content
Merged
Show file tree
Hide file tree
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
47 changes: 35 additions & 12 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,26 +873,49 @@ def test_command_count_does_not_crash(self):
assert "conflicting option string" not in result.stderr

def test_scan_with_format_long_does_not_crash(self):
"""``codelens scan . --format json`` must not raise argparse error."""
"""``codelens scan <ws> --format json`` must not raise argparse error.

Uses a tiny throwaway workspace (not ``.``) so the scan finishes
fast — this test only verifies the ``--format`` argparse path, it
does not need to scan a real codebase.
"""
import subprocess
result = subprocess.run(
[sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"),
"scan", ".", "--format", "json"],
capture_output=True, text=True, timeout=60,
)
import shutil
ws = tempfile.mkdtemp()
try:
with open(os.path.join(ws, "trivial.py"), "w") as f:
f.write("x = 1\n")
result = subprocess.run(
[sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"),
"scan", ws, "--format", "json"],
capture_output=True, text=True, timeout=60,
)
finally:
shutil.rmtree(ws, ignore_errors=True)
assert "argparse.ArgumentError" not in result.stderr, (
f"argparse error:\n{result.stderr[:500]}"
)
assert "conflicting option string" not in result.stderr

def test_scan_with_format_short_does_not_crash(self):
"""``codelens scan . -f json`` must not raise argparse error."""
"""``codelens scan <ws> -f json`` must not raise argparse error.

Uses a tiny throwaway workspace (not ``.``) so the scan finishes
fast — this test only verifies the ``-f`` argparse path.
"""
import subprocess
result = subprocess.run(
[sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"),
"scan", ".", "-f", "json"],
capture_output=True, text=True, timeout=60,
)
import shutil
ws = tempfile.mkdtemp()
try:
with open(os.path.join(ws, "trivial.py"), "w") as f:
f.write("x = 1\n")
result = subprocess.run(
[sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"),
"scan", ws, "-f", "json"],
capture_output=True, text=True, timeout=60,
)
finally:
shutil.rmtree(ws, ignore_errors=True)
assert "argparse.ArgumentError" not in result.stderr, (
f"argparse error:\n{result.stderr[:500]}"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_hybrid_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ def test_deep_unsupported_command_sets_hint(self):
# is the post-#199 entry point. search is NOT in the --deep
# supported list.
proc = subprocess.run(
[sys.executable, "scripts/codelens.py",
[sys.executable, os.path.join(SCRIPT_DIR, "codelens.py"),
"search", "--mode", "symbol", "foo", ws, "--deep", "--format", "json"],
capture_output=True, text=True, timeout=60,
env={**os.environ, "PYTHONPATH": "scripts"},
env={**os.environ, "PYTHONPATH": SCRIPT_DIR},
)

# Should not crash, and should include the hint
Expand Down
Loading