Files
shell-speak/tests/unit/test_cli.py
Auto User 95459fb4c8 fix: resolve CI test failure in output.py
- Fixed undefined 'tool' variable in display_history function
- Changed '[tool]' markup tag usage to proper Rich syntax
- All tests now pass (38/38 unit tests)
- Type checking passes with mypy --strict
2026-01-31 06:22:27 +00:00

61 lines
2.1 KiB
Python

"""Unit tests for CLI module."""
import os
import tempfile
from click.testing import CliRunner
from codesnap.__main__ import main
class TestCLI:
"""Tests for CLI commands."""
def setup_method(self) -> None:
self.runner = CliRunner()
def test_main_help(self) -> None:
result = self.runner.invoke(main, ["--help"])
assert result.exit_code == 0
assert "CodeSnap" in result.output
def test_cli_version(self) -> None:
result = self.runner.invoke(main, ["--version"])
assert result.exit_code == 0
assert "0.1.0" in result.output
def test_cli_analyze_nonexistent_path(self) -> None:
result = self.runner.invoke(main, ["analyze", "/nonexistent/path"])
assert result.exit_code != 0
def test_cli_analyze_current_directory(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
with open(os.path.join(tmpdir, "test.py"), "w") as f:
f.write("def test(): pass\n")
result = self.runner.invoke(main, ["analyze", tmpdir])
assert result.exit_code == 0
def test_cli_analyze_with_output_format(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
with open(os.path.join(tmpdir, "test.py"), "w") as f:
f.write("def test(): pass\n")
result = self.runner.invoke(main, ["analyze", tmpdir, "--format", "json"])
assert result.exit_code == 0
def test_cli_analyze_with_max_files(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
with open(os.path.join(tmpdir, "test.py"), "w") as f:
f.write("def test(): pass\n")
result = self.runner.invoke(main, ["analyze", tmpdir, "--max-files", "10"])
assert result.exit_code == 0
def test_cli_languages(self) -> None:
result = self.runner.invoke(main, ["languages"])
assert result.exit_code == 0
assert "python" in result.output.lower()
def test_cli_info_languages(self) -> None:
result = self.runner.invoke(main, ["info", "--languages"])
assert result.exit_code == 0
assert "python" in result.output.lower()