Skip to content

Commit 2b58457

Browse files
author
Brendan Whitfield
committed
fixed tests for None reserved commands, and mode_int -> mode
1 parent 8d16793 commit 2b58457

5 files changed

Lines changed: 46 additions & 24 deletions

File tree

obd/OBDCommand.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def clone(self):
6565
self.fast)
6666

6767
@property
68-
def mode_int(self):
68+
def mode(self):
6969
if len(self.command) >= 2:
7070
return unhex(self.command[:2])
7171
else:
7272
return 0
7373

7474
@property
75-
def pid_int(self):
75+
def pid(self):
7676
if len(self.command) > 2:
7777
return unhex(self.command[2:])
7878
else:

obd/commands.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,15 @@ def base_commands(self):
382382
def pid_getters(self):
383383
""" returns a list of PID GET commands """
384384
getters = []
385-
for m in self.modes:
386-
for c in m:
387-
if c.decode == pid: # GET commands have a special decoder
388-
getters.append(c)
385+
for mode in self.modes:
386+
for cmd in mode:
387+
388+
if cmd is None:
389+
continue # this command is reserved
390+
391+
if cmd.decode == pid: # GET commands have a special decoder
392+
getters.append(cmd)
393+
389394
return getters
390395

391396

obd/obd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def __load_commands(self):
120120
for i in range(len(supported)):
121121
if supported[i] == "1":
122122

123-
mode = get.mode_int
124-
pid = get.pid_int + i + 1
123+
mode = get.mode
124+
pid = get.pid + i + 1
125125

126126
if commands.has_pid(mode, pid):
127127
self.supported_commands.add(commands[mode][pid])

tests/test_OBDCommand.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def test_constructor():
1919
assert cmd.ecu == ECU.ENGINE
2020
assert cmd.fast == False
2121

22-
assert cmd.mode_int == 1
23-
assert cmd.pid_int == 35
22+
assert cmd.mode == 1
23+
assert cmd.pid == 35
2424

2525
# a case where "fast", and "supported" were set explicitly
2626
# name description cmd bytes decoder ECU fast
@@ -67,18 +67,18 @@ def test_call():
6767

6868

6969

70-
def test_get_mode_int():
70+
def test_get_mode():
7171
cmd = OBDCommand("", "", "0123", 4, noop, ECU.ENGINE)
72-
assert cmd.mode_int == 0x01
72+
assert cmd.mode == 0x01
7373

7474
cmd = OBDCommand("", "", "", "23", 4, noop, ECU.ENGINE)
75-
assert cmd.mode_int == 0
75+
assert cmd.mode == 0
7676

7777

7878

79-
def test_pid_int():
79+
def test_pid():
8080
cmd = OBDCommand("", "", "0123", 4, noop, ECU.ENGINE)
81-
assert cmd.pid_int == 0x23
81+
assert cmd.pid == 0x23
8282

8383
cmd = OBDCommand("", "", "01", 4, noop, ECU.ENGINE)
84-
assert cmd.pid_int == 0
84+
assert cmd.pid == 0

tests/test_commands.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ def test_list_integrity():
77
for mode, cmds in enumerate(obd.commands.modes):
88
for pid, cmd in enumerate(cmds):
99

10+
if cmd is None:
11+
continue # this command is reserved
12+
1013
assert cmd.command != "", "The Command's command string must not be null"
1114

1215
# make sure the command tables are in mode & PID order
13-
assert mode == cmd.mode_int, "Command is in the wrong mode list: %s" % cmd.name
14-
assert pid == cmd.pid_int, "The index in the list must also be the PID: %s" % cmd.name
16+
assert mode == cmd.mode, "Command is in the wrong mode list: %s" % cmd.name
17+
assert pid == cmd.pid, "The index in the list must also be the PID: %s" % cmd.name
1518

1619
# make sure all the fields are set
1720
assert cmd.name != "", "Command names must not be null"
@@ -30,6 +33,10 @@ def test_unique_names():
3033

3134
for cmds in obd.commands.modes:
3235
for cmd in cmds:
36+
37+
if cmd is None:
38+
continue # this command is reserved
39+
3340
assert not names.__contains__(cmd.name), "Two commands share the same name: %s" % cmd.name
3441
names[cmd.name] = True
3542

@@ -39,9 +46,12 @@ def test_getitem():
3946
for cmds in obd.commands.modes:
4047
for cmd in cmds:
4148

49+
if cmd is None:
50+
continue # this command is reserved
51+
4252
# by [mode][pid]
43-
mode = cmd.mode_int
44-
pid = cmd.pid_int
53+
mode = cmd.mode
54+
pid = cmd.pid
4555
assert cmd == obd.commands[mode][pid], "mode %d, PID %d could not be accessed through __getitem__" % (mode, pid)
4656

4757
# by [name]
@@ -53,12 +63,15 @@ def test_contains():
5363
for cmds in obd.commands.modes:
5464
for cmd in cmds:
5565

66+
if cmd is None:
67+
continue # this command is reserved
68+
5669
# by (command)
5770
assert obd.commands.has_command(cmd)
5871

5972
# by (mode, pid)
60-
mode = cmd.mode_int
61-
pid = cmd.pid_int
73+
mode = cmd.mode
74+
pid = cmd.pid
6275
assert obd.commands.has_pid(mode, pid)
6376

6477
# by (name)
@@ -78,7 +91,11 @@ def test_pid_getters():
7891
# ensure that all pid getters are found
7992
pid_getters = obd.commands.pid_getters()
8093

81-
for cmds in obd.commands.modes:
82-
for cmd in cmds:
94+
for mode in obd.commands.modes:
95+
for cmd in mode:
96+
97+
if cmd is None:
98+
continue # this command is reserved
99+
83100
if cmd.decode == pid:
84101
assert cmd in pid_getters

0 commit comments

Comments
 (0)