This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
74 lines (58 loc) · 2.36 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
# -*- coding: utf-8 -*-
# (c) Copyright 2021 Sensirion AG, Switzerland
from __future__ import absolute_import, division, print_function
from sensirion_shdlc_driver import ShdlcSerialPort, ShdlcConnection
from sensirion_shdlc_sensorbridge import SensorBridgePort, \
SensorBridgeShdlcDevice, SensorBridgeI2cProxy
from sensirion_i2c_driver import I2cConnection
from sensirion_i2c_stc import Stc3xI2cDevice
import pytest
def pytest_addoption(parser):
"""
Register command line options
"""
parser.addoption("--serial-port", action="store", type="string")
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 = []
lines.append("SensorBridge serial port: " + str(_get_serial_port(config)))
lines.append("SensorBridge serial bitrate: " +
str(_get_serial_bitrate(config)))
return '\n'.join(lines)
@pytest.fixture(scope="session")
def bridge(request):
serial_port = _get_serial_port(request.config, validate=True)
serial_bitrate = _get_serial_bitrate(request.config)
with ShdlcSerialPort(serial_port, serial_bitrate) as port:
dev = SensorBridgeShdlcDevice(ShdlcConnection(port), slave_address=0)
yield dev
@pytest.fixture
def stc3x(bridge):
# Configure SensorBridge port 1 for STC3x
bridge.set_i2c_frequency(SensorBridgePort.ONE, frequency=400e3)
bridge.set_supply_voltage(SensorBridgePort.ONE, voltage=3.3)
bridge.switch_supply_on(SensorBridgePort.ONE)
# Create STC3x device
i2c_transceiver = SensorBridgeI2cProxy(bridge, port=SensorBridgePort.ONE)
stc3x = Stc3xI2cDevice(I2cConnection(i2c_transceiver))
yield stc3x
# make sure the channel is powered off after executing tests
bridge.switch_supply_off(SensorBridgePort.ONE)