Reviewed-on: #1 Co-authored-by: Vishesh 'ironeagle' Bangotra <aetoskia@gmail.com> Co-committed-by: Vishesh 'ironeagle' Bangotra <aetoskia@gmail.com>
127 lines
2.6 KiB
Python
127 lines
2.6 KiB
Python
import sys
|
|
import json
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
from click.testing import CliRunner
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_package(tmp_path: Path):
|
|
"""
|
|
Creates a temporary Python package and adds it to sys.path.
|
|
"""
|
|
pkg = tmp_path / "testpkg"
|
|
pkg.mkdir()
|
|
(pkg / "__init__.py").write_text('"""Test package."""\n')
|
|
|
|
sys.path.insert(0, str(tmp_path))
|
|
yield pkg
|
|
sys.path.remove(str(tmp_path))
|
|
|
|
|
|
@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"]
|
|
|
|
@pytest.fixture
|
|
def fake_mcp_docs(tmp_path: Path) -> Path:
|
|
"""
|
|
Create a minimal valid MCP bundle in mcp_docs/.
|
|
"""
|
|
mcp_root = tmp_path / "mcp_docs"
|
|
modules_dir = mcp_root / "modules"
|
|
modules_dir.mkdir(parents=True)
|
|
|
|
(mcp_root / "index.json").write_text(
|
|
json.dumps({"project": "test", "type": "docforge-model"}),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
(mcp_root / "nav.json").write_text(
|
|
json.dumps([]),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
(modules_dir / "test.mod.json").write_text(
|
|
json.dumps({"module": "test.mod", "content": {}}),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
return mcp_root
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_mcp_server_run(monkeypatch):
|
|
"""
|
|
Mock MCPServer.run so no real server is started.
|
|
"""
|
|
called = {"value": False}
|
|
|
|
def fake_run(self, transport="streamable-http"):
|
|
called["value"] = True
|
|
|
|
monkeypatch.setattr(
|
|
"docforge.servers.MCPServer.run",
|
|
fake_run,
|
|
)
|
|
|
|
return lambda: called["value"]
|