-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated test suite in the first tutorial and removed redundant snippet
- Loading branch information
Showing
3 changed files
with
18 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
# isort: off | ||
import pytest | ||
from __future__ import annotations | ||
|
||
from asphalt.core import Context | ||
from pytest import CaptureFixture | ||
from collections.abc import AsyncGenerator | ||
|
||
import pytest | ||
from anyio import wait_all_tasks_blocked | ||
from echo.client import ClientComponent | ||
from echo.server import ServerComponent | ||
from pytest import CaptureFixture | ||
|
||
from asphalt.core import Context | ||
|
||
pytestmark = pytest.mark.anyio | ||
|
||
|
||
async def test_client_and_server(capsys: CaptureFixture[str]) -> None: | ||
@pytest.fixture | ||
async def server(capsys: CaptureFixture[str]) -> AsyncGenerator[None, None]: | ||
async with Context(): | ||
server = ServerComponent() | ||
await server.start() | ||
yield | ||
|
||
|
||
async def test_client_and_server(server: None, capsys: CaptureFixture[str]) -> None: | ||
async with Context(): | ||
client = ClientComponent("Hello!") | ||
await client.start() | ||
await client.run() | ||
|
||
# Grab the captured output of sys.stdout and sys.stderr from the capsys fixture | ||
await wait_all_tasks_blocked() | ||
out, err = capsys.readouterr() | ||
assert out == "Message from client: Hello!\nServer responded: Hello!\n" | ||
assert "Message from client: Hello!" in out | ||
assert "Server responded: Hello!" in out |