Skip to content

Commit 0fe4cf3

Browse files
Create test_generator.py
1 parent fba1b71 commit 0fe4cf3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

tests/test_generator.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""Tests for the Sphinx documentation generator."""
2+
3+
import os
4+
import pytest
5+
from vyper_sphinx_docs.generator import SphinxGenerator
6+
from vyper_sphinx_docs.parser import VyperParser
7+
8+
9+
def test_sphinx_generation(contracts_dir, output_dir):
10+
"""Test complete Sphinx documentation generation."""
11+
# Parse contracts
12+
parser = VyperParser(str(contracts_dir))
13+
contracts = parser.parse_contracts()
14+
15+
# Generate documentation
16+
generator = SphinxGenerator(str(output_dir))
17+
generator.generate(contracts)
18+
19+
# Check generated files
20+
docs_dir = output_dir / "docs"
21+
assert docs_dir.exists()
22+
23+
# Check conf.py
24+
conf_py = docs_dir / "conf.py"
25+
assert conf_py.exists()
26+
conf_content = conf_py.read_text()
27+
assert "sphinx.ext.autodoc" in conf_content
28+
assert "sphinx_rtd_theme" in conf_content
29+
30+
# Check index.rst
31+
index_rst = docs_dir / "index.rst"
32+
assert index_rst.exists()
33+
index_content = index_rst.read_text()
34+
assert "Vyper Smart Contracts Documentation" in index_content
35+
assert "token" in index_content
36+
assert "nested_token" in index_content
37+
38+
# Check contract documentation
39+
token_rst = docs_dir / "token.rst"
40+
assert token_rst.exists()
41+
token_content = token_rst.read_text()
42+
assert "ERC20 Token Implementation" in token_content
43+
assert "transfer" in token_content
44+
assert "balance_of" in token_content
45+
46+
47+
def test_contract_rst_generation(contracts_dir, output_dir):
48+
"""Test detailed RST file generation for contracts."""
49+
parser = VyperParser(str(contracts_dir))
50+
contracts = parser.parse_contracts()
51+
52+
generator = SphinxGenerator(str(output_dir))
53+
generator.generate(contracts)
54+
55+
# Check token.rst content
56+
token_rst = output_dir / "docs" / "token.rst"
57+
content = token_rst.read_text()
58+
59+
# Check sections
60+
assert "token" in content
61+
assert "Functions" in content
62+
63+
# Check function documentation
64+
assert ".. py:function:: transfer" in content
65+
assert "to: address" in content
66+
assert "amount: uint256" in content
67+
assert "-> bool" in content
68+
69+
assert ".. py:function:: balance_of" in content
70+
assert "account: address" in content
71+
assert "-> uint256" in content
72+
73+
# Check docstrings
74+
assert "Transfer tokens to a specified address" in content
75+
assert "Get the token balance of an account" in content

0 commit comments

Comments
 (0)