Skip to content

Commit 214947f

Browse files
committed
Integration tests use pytest
1 parent 9a5f47a commit 214947f

3 files changed

Lines changed: 92 additions & 13 deletions

File tree

justfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ check:
8181

8282
# Run tests with pytest
8383
test:
84-
uv run pytest -vvv ./tests
84+
uv run pytest -vvv ./tests --ignore=./tests/test_integration.py
8585
@just clean-test
8686

8787
# Update snapshots
8888
snap:
8989
uv run pytest --snapshot-update ./tests
9090
@just clean-test
9191

92-
# Run integration tests (for what they are)
92+
# Run integration tests
9393
integration:
94-
uv run python ./tests/integration.py
94+
uv run pytest ./tests/test_integration.py
9595

9696
clean-test:
9797
rm -f pytest_runner-*.egg

tests/conftest.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import os
44
import os.path
5+
from typing import Callable, Never
56
from unittest.mock import Mock
67

78
import pytest
9+
from rich.prompt import Prompt
810

911
from plusdeck.client import Client, State
1012
import plusdeck.config
@@ -49,3 +51,78 @@ def default_port() -> str:
4951
monkeypatch.setattr(plusdeck.config, "default_port", default_port)
5052

5153
return port
54+
55+
56+
#
57+
# Integration test fixtures
58+
#
59+
60+
61+
class AbortError(AssertionError):
62+
"""
63+
A manual testing step has been aborted.
64+
"""
65+
66+
pass
67+
68+
69+
@pytest.fixture
70+
def abort() -> Callable[[], Never]:
71+
"""
72+
Abort a GAK test.
73+
"""
74+
75+
def _abort() -> Never:
76+
raise AbortError("Aborted.")
77+
78+
return _abort
79+
80+
81+
@pytest.fixture
82+
def confirm(abort, capsys) -> Callable[[str], None]:
83+
"""
84+
Manually confirm an expected state.
85+
"""
86+
87+
def _confirm(text: str) -> None:
88+
with capsys.disabled():
89+
res = Prompt.ask(text, choices=["confirm", "abort"])
90+
91+
if res == "abort":
92+
abort()
93+
94+
return _confirm
95+
96+
97+
@pytest.fixture
98+
def take_action(abort, capsys) -> Callable[[str], None]:
99+
"""
100+
Take a manual action before continuing.
101+
"""
102+
103+
def _take_action(text: str) -> None:
104+
with capsys.disabled():
105+
res = Prompt.ask(text, choices=["continue", "abort"])
106+
107+
if res == "abort":
108+
abort()
109+
110+
return _take_action
111+
112+
113+
@pytest.fixture
114+
def check(abort, capsys) -> Callable[[str, str], None]:
115+
"""
116+
Manually check whether or not an expected state is so.
117+
"""
118+
119+
def _check(text: str, expected: str) -> None:
120+
with capsys.disabled():
121+
res = Prompt.ask(text, choices=["yes", "no", "abort"])
122+
123+
if res == "abort":
124+
abort()
125+
126+
assert res == "yes", expected
127+
128+
return _check
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import pytest
2+
13
from plusdeck.client import Command, create_connection, State
24
from plusdeck.config import Config
3-
from plusdeck.test import check, confirm, run_tests, skip, take_action
45

56
CONFIG = Config.from_environment()
67

78

8-
@skip
9-
async def test_manual_no_events():
10-
"""Plus Deck plays tapes manually without state subscription."""
9+
@pytest.mark.skip
10+
async def test_manual_no_events(check, confirm, take_action) -> None:
11+
"""
12+
Plus Deck plays tapes manually without state subscription.
13+
"""
1114

1215
confirm("There is NO tape in the deck")
1316

@@ -33,8 +36,11 @@ def unexpected_state(state: State):
3336
client.close()
3437

3538

36-
async def test_commands_and_events():
37-
"""Plus Deck plays tapes with commands when subscribed."""
39+
@pytest.mark.asyncio
40+
async def test_commands_and_events(check, confirm, take_action) -> None:
41+
"""
42+
Plus Deck plays tapes with commands when subscribed.
43+
"""
3844

3945
confirm("There is NO tape in the deck")
4046

@@ -107,7 +113,3 @@ def log_state(state: State) -> None:
107113
client.events.remove_listener("state", log_state)
108114

109115
client.close()
110-
111-
112-
if __name__ == "__main__":
113-
run_tests(__name__)

0 commit comments

Comments
 (0)