Skip to content

Commit 87d1e32

Browse files
committed
Add hot reloading test
1 parent 92bcf10 commit 87d1e32

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ dependencies = [
5050
optional-dependencies.docs = [
5151
]
5252
optional-dependencies.test = [
53+
"asgi-lifespan",
5354
"httpx",
55+
"httpx-ws",
5456
"pytest>=6",
5557
]
5658
urls.Changelog = "https://github.com/sphinx-doc/sphinx-autobuild/blob/main/NEWS.rst"

tests/test_application.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import shutil
44
from pathlib import Path
55

6-
from starlette.testclient import TestClient
6+
import anyio
7+
import httpx
8+
import pytest
9+
from asgi_lifespan import LifespanManager
10+
from httpx_ws import aconnect_ws
11+
from httpx_ws.transport import ASGIWebSocketTransport
712

813
from sphinx_autobuild.__main__ import _create_app
914
from sphinx_autobuild.build import Builder
@@ -12,21 +17,39 @@
1217
ROOT = Path(__file__).parent.parent
1318

1419

15-
def test_application(tmp_path):
20+
@pytest.fixture
21+
def anyio_backend():
22+
return "asyncio"
23+
24+
25+
async def test_application(tmp_path, anyio_backend): # noqa: ARG001
1626
src_dir = tmp_path / "docs"
1727
out_dir = tmp_path / "build"
1828
shutil.copytree(ROOT / "docs", tmp_path / "docs")
1929
out_dir.mkdir(parents=True, exist_ok=True)
30+
index_file = anyio.Path(src_dir / "index.rst")
31+
await index_file.write_text("hello")
2032

2133
url_host = "127.0.0.1:7777"
2234
ignore_handler = IgnoreFilter([out_dir], [])
2335
builder = Builder(
2436
[str(src_dir), str(out_dir)], url_host=url_host, pre_build_commands=[]
2537
)
2638
app = _create_app([src_dir], ignore_handler, builder, out_dir, url_host)
27-
client = TestClient(app)
2839

29-
builder(changed_paths=())
40+
async with (
41+
LifespanManager(app) as manager,
42+
httpx.AsyncClient(
43+
transport=ASGIWebSocketTransport(manager.app), base_url="http://testserver"
44+
) as client,
45+
):
46+
builder(changed_paths=())
47+
48+
response = await client.get("/")
49+
assert response.status_code == 200
50+
51+
async with aconnect_ws("/websocket-reload", client) as websocket:
52+
await index_file.write_text("world")
3053

31-
response = client.get("/")
32-
assert response.status_code == 200
54+
data = await websocket.receive_text()
55+
assert data == "refresh"

0 commit comments

Comments
 (0)