mirror of https://github.com/Nonannet/pyhoff.git
test for setup BusTerminal added
This commit is contained in:
parent
6a4aa22575
commit
2d69ffc7d5
|
@ -1,9 +1,14 @@
|
||||||
import inspect
|
import inspect
|
||||||
|
import src.pyhoff as pyhoff
|
||||||
import src.pyhoff.devices as devices
|
import src.pyhoff.devices as devices
|
||||||
from src.pyhoff.devices import DigitalInputTerminal, DigitalOutputTerminal, AnalogInputTerminal, AnalogOutputTerminal
|
from src.pyhoff.devices import DigitalInputTerminal, DigitalOutputTerminal, AnalogInputTerminal, AnalogOutputTerminal
|
||||||
|
|
||||||
|
|
||||||
def test_terminal_plausib():
|
def test_terminal_plausib():
|
||||||
|
"""
|
||||||
|
Test if all implemented BusTerminal classes in devices
|
||||||
|
have the plausible parameters
|
||||||
|
"""
|
||||||
|
|
||||||
for n, o in inspect.getmembers(devices):
|
for n, o in inspect.getmembers(devices):
|
||||||
if inspect.isclass(o) and o not in [DigitalInputTerminal,
|
if inspect.isclass(o) and o not in [DigitalInputTerminal,
|
||||||
|
@ -32,3 +37,25 @@ def test_terminal_plausib():
|
||||||
assert o.parameters.get('input_bit_width', 0) == 0
|
assert o.parameters.get('input_bit_width', 0) == 0
|
||||||
assert o.parameters.get('output_bit_width', 0) == 0
|
assert o.parameters.get('output_bit_width', 0) == 0
|
||||||
assert o.parameters.get('output_word_width', 0) > 0
|
assert o.parameters.get('output_word_width', 0) > 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_terminal_setup():
|
||||||
|
"""
|
||||||
|
Test if all implemented BusTerminal classes in devices can
|
||||||
|
be instantiated and connected to a bus coupler
|
||||||
|
"""
|
||||||
|
|
||||||
|
terminal_classes: list[type[pyhoff.BusTerminal]] = []
|
||||||
|
for n, o in inspect.getmembers(devices):
|
||||||
|
if inspect.isclass(o) and o not in [DigitalInputTerminal,
|
||||||
|
DigitalOutputTerminal,
|
||||||
|
AnalogInputTerminal,
|
||||||
|
AnalogOutputTerminal]:
|
||||||
|
if issubclass(o, pyhoff.BusTerminal):
|
||||||
|
print(n)
|
||||||
|
terminal_classes.append(o)
|
||||||
|
|
||||||
|
bus_cupler = devices.BK9050('localhost', 11255, terminal_classes, timeout=0.001)
|
||||||
|
|
||||||
|
assert len(terminal_classes) == len(bus_cupler.bus_terminals)
|
||||||
|
assert bus_cupler.get_error() == 'connection failed', bus_cupler.get_error()
|
||||||
|
|
Loading…
Reference in New Issue