82
.tests/unit/test_cli.py
Normal file
82
.tests/unit/test_cli.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""Unit tests for CLI interface."""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from click.testing import CliRunner
|
||||
from code_doc_cli.cli.main import cli, ExitCode
|
||||
|
||||
|
||||
class TestCLI:
|
||||
"""Tests for CLI commands."""
|
||||
|
||||
@pytest.fixture
|
||||
def runner(self):
|
||||
return CliRunner()
|
||||
|
||||
def test_version_command(self, runner):
|
||||
"""Test version command."""
|
||||
result = runner.invoke(cli, ["version"])
|
||||
assert result.exit_code == 0
|
||||
assert "version" in result.output.lower()
|
||||
|
||||
def test_languages_command(self, runner):
|
||||
"""Test languages command."""
|
||||
result = runner.invoke(cli, ["languages"])
|
||||
assert result.exit_code == 0
|
||||
assert "python" in result.output
|
||||
assert "typescript" in result.output
|
||||
assert "go" in result.output
|
||||
|
||||
def test_init_command(self, runner):
|
||||
"""Test init command."""
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(cli, ["init"], input="y\n")
|
||||
assert result.exit_code == 0
|
||||
assert "code-doc.toml" in result.output
|
||||
|
||||
def test_generate_no_files_error(self, runner):
|
||||
"""Test generate with no files."""
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(cli, ["generate"])
|
||||
assert result.exit_code == ExitCode.NO_FILES
|
||||
assert "No source files" in result.output
|
||||
|
||||
def test_generate_python_file(self, runner):
|
||||
"""Test generate with Python file."""
|
||||
with runner.isolated_filesystem():
|
||||
with open("test.py", "w") as f:
|
||||
f.write('''
|
||||
def add(a: int, b: int) -> int:
|
||||
"""Add two numbers."""
|
||||
return a + b
|
||||
''')
|
||||
result = runner.invoke(cli, ["generate", "test.py"])
|
||||
assert result.exit_code == 0
|
||||
assert "API Documentation" in result.output
|
||||
assert "add" in result.output
|
||||
|
||||
|
||||
class TestExitCodes:
|
||||
"""Tests for exit codes."""
|
||||
|
||||
@pytest.fixture
|
||||
def runner(self):
|
||||
return CliRunner()
|
||||
|
||||
def test_success_exit_code(self, runner):
|
||||
"""Test successful execution returns 0."""
|
||||
with runner.isolated_filesystem():
|
||||
with open("test.py", "w") as f:
|
||||
f.write('''
|
||||
def add(a: int, b: int) -> int:
|
||||
"""Add two numbers."""
|
||||
return a + b
|
||||
''')
|
||||
result = runner.invoke(cli, ["generate", "test.py"])
|
||||
assert result.exit_code == ExitCode.SUCCESS
|
||||
|
||||
def test_no_files_exit_code(self, runner):
|
||||
"""Test no files found returns 1."""
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(cli, ["generate"])
|
||||
assert result.exit_code == ExitCode.NO_FILES
|
||||
Reference in New Issue
Block a user