"""Test configuration and fixtures for MkDocs MCP server."""
import tempfile
from pathlib import Path
from typing import Generator
import pytest
import pytest_asyncio
@pytest.fixture
def temp_docs_dir() -> Generator[Path, None, None]:
"""Create a temporary documentation directory for testing."""
with tempfile.TemporaryDirectory() as tmpdir:
docs_path = Path(tmpdir)
# Create sample documentation files
(docs_path / "index.md").write_text("""---
title: Home Page
description: Welcome to our documentation
---
# Home Page
This is the home page of our documentation.
## Getting Started
Welcome to our project! This documentation will help you get started.
### Prerequisites
You'll need:
- Python 3.11+
- Basic knowledge of MCP
```python
print("Hello, world!")
```
## Next Steps
Continue to the [Installation Guide](getting-started/installation.md).
""")
# Create subdirectory
getting_started_dir = docs_path / "getting-started"
getting_started_dir.mkdir()
(getting_started_dir / "installation.md").write_text("""---
title: Installation Guide
description: How to install the software
tags: [setup, installation]
---
# Installation
Follow these steps to install the software:
## Step 1: Prerequisites
Make sure you have Python installed:
```bash
python --version
```
## Step 2: Install
Install using pip:
```python
import subprocess
subprocess.run(["pip", "install", "our-package"])
```
## Troubleshooting
If you encounter issues, check our FAQ.
""")
(getting_started_dir / "configuration.md").write_text("""# Configuration
Configure your application using these options:
## Basic Configuration
```yaml
server:
host: localhost
port: 8000
```
## Advanced Settings
For production use, consider these options:
```javascript
const config = {
production: true,
debug: false
};
```
""")
# Create API directory
api_dir = docs_path / "api"
api_dir.mkdir()
(api_dir / "reference.md").write_text("""---
title: API Reference
description: Complete API documentation
---
# API Reference
## Classes
### DocumentationServer
Main server class for handling requests.
## Functions
### search_docs(query)
Search documentation content.
```python
def search_docs(query: str) -> List[str]:
\"\"\"Search for content matching the query.\"\"\"
return results
```
""")
yield docs_path
@pytest_asyncio.fixture
async def sample_docs_dir() -> Path:
"""Async fixture for sample docs directory."""
with tempfile.TemporaryDirectory() as tmpdir:
docs_path = Path(tmpdir)
# Create a simple test file
test_file = docs_path / "test.md"
test_file.write_text("""# Test Page
This is a test page for unit testing.
```python
def test_function():
return True
```
""")
yield docs_path
@pytest.fixture
def sample_markdown_content() -> str:
"""Sample markdown content for testing."""
return """---
title: Sample Page
description: A sample page for testing
tags: [test, sample]
---
# Sample Page
This is a sample page with various elements.
## Code Example
```python
def hello_world():
print("Hello, world!")
return "success"
```
## Another Section
More content here with some **bold** and *italic* text.
### Subsection
Even more nested content.
```bash
echo "Another code block"
ls -la
```
"""
@pytest.fixture
def empty_docs_dir() -> Generator[Path, None, None]:
"""Create an empty documentation directory for testing."""
with tempfile.TemporaryDirectory() as tmpdir:
yield Path(tmpdir)