Skip to content

Commit 7c56905

Browse files
author
Brendan Whitfield
committed
updated tests to include headers
1 parent 490400a commit 7c56905

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

obd/port.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __error(self, msg=None):
106106
debug("Connection Error:", True)
107107

108108
if msg is not None:
109-
debug(' ' + msg, True)
109+
debug(' ' + str(msg), True)
110110

111111
if self.port is not None:
112112
self.port.close()

tests/test_OBD.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,42 @@ def test_query():
1818
# forge our own command, to control the output
1919
cmd = OBDCommand("", "", "01", "23", 2, noop)
2020

21-
# forge IO from the car by overwriting the get/send functions
21+
# forge IO from the car by overwriting the read/write functions
2222

2323
# buffers
2424
toCar = [""] # needs to be inside mutable object to allow assignment in closure
2525
fromCar = ""
2626

27-
def send(cmd):
27+
def write(cmd):
2828
toCar[0] = cmd
2929

3030
o.is_connected = lambda *args: True
31-
o.port.send = send
32-
o.port.get = lambda *args: fromCar
31+
o.port.port = True
32+
o.port._OBDPort__write = write
33+
o.port._OBDPort__read = lambda *args: fromCar
3334

34-
# make sure unsupported commands don't send
35-
fromCar = "41 23 AB CD\r\r"
35+
# make sure unsupported commands don't write
36+
fromCar = "48 6B 10 41 23 AB CD\r\r"
3637
r = o.query(cmd)
3738
assert toCar[0] == ""
3839
assert r.is_null()
3940

4041
# a correct command transaction
41-
fromCar = "41 23 AB CD\r\r" # preset the response
42+
fromCar = "48 6B 10 41 23 AB CD\r\r" # preset the response
4243
r = o.query(cmd, force=True) # run
4344
assert toCar[0] == "0123" # verify that the command was sent correctly
4445
assert r.raw_data == fromCar # verify that raw_data was stored in the Response
4546
assert r.value == "ABCD" # verify that the response was parsed correctly
4647

4748
# response of greater length
48-
fromCar = "41 23 AB CD EF\r\r"
49+
fromCar = "48 6B 10 41 23 AB CD EF\r\r"
4950
r = o.query(cmd, force=True)
5051
assert toCar[0] == "0123"
5152
assert r.raw_data == fromCar
5253
assert r.value == "ABCD"
5354

5455
# response of greater length
55-
fromCar = "41 23 AB\r\r"
56+
fromCar = "48 6B 10 41 23 AB\r\r"
5657
r = o.query(cmd, force=True)
5758
assert toCar[0] == "0123"
5859
assert r.raw_data == fromCar

tests/test_OBDCommand.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ def test_clone():
3939
def test_data_stripping():
4040
# name description mode cmd bytes decoder
4141
cmd = OBDCommand("Test", "example OBD command", "01", "00", 2, noop)
42-
r = cmd.compute("41 00 01 01\r\n")
42+
r = cmd.compute("48 6B 10 41 00 01 01\r\n")
4343
assert not r.is_null()
4444
assert r.value == "0101"
4545

4646

4747
def test_data_not_hex():
4848
# name description mode cmd bytes decoder
4949
cmd = OBDCommand("Test", "example OBD command", "01", "00", 2, noop)
50-
r = cmd.compute("41 00 wx yz\r\n")
50+
r = cmd.compute("48 6B 10 41 00 wx yz\r\n")
5151
assert r.is_null()
5252

5353

5454
def test_data_length():
5555
# name description mode cmd bytes decoder
5656
cmd = OBDCommand("Test", "example OBD command", "01", "00", 2, noop)
57-
r = cmd.compute("41 00 01 23 45\r\n")
57+
r = cmd.compute("48 6B 10 41 00 01 23 45\r\n")
5858
assert r.value == "0123"
59-
r = cmd.compute("41 00 01\r\n")
59+
r = cmd.compute("48 6B 10 41 00 01\r\n")
6060
assert r.value == "0100"

0 commit comments

Comments
 (0)