Files
shell-speak/tests/integration/test_all_formats.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

142 lines
4.1 KiB
Python

"""Integration tests for all output formats."""
import tempfile
from pathlib import Path
from doc2man.parsers.python import parse_python_file
from doc2man.generators.man import generate_man_page
from doc2man.generators.markdown import generate_markdown
from doc2man.generators.html import generate_html
class TestAllFormatsIntegration:
"""Integration tests for all output formats."""
def test_man_format(self):
"""Test man page format output."""
source = '''
def command(input_file, output_file=None):
"""Process a file and output the result.
Args:
input_file: Path to input file.
output_file: Optional path to output file.
Returns:
Processed data.
"""
return "processed"
'''
with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as f:
f.write(source.encode())
f.flush()
parsed = parse_python_file(Path(f.name))
with tempfile.NamedTemporaryFile(suffix=".1", delete=False) as out:
result = generate_man_page([{"file": f.name, "data": parsed}], Path(out.name))
assert ".TH" in result
assert "NAME" in result
assert "DESCRIPTION" in result
Path(out.name).unlink()
Path(f.name).unlink()
def test_markdown_format(self):
"""Test markdown format output."""
source = '''
def api(endpoint, method="GET"):
"""Make an API request.
Args:
endpoint: The API endpoint URL.
method: HTTP method to use.
Returns:
Response JSON data.
"""
return {"status": "ok"}
'''
with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as f:
f.write(source.encode())
f.flush()
parsed = parse_python_file(Path(f.name))
with tempfile.NamedTemporaryFile(suffix=".md", delete=False) as out:
result = generate_markdown([{"file": f.name, "data": parsed}], Path(out.name))
assert "#" in result
assert "## Functions" in result or "#" in result
Path(out.name).unlink()
Path(f.name).unlink()
def test_html_format(self):
"""Test HTML format output."""
source = '''
class DataProcessor:
"""Process data efficiently."""
def process(self, data):
"""Process the given data.
Args:
data: Input data to process.
Returns:
Processed result.
"""
return data.upper()
'''
with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as f:
f.write(source.encode())
f.flush()
parsed = parse_python_file(Path(f.name))
with tempfile.NamedTemporaryFile(suffix=".html", delete=False) as out:
result = generate_html([{"file": f.name, "data": parsed}], Path(out.name))
assert "<!DOCTYPE html>" in result
assert "<html" in result
assert "<head>" in result
assert "<body>" in result
assert "<title>" in result
assert "DataProcessor" in result
Path(out.name).unlink()
Path(f.name).unlink()
def test_all_formats_same_data(self):
"""Test that all formats produce consistent output from same data."""
source = '''
def consistent(name):
"""A function with consistent docs.
Args:
name: A name parameter.
Returns:
A greeting.
"""
return f"Hello {name}"
'''
with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as f:
f.write(source.encode())
f.flush()
parsed = parse_python_file(Path(f.name))
parsed_data = [{"file": f.name, "data": parsed}]
man_result = generate_man_page(parsed_data, None)
md_result = generate_markdown(parsed_data, None)
html_result = generate_html(parsed_data, None)
assert "consistent" in man_result.lower()
assert "consistent" in md_result.lower()
assert "consistent" in html_result.lower()
Path(f.name).unlink()