Skip to content

Commit 257b94d

Browse files
committed
protoplaster: tests: Add force option to SMBus tests
Signed-off-by: Krzysztof Sychla <ksychla@antmicro.com>
1 parent 61c1f74 commit 257b94d

File tree

8 files changed

+27
-16
lines changed

8 files changed

+27
-16
lines changed

protoplaster/tests/i2c_mux/TCA9548A/TCA9548A.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
class TCA9548A(I2CMux):
66

7-
def __init__(self, i2c_bus: int, i2c_address: int):
8-
self.bus = SMBus(i2c_bus)
7+
def __init__(self,
8+
i2c_bus: int,
9+
i2c_address: int,
10+
smbus_force: bool = False):
11+
self.bus = SMBus(i2c_bus, force=smbus_force)
912
self.address = i2c_address
1013

1114
def is_alive(self):

protoplaster/tests/i2c_mux/TCA9548A/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def test_is_alive(self):
1818
check if TCA9548A responds correctly to simple requests
1919
{%- endmacro %}
2020
"""
21-
mux = TCA9548A(self.i2c_bus, self.i2c_address)
21+
self.smbus_force = getattr(self, "smbus_force", False)
22+
mux = TCA9548A(self.i2c_bus, self.i2c_address, self.smbus_force)
2223
assert mux.is_alive(), "TCA9548A does not respond correctly"
2324

2425
def name(self):

protoplaster/tests/pmic/DA9062/DA9062.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class LDOSelection(IntEnum):
8080
class DA9062:
8181
DEVICE_ID = 0x62
8282

83-
def __init__(self, i2c_bus, i2c_address):
84-
self.bus = SMBus(i2c_bus)
83+
def __init__(self, i2c_bus, i2c_address, smbus_force):
84+
self.bus = SMBus(i2c_bus, force=smbus_force)
8585
self.i2c_address = i2c_address
8686

8787
def is_alive(self):

protoplaster/tests/pmic/DA9062/test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ class TestDA9062:
1313
"""
1414

1515
def setup_class(self):
16-
if not hasattr(self, 'current_selections'):
17-
self.current_selections = []
18-
if not hasattr(self, 'current_voltages'):
19-
self.current_voltages = []
20-
self.pmic = DA9062(self.bus, self.address)
16+
self.current_selections = getattr(self, "current_selections", [])
17+
self.current_voltages = getattr(self, "current_voltages", [])
18+
self.smbus_force = getattr(self, "smbus_force", False)
19+
self.pmic = DA9062(self.bus, self.address, self.smbus_force)
2120

2221
def test_is_alive(self):
2322
"""

protoplaster/tests/pmic/UCD90320U/UCD90320U.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ class UCD90320URegs(IntEnum):
1111

1212
class UCD90320U:
1313

14-
def __init__(self, i2c_bus, i2c_address):
15-
self.bus = SMBus(i2c_bus)
14+
def __init__(self,
15+
i2c_bus: int,
16+
i2c_address: int,
17+
smbus_force: bool = False):
18+
self.bus = SMBus(i2c_bus, smbus_force)
1619
self.address = i2c_address
1720

1821
def is_alive(self):

protoplaster/tests/pmic/UCD90320U/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def test_is_alive(self):
1919
check if UCD90320U responds correctly to simple requests
2020
{%- endmacro %}
2121
"""
22-
pmic = UCD90320U(self.bus, self.address)
22+
self.smbus_force = getattr(self, "smbus_force", False)
23+
pmic = UCD90320U(self.bus, self.address, self.smbus_force)
2324
assert pmic.is_alive(), "UCD90320U does not respond correctly"
2425

2526
def name(self):

protoplaster/tests/thermometer/TMP431/TMP431.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ class TMP431:
1414
DEVICE_ID = 0x31
1515
MANUFACTURER_ID = 0x55
1616

17-
def __init__(self, i2c_bus, i2c_address):
18-
self.bus = SMBus(i2c_bus)
17+
def __init__(self,
18+
i2c_bus: int,
19+
i2c_address: int,
20+
smbus_force: bool = False):
21+
self.bus = SMBus(i2c_bus, force=smbus_force)
1922
self.address = i2c_address
2023

2124
def is_alive(self):

protoplaster/tests/thermometer/TMP431/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def test_is_alive(self):
1818
check if TMP431 responds correctly to simple requests
1919
{%- endmacro %}
2020
"""
21-
thermometer = TMP431(self.bus, self.address)
21+
self.smbus_force = getattr(self, "smbus_force", False)
22+
thermometer = TMP431(self.bus, self.address, self.smbus_force)
2223
assert thermometer.is_alive(), f"TMP431 does not respond correctly"
2324

2425
def name(self):

0 commit comments

Comments
 (0)