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
This commit is contained in:
60
tests/unit/test_cli.py
Normal file
60
tests/unit/test_cli.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user