This commit is contained in:
130
.tests/integration/test_full_workflow.py
Normal file
130
.tests/integration/test_full_workflow.py
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
"""Integration tests for complete workflow."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from click.testing import CliRunner
|
||||||
|
from code_doc_cli.cli.main import cli
|
||||||
|
|
||||||
|
|
||||||
|
class TestFullWorkflow:
|
||||||
|
"""Integration tests for the complete documentation workflow."""
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def runner(self):
|
||||||
|
return CliRunner()
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def python_project(self, tmp_path):
|
||||||
|
"""Create a Python project for testing."""
|
||||||
|
project_dir = tmp_path / "python_project"
|
||||||
|
project_dir.mkdir()
|
||||||
|
|
||||||
|
main_py = project_dir / "main.py"
|
||||||
|
main_py.write_text('''
|
||||||
|
"""Main module of the application."""
|
||||||
|
|
||||||
|
def process_items(items):
|
||||||
|
"""Process a list of items.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
items: Input items to process
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Processed items
|
||||||
|
"""
|
||||||
|
return [item.strip() for item in items]
|
||||||
|
''')
|
||||||
|
|
||||||
|
utils_py = project_dir / "utils.py"
|
||||||
|
utils_py.write_text('''
|
||||||
|
"""Utility functions module."""
|
||||||
|
|
||||||
|
def validate_input(value):
|
||||||
|
"""Validate input value.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value: Value to validate
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if valid
|
||||||
|
"""
|
||||||
|
return len(value) > 0
|
||||||
|
''')
|
||||||
|
|
||||||
|
return project_dir
|
||||||
|
|
||||||
|
def test_python_only_project(self, runner, python_project):
|
||||||
|
"""Test processing a Python-only project."""
|
||||||
|
with runner.isolated_filesystem():
|
||||||
|
shutil.copytree(str(python_project), "project", dirs_exist_ok=True)
|
||||||
|
result = runner.invoke(cli, ["generate", "project"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
output = result.output
|
||||||
|
assert "process_items" in output
|
||||||
|
assert "validate_input" in output
|
||||||
|
|
||||||
|
def test_module_docstring_extraction(self, runner, python_project):
|
||||||
|
"""Test module-level docstring extraction."""
|
||||||
|
with runner.isolated_filesystem():
|
||||||
|
shutil.copytree(str(python_project), "project", dirs_exist_ok=True)
|
||||||
|
result = runner.invoke(cli, ["generate", "project"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "Main module" in result.output or "Utility" in result.output
|
||||||
|
|
||||||
|
def test_return_type_documentation(self, runner, python_project):
|
||||||
|
"""Test return type documentation extraction."""
|
||||||
|
with runner.isolated_filesystem():
|
||||||
|
shutil.copytree(str(python_project), "project", dirs_exist_ok=True)
|
||||||
|
result = runner.invoke(cli, ["generate", "project"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "Returns:" in result.output
|
||||||
|
|
||||||
|
|
||||||
|
class TestCICDIntegration:
|
||||||
|
"""Tests for CI/CD integration features."""
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def runner(self):
|
||||||
|
return CliRunner()
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_project(self, tmp_path):
|
||||||
|
"""Create a sample project for CI/CD testing."""
|
||||||
|
project_dir = tmp_path / "ci_project"
|
||||||
|
project_dir.mkdir()
|
||||||
|
|
||||||
|
file_py = project_dir / "example.py"
|
||||||
|
file_py.write_text('''
|
||||||
|
"""Example module for CI/CD testing."""
|
||||||
|
|
||||||
|
def hello(name):
|
||||||
|
"""Say hello to someone.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: Person's name
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Greeting message
|
||||||
|
"""
|
||||||
|
return f"Hello, {name}!"
|
||||||
|
''')
|
||||||
|
|
||||||
|
return project_dir
|
||||||
|
|
||||||
|
def test_exit_code_success(self, runner, sample_project):
|
||||||
|
"""Test exit code on success."""
|
||||||
|
with runner.isolated_filesystem():
|
||||||
|
shutil.copytree(str(sample_project), "project", dirs_exist_ok=True)
|
||||||
|
result = runner.invoke(cli, ["generate", "project"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
def test_exit_code_no_files(self, runner, tmp_path):
|
||||||
|
"""Test exit code when no files found."""
|
||||||
|
empty_dir = tmp_path / "empty"
|
||||||
|
empty_dir.mkdir()
|
||||||
|
|
||||||
|
with runner.isolated_filesystem():
|
||||||
|
result = runner.invoke(cli, ["generate", str(empty_dir)])
|
||||||
|
assert result.exit_code == 1
|
||||||
Reference in New Issue
Block a user