changeset 8:25538e3ee531

rename
author drewp@bigasterisk.com
date Sat, 16 Mar 2024 12:51:39 -0700
parents d98cb018fad7
children b72f4ba1345d
files examples/_run_server_child.py examples/empty_server_test.py examples/run_server_make_request.py examples/serve_custom_root_page_test.py
diffstat 4 files changed, 32 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/_run_server_child.py	Sat Mar 16 12:51:39 2024 -0700
@@ -0,0 +1,28 @@
+import asyncio
+from dataclasses import dataclass
+from pathlib import Path
+
+import aiohttp
+
+
+@dataclass
+class RunHttpServerChildProcess:
+    server_path: Path
+
+    async def __aenter__(self):
+        self.subprocess = await asyncio.create_subprocess_exec(
+            'pdm', 'run', 'python', self.server_path)
+        self._session = await aiohttp.ClientSession().__aenter__()
+        return self
+
+    async def __aexit__(self, exc_type, exc, tb):
+        await self._session.close()
+        self.subprocess.terminate()
+        await self.subprocess.wait()
+
+    async def get(self, url: str) -> aiohttp.ClientResponse:
+        while True:
+            try:
+                return await self._session.get(url)
+            except aiohttp.ClientConnectorError:
+                await asyncio.sleep(0.05)
--- a/examples/empty_server_test.py	Sat Mar 16 12:36:13 2024 -0700
+++ b/examples/empty_server_test.py	Sat Mar 16 12:51:39 2024 -0700
@@ -2,11 +2,11 @@
 
 import pytest
 
-from examples.run_server_make_request import HttpServer
+from examples._run_server_child import RunHttpServerChildProcess
 
 
 @pytest.mark.asyncio
 async def test_http_request_to_subprocess():
-    async with HttpServer(Path('examples/empty_server.py')) as http_server:
+    async with RunHttpServerChildProcess(Path('examples/empty_server.py')) as http_server:
         response = await http_server.get('http://localhost:8005/')
         assert response.status == 200
--- a/examples/run_server_make_request.py	Sat Mar 16 12:36:13 2024 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-import asyncio
-from dataclasses import dataclass
-from pathlib import Path
-
-import aiohttp
-
-
-@dataclass
-class HttpServer:
-    server_path: Path
-
-    async def __aenter__(self):
-        self.subprocess = await asyncio.create_subprocess_exec(
-            'pdm', 'run', 'python', self.server_path)
-        self._session = await aiohttp.ClientSession().__aenter__()
-        return self
-
-    async def __aexit__(self, exc_type, exc, tb):
-        await self._session.close()
-        self.subprocess.terminate()
-        await self.subprocess.wait()
-
-    async def get(self, url: str) -> aiohttp.ClientResponse:
-        while True:
-            try:
-                return await self._session.get(url)
-            except aiohttp.ClientConnectorError:
-                await asyncio.sleep(0.05)
--- a/examples/serve_custom_root_page_test.py	Sat Mar 16 12:36:13 2024 -0700
+++ b/examples/serve_custom_root_page_test.py	Sat Mar 16 12:51:39 2024 -0700
@@ -2,12 +2,12 @@
 
 import pytest
 
-from examples.run_server_make_request import HttpServer
+from examples._run_server_child import RunHttpServerChildProcess
 
 
 @pytest.mark.asyncio
 async def test_http_request_to_subprocess():
-    async with HttpServer(
+    async with RunHttpServerChildProcess(
             Path('examples/serve_custom_root_page.py')) as http_server:
         response = await http_server.get('http://localhost:8005/')
         assert (await response.text()) == 'hello world'