Skip to content

Commit 29d80dc

Browse files
author
Brendan Whitfield
committed
fixed CAN 11 bit tests
1 parent c915300 commit 29d80dc

2 files changed

Lines changed: 50 additions & 14 deletions

File tree

‎tests/test_protocol_can.py‎

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def check_message(m, num_frames, tx_id, data):
2727

2828

2929

30-
31-
3230
def test_single_frame():
3331
for protocol in CAN_11_PROTOCOLS:
3432
p = protocol([])
@@ -41,22 +39,40 @@ def test_single_frame():
4139

4240

4341
def test_hex_straining():
42+
"""
43+
If non-hex values are sent, they should be marked as ECU.UNKNOWN
44+
"""
45+
4446
for protocol in CAN_11_PROTOCOLS:
4547
p = protocol([])
4648

49+
# single non-hex message
50+
r = p(["12.8 Volts"])
51+
assert len(r) == 1
52+
assert r[0].ecu == ECU.UNKNOWN
53+
assert len(r[0].frames) == 1
54+
4755

48-
r = p(["NO DATA"])
49-
assert len(r) == 0
56+
# multiple non-hex message
57+
r = p(["12.8 Volts", "NO DATA"])
58+
assert len(r) == 2
5059

51-
r = p(["TOTALLY NOT HEX"])
52-
assert len(r) == 0
60+
for m in r:
61+
assert m.ecu == ECU.UNKNOWN
62+
assert len(m.frames) == 1
5363

64+
# mixed hex and non-hex
5465
r = p(["NO DATA", "7E8 06 41 00 00 01 02 03"])
55-
assert len(r) == 1
66+
assert len(r) == 2
67+
68+
# first message should be the valid, parsable hex message
69+
# NOTE: the parser happens to process the valid one's first
5670
check_message(r[0], 1, 0x0, list(range(4)))
5771

58-
r = p(["NO DATA", "NO DATA"])
59-
assert len(r) == 0
72+
# second message: invalid, non-parsable non-hex
73+
assert r[1].ecu == ECU.UNKNOWN
74+
assert len(r[1].frames) == 1
75+
assert len(r[1].data) == 0 # no data
6076

6177

6278

@@ -84,8 +100,12 @@ def test_multi_ecu():
84100

85101

86102

87-
88103
def test_multi_line():
104+
"""
105+
Tests that valid multiline messages are recombined into single
106+
messages.
107+
"""
108+
89109
for protocol in CAN_11_PROTOCOLS:
90110
p = protocol([])
91111

@@ -112,8 +132,15 @@ def test_multi_line():
112132
check_message(r[0], len(test_case), 0x0, correct_data)
113133

114134

115-
# missing frames in a multi-frame message should drop the message
116-
# (tests the contiguity check, and data length byte)
135+
136+
def test_multi_line_missing_frames():
137+
"""
138+
Missing frames in a multi-frame message should drop the message.
139+
Tests the contiguity check, and data length byte
140+
"""
141+
142+
for protocol in CAN_11_PROTOCOLS:
143+
p = protocol([])
117144

118145
test_case = [
119146
"7E8 10 20 49 04 00 01 02 03",
@@ -130,7 +157,16 @@ def test_multi_line():
130157
assert len(r) == 0
131158

132159

133-
# MODE 03 COMMANDS (GET_DTC) RETURN NO PID BYTE
160+
161+
def test_multi_line_mode_03():
162+
"""
163+
Tests the special handling of mode 3 commands.
164+
Namely, Mode 03 commands (GET_DTC) return no PID byte.
165+
When frames are combined, the parser should account for this.
166+
"""
167+
168+
for protocol in CAN_11_PROTOCOLS:
169+
p = protocol([])
134170

135171
test_case = [
136172
"7E8 10 20 43 04 00 01 02 03",

‎tests/test_protocol_legacy.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_hex_straining():
6868
for m in r:
6969
assert m.ecu == ECU.UNKNOWN
7070
assert len(m.frames) == 1
71-
71+
7272
# mixed hex and non-hex
7373
r = p(["NO DATA", "48 6B 10 41 00 00 01 02 03 FF"])
7474
assert len(r) == 2

0 commit comments

Comments
 (0)