This repository has been archived by the owner on Aug 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconftest.py
80 lines (55 loc) · 1.97 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from pathlib import Path
import pytest
from ledgercomm import Transport
from boilerplate_client.boilerplate_cmd import BoilerplateCommand
from boilerplate_client.button import ButtonTCP, ButtonFake
def pytest_addoption(parser):
parser.addoption("--hid",
action="store_true")
parser.addoption("--headless",
action="store_true")
@pytest.fixture(scope="module")
def sw_h_path():
# path with tests
conftest_folder_path: Path = Path(__file__).parent
# sw.h should be in src/sw.h
sw_h_path = conftest_folder_path.parent / "src" / "sw.h"
if not sw_h_path.is_file():
raise FileNotFoundError(f"Can't find sw.h: '{sw_h_path}'")
return sw_h_path
@pytest.fixture(scope="module")
def types_h_path():
# path with tests
conftest_folder_path: Path = Path(__file__).parent
# types.h should be in src/types.h
types_h_path = conftest_folder_path.parent / "src" / "transaction" / "types.h"
if not types_h_path.is_file():
raise FileNotFoundError(f"Can't find types.h: '{types_h_path}'")
return types_h_path
@pytest.fixture(scope="session")
def hid(pytestconfig):
return pytestconfig.getoption("hid")
@pytest.fixture(scope="session")
def headless(pytestconfig):
return pytestconfig.getoption("headless")
@pytest.fixture(scope="module")
def button(headless):
if headless:
button_client = ButtonTCP(server="127.0.0.1", port=42000)
else:
button_client = ButtonFake()
yield button_client
button_client.close()
@pytest.fixture(scope="session")
def cmd(hid):
transport = (Transport(interface="hid", debug=True)
if hid else Transport(interface="tcp",
server="127.0.0.1",
port=9999,
debug=True))
command = BoilerplateCommand(
transport=transport,
debug=True
)
yield command
command.transport.close()