Download tests/test_mcp_server.py from smlflg/PromptGarage: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/smlflg/PromptGarage/resolve/main/tests/test_mcp_server.py
- Command line
-
hf download hf://smlflg/PromptGarage/tests/test_mcp_server.py
-
curl -L -o test_mcp_server.py https://huggingface.co/smlflg/PromptGarage/resolve/main/tests/test_mcp_server.py
1.75 kB
| import asyncio | |
| import pytest | |
| import sys | |
| import os | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from mcp_server import search, show, use, random_prompt, stats | |
| from db import add_prompt, init_db | |
| # Tests use the conftest.py temp_db fixture (autouse) | |
| def test_search_finds_prompt(): | |
| add_prompt(title="Python refactor helper", content="Help me refactor this Python code", tags="python,refactor") | |
| result = asyncio.run(search("python refactor")) | |
| assert "#" in result | |
| assert "Python refactor" in result | |
| def test_search_no_match(): | |
| result = asyncio.run(search("nonexistent_xyz")) | |
| assert "No matches" in result | |
| def test_search_compact_max_5(): | |
| for i in range(10): | |
| add_prompt(title=f"Test prompt {i}", content=f"Content about testing {i}", tags="test") | |
| result = asyncio.run(search("testing")) | |
| lines = [l for l in result.strip().split("\n") if l.strip()] | |
| assert len(lines) <= 5 | |
| def test_show_full_content(): | |
| pid = add_prompt(title="My prompt", content="Full content here", tags="demo") | |
| result = asyncio.run(show(pid)) | |
| assert "Full content here" in result | |
| assert "My prompt" in result | |
| def test_show_not_found(): | |
| result = asyncio.run(show(99999)) | |
| assert "not found" in result | |
| def test_use_increments(): | |
| pid = add_prompt(title="Use me", content="Use this prompt") | |
| result = asyncio.run(use(pid)) | |
| assert "use_count: 1" in result | |
| def test_random_returns_prompt(): | |
| add_prompt(title="Random test", content="Random content") | |
| result = asyncio.run(random_prompt()) | |
| assert "#" in result | |
| def test_stats_compact(): | |
| add_prompt(title="Stats test", content="Content") | |
| result = asyncio.run(stats()) | |
| assert "Total:" in result | |