forked from riot-appstore/PHiLIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
57 lines (46 loc) · 1.68 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
"""Conf Test for pytest
Declares fixtures and common functions
"""
import pytest
import serial
from philip_pal import Phil
from digilent_device import DigilentAnalogDiscovery2
def pytest_addoption(parser):
"""Adds options like arg parse"""
parser.addoption("--philip_port", action="store",
default="/dev/ttyACM0", help="The serial port for PHiLIP")
parser.addoption("--tester_port", action="store",
default="/dev/ttyUSB0",
help="The serial port for the testing device")
@pytest.fixture(scope="module")
def phil_init(request):
"""Instance for the philip connection"""
phil = Phil(request.config.getoption("--philip_port"))
yield phil
phil.reset_mcu()
phil.dev.close()
@pytest.fixture(scope="function")
def phil(phil_init):
"""Instance for the philip connection, provides reset"""
# Provide extra reset since a test may fail assert and need to resync
result = phil_init.RESULT_TIMEOUT
for attempts in range(1, 3):
result = phil_init.reset_mcu(timeout=(attempts * 0.5))['result']
if result == phil_init.RESULT_SUCCESS:
break
assert result == phil_init.RESULT_SUCCESS
yield phil_init
phil_init.reset_mcu()
@pytest.fixture(scope="function")
def tester(request):
"""Instance for the serial to usb tester"""
dev = serial.Serial(port=request.config.getoption("--tester_port"),
baudrate=115200, timeout=0.3, write_timeout=1)
yield dev
dev.close()
@pytest.fixture(scope="function")
def tester_dad2():
"""Instance for Digilent Analog Discover 2"""
dad2 = DigilentAnalogDiscovery2()
yield dad2
dad2.driver.pins_reset()