-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
59 lines (47 loc) · 1.99 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
# -*- coding: utf-8 -*-
# (c) Copyright 2021 Sensirion AG, Switzerland
import pytest
from sensirion_shdlc_sensorbridge import SensorBridgePort
from sensirion_driver_adapters.i2c_adapter.sensor_bridge_i2c_channel_provider import SensorBridgeI2cChannelProvider
from sensirion_driver_adapters.mocks.mock_i2c_channel_provider import MockI2cChannelProvider
from sensirion_i2c_sht3x.response_provider import Sht3xResponseProvider
def pytest_addoption(parser):
"""
Register command line options
"""
parser.addoption("--serial-port", action="store", type=str)
parser.addoption("--serial-bitrate", action="store", type=int, default=460800)
def _get_serial_port(config, validate=False):
"""
Get the serial port to be used for the tests.
"""
port = config.getoption("--serial-port")
if (validate is True) and (port is None):
raise ValueError("Please specify the serial port to be used with "
"the '--serial-port' argument.")
return port
def _get_serial_bitrate(config):
"""
Get the serial port bitrate to be used for the tests.
"""
return config.getoption("--serial-bitrate")
def pytest_report_header(config):
"""
Add extra information to test report header
"""
lines = [
"SensorBridge serial port: " + str(_get_serial_port(config)),
"SensorBridge serial bitrate: " + str(_get_serial_bitrate(config))
]
return '\n'.join(lines)
@pytest.fixture(scope="session")
def channel_provider(request):
serial_port = _get_serial_port(request.config)
serial_bitrate = _get_serial_bitrate(request.config)
if serial_port is not None:
yield SensorBridgeI2cChannelProvider(sensor_bridge_port=SensorBridgePort.ONE,
serial_baud_rate=serial_bitrate,
serial_port=serial_port)
else:
yield MockI2cChannelProvider(command_width=2,
response_provider=Sht3xResponseProvider())