Skip to content

Commit f4e1b03

Browse files
author
Brendan Whitfield
committed
added test for status command
1 parent c8562c7 commit f4e1b03

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎tests/test_OBD.py‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ def __init__(self, portname, baudrate, protocol):
2222
self.portname = portname
2323
self.baudrate = baudrate
2424
self.protocol = protocol
25+
self._status = OBDStatus.CAR_CONNECTED
2526
self.last_command = None
2627

2728
def port_name(self):
2829
return self.portname
2930

3031
def status(self):
31-
return OBDStatus.CAR_CONNECTED
32+
return self._status
3233

3334
def ecus(self):
3435
return [ ECU.ENGINE, ECU.UNKNOWN ]
@@ -77,13 +78,31 @@ def _test_last_command(self, expected):
7778
def test_is_connected():
7879
o = obd.OBD("/dev/null")
7980
assert not o.is_connected()
80-
assert not o.supports(obd.commands.RPM)
8181

8282
# our fake ELM class always returns success for connections
8383
o.port = FakeELM("/dev/null", 34800, None)
8484
assert o.is_connected()
8585

8686

87+
def test_status():
88+
"""
89+
Make sure that the API's status() functions reports the
90+
same values as the underlying ELM327 class.
91+
"""
92+
o = obd.OBD("/dev/null")
93+
assert o.status() == OBDStatus.NOT_CONNECTED
94+
95+
# we can manually set our fake ELM class to test
96+
# the other values
97+
o.port = FakeELM("/dev/null", 34800, None)
98+
99+
o.port._status = OBDStatus.ELM_CONNECTED
100+
assert o.status() == OBDStatus.ELM_CONNECTED
101+
102+
o.port._status = OBDStatus.CAR_CONNECTED
103+
assert o.status() == OBDStatus.CAR_CONNECTED
104+
105+
87106
def test_supports():
88107
o = obd.OBD("/dev/null")
89108

0 commit comments

Comments
 (0)