added cli
This commit is contained in:
0
tests/cli/__init__.py
Normal file
0
tests/cli/__init__.py
Normal file
67
tests/cli/conftest.py
Normal file
67
tests/cli/conftest.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cli_runner() -> CliRunner:
|
||||
"""Click CLI runner."""
|
||||
return CliRunner()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_mkdocs_yml(tmp_path: Path) -> Path:
|
||||
"""Create a minimal mkdocs.yml file."""
|
||||
yml = tmp_path / "mkdocs.yml"
|
||||
yml.write_text(
|
||||
"""
|
||||
site_name: Test Docs
|
||||
nav: []
|
||||
plugins:
|
||||
- mkdocstrings
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return yml
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_mkdocs_load_config(monkeypatch):
|
||||
"""Mock mkdocs.config.load_config."""
|
||||
def fake_load_config(path):
|
||||
return object() # dummy config object
|
||||
|
||||
monkeypatch.setattr(
|
||||
"mkdocs.config.load_config",
|
||||
fake_load_config,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_mkdocs_build(monkeypatch):
|
||||
called = {"value": False}
|
||||
|
||||
def fake_build(config):
|
||||
called["value"] = True
|
||||
|
||||
monkeypatch.setattr(
|
||||
"mkdocs.commands.build.build",
|
||||
fake_build,
|
||||
)
|
||||
return lambda: called["value"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_mkdocs_serve(monkeypatch):
|
||||
called = {"value": False}
|
||||
|
||||
def fake_serve(*args, **kwargs):
|
||||
called["value"] = True
|
||||
|
||||
monkeypatch.setattr(
|
||||
"mkdocs.commands.serve.serve",
|
||||
fake_serve,
|
||||
)
|
||||
return lambda: called["value"]
|
||||
20
tests/cli/test_build.py
Normal file
20
tests/cli/test_build.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from docforge.cli.main import cli
|
||||
|
||||
|
||||
def test_build_command(
|
||||
cli_runner,
|
||||
fake_mkdocs_yml,
|
||||
mock_mkdocs_load_config,
|
||||
mock_mkdocs_build,
|
||||
):
|
||||
result = cli_runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"build",
|
||||
"--mkdocs-yml",
|
||||
str(fake_mkdocs_yml),
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert mock_mkdocs_build() is True
|
||||
32
tests/cli/test_generate.py
Normal file
32
tests/cli/test_generate.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from pathlib import Path
|
||||
|
||||
from docforge.cli.main import cli
|
||||
|
||||
|
||||
def test_generate_command(cli_runner, temp_package, tmp_path: Path):
|
||||
(temp_package / "mod.py").write_text(
|
||||
'''
|
||||
def f(): ...
|
||||
'''
|
||||
)
|
||||
|
||||
docs_dir = tmp_path / "docs"
|
||||
|
||||
result = cli_runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"generate",
|
||||
"--modules",
|
||||
"testpkg.mod",
|
||||
"--docs-dir",
|
||||
str(docs_dir),
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
|
||||
md = docs_dir / "testpkg" / "mod.md"
|
||||
assert md.exists()
|
||||
|
||||
content = md.read_text()
|
||||
assert "::: testpkg.mod" in content
|
||||
19
tests/cli/test_serve.py
Normal file
19
tests/cli/test_serve.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from docforge.cli.main import cli
|
||||
|
||||
|
||||
def test_serve_command(
|
||||
cli_runner,
|
||||
fake_mkdocs_yml,
|
||||
mock_mkdocs_serve,
|
||||
):
|
||||
result = cli_runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"serve",
|
||||
"--mkdocs-yml",
|
||||
str(fake_mkdocs_yml),
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert mock_mkdocs_serve() is True
|
||||
24
tests/cli/test_tree.py
Normal file
24
tests/cli/test_tree.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from docforge.cli.main import cli
|
||||
|
||||
|
||||
def test_tree_command(cli_runner, temp_package):
|
||||
(temp_package / "mod.py").write_text(
|
||||
'''
|
||||
class A:
|
||||
def f(self): ...
|
||||
'''
|
||||
)
|
||||
|
||||
result = cli_runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"tree",
|
||||
"--modules",
|
||||
"testpkg.mod",
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "testpkg" in result.output
|
||||
assert "mod" in result.output
|
||||
assert "A" in result.output
|
||||
Reference in New Issue
Block a user