This commit is contained in:
38
tests/test_generator.py
Normal file
38
tests/test_generator.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import pytest
|
||||
from src.core.generator import generate_docs
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_generate_html(tmp_path, sample_spec):
|
||||
output = tmp_path / "test.html"
|
||||
generate_docs(str(sample_spec), str(output), 'html')
|
||||
assert output.exists()
|
||||
html = output.read_text()
|
||||
assert '<html>' in html
|
||||
assert 'API Documentation' in html
|
||||
|
||||
|
||||
def test_generate_markdown(tmp_path, sample_spec):
|
||||
output = tmp_path / "test.md"
|
||||
generate_docs(str(sample_spec), str(output), 'markdown')
|
||||
assert output.exists()
|
||||
md = output.read_text()
|
||||
assert '# API Documentation' in md
|
||||
|
||||
|
||||
def test_generate_json(tmp_path, sample_spec):
|
||||
output = tmp_path / "test.json"
|
||||
generate_docs(str(sample_spec), str(output), 'json')
|
||||
assert output.exists()
|
||||
import json
|
||||
data = json.loads(output.read_text())
|
||||
assert 'title' in data
|
||||
assert 'endpoints' in data
|
||||
|
||||
|
||||
def test_invalid_spec(tmp_path):
|
||||
invalid_spec = tmp_path / "invalid.json"
|
||||
invalid_spec.write_text('{"invalid": "spec"}')
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
generate_docs(str(invalid_spec), 'html')
|
||||
Reference in New Issue
Block a user