|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | import os.path |
| 5 | +from typing import Callable, Never |
5 | 6 | from unittest.mock import Mock |
6 | 7 |
|
7 | 8 | import pytest |
| 9 | +from rich.prompt import Prompt |
8 | 10 |
|
9 | 11 | from plusdeck.client import Client, State |
10 | 12 | import plusdeck.config |
@@ -49,3 +51,78 @@ def default_port() -> str: |
49 | 51 | monkeypatch.setattr(plusdeck.config, "default_port", default_port) |
50 | 52 |
|
51 | 53 | 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 |
0 commit comments