Skip to content

Commit 86ad217

Browse files
charlesworthCharlesworth
charlesworth
authored andcommitted
added Eva_GPIO tests
1 parent fba1c89 commit 86ad217

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

tests/Eva_gpio_test.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
3+
digital_inputs = [('d0', 'input'), ('d1', 'input'), ('d2', 'input'), ('d3', 'input'), ('ee_d0', 'input'), ('ee_d1', 'input')]
4+
digital_outputs = [('d0', 'output'), ('d1', 'output'), ('d2', 'output'), ('d3', 'output'), ('ee_d0', 'output'), ('ee_d1', 'output')]
5+
analog_inputs = [('ee_a0', 'input'), ('ee_a1', 'input')]
6+
IOs = digital_inputs + analog_inputs + digital_outputs
7+
# Not supported yet ('a0', 'input'), ('a1', 'input'), ('a0', 'output'), ('a1', 'output'), ('ee_a0', 'output'), ('ee_a1', 'output')
8+
9+
10+
@pytest.mark.robot_required
11+
class TestEva_GPIO:
12+
def test_get(self, eva):
13+
# For all io variations, if the key is not present an exception
14+
# will be thrown so no assertions are required
15+
for pin in IOs:
16+
(pin_name, pin_type) = pin
17+
eva.gpio_get(pin_name, pin_type)
18+
19+
20+
def test_set(self, locked_eva):
21+
# All outputs should be set-able and idempotent
22+
for pin in digital_outputs:
23+
(pin_name, _) = pin
24+
locked_eva.gpio_set(pin_name, True)
25+
locked_eva.gpio_set(pin_name, True)
26+
locked_eva.gpio_set(pin_name, False)
27+
locked_eva.gpio_set(pin_name, False)
28+
29+
30+
@pytest.mark.io_loopback_required
31+
def test_set_get(self, locked_eva):
32+
digital_states = [True, False]
33+
for state in digital_states:
34+
for (pin_name, _) in digital_outputs:
35+
locked_eva.gpio_set(pin_name, state)
36+
37+
for (pin_name, pin_type) in digital_inputs:
38+
pin_state = locked_eva.gpio_get(pin_name, pin_type)
39+
assert(pin_state == state)

tests/conftest.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ def pytest_addoption(parser):
88
parser.addoption("--token", default='', help="API token of the test robot")
99
parser.addoption("--runslow", action="store_true", default=False, help="run slow tests")
1010
parser.addoption("--runrobot", action="store_true", default=False, help="run tests that require a connected Eva")
11+
parser.addoption(
12+
"--io_loopback",
13+
action="store_true",
14+
default=False,
15+
help="run tests that require head and base IO loopback cables connected to Eva",
16+
)
1117

1218

1319
@pytest.fixture(scope="session")
@@ -23,27 +29,35 @@ def token(request):
2329
def pytest_configure(config):
2430
config.addinivalue_line("markers", "slow: mark test as slow to run")
2531
config.addinivalue_line("markers", "robot_required: no mocks, needs a connected Eva to run")
32+
config.addinivalue_line(
33+
"markers",
34+
"io_loopback_required: require head and base IO loopback cables connected to Eva",
35+
)
2636

2737

2838
def pytest_collection_modifyitems(config, items):
29-
if config.getoption("--runslow"):
30-
# --runslow given in cli: do not skip slow tests
31-
return
32-
else:
39+
# --runslow given in cli: do not skip slow tests
40+
if not config.getoption("--runslow"):
3341
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
3442
for item in items:
3543
if "slow" in item.keywords:
3644
item.add_marker(skip_slow)
3745

38-
if config.getoption("--runrobot"):
39-
# --runrobot given in cli: do not skip tests where a connected Eva is required
40-
return
41-
else:
46+
# --runrobot given in cli: do not skip tests where a connected Eva is required
47+
if not config.getoption("--runrobot"):
4248
skip_robot_required = pytest.mark.skip(reason="need --runrobot option to run")
4349
for item in items:
4450
if "robot_required" in item.keywords:
4551
item.add_marker(skip_robot_required)
4652

53+
# --io_loopback given in cli: do not skip tests requiring
54+
# attached base and ee IO loopback cables
55+
if not config.getoption("--io_loopback"):
56+
skip_io_loopback_required = pytest.mark.skip(reason="need --io_loopback option to run")
57+
for item in items:
58+
if "io_loopback_required" in item.keywords:
59+
item.add_marker(skip_io_loopback_required)
60+
4761

4862
@pytest.fixture(scope="module")
4963
def eva(ip, token):

0 commit comments

Comments
 (0)