Skip to content

Commit 1227f34

Browse files
author
Brendan Whitfield
committed
wrote tests for command tables
1 parent 25ae553 commit 1227f34

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

tests/test_Commands.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
import obd
3+
from obd.decoders import pid
4+
5+
6+
def test_list_integrity():
7+
for mode, cmds in enumerate(obd.commands.modes):
8+
for pid, cmd in enumerate(cmds):
9+
10+
# make sure the command tables are in mode & PID order
11+
assert mode == cmd.get_mode_int()
12+
assert pid == cmd.get_pid_int()
13+
14+
# make sure all the fields are set
15+
assert cmd.name != ""
16+
assert cmd.desc != ""
17+
assert (mode >= 1) and (mode <= 9)
18+
assert (pid >= 0) and (pid <= 196)
19+
assert cmd.bytes >= 0
20+
assert hasattr(cmd.decode, '__call__')
21+
22+
23+
def test_unique_names():
24+
# make sure no two commands have the same name
25+
names = {}
26+
27+
for cmds in obd.commands.modes:
28+
for cmd in cmds:
29+
assert not names.has_key(cmd.name)
30+
names[cmd.name] = True
31+
32+
33+
def test_getitem_mode_pid():
34+
# ensure that obd.commands[mode][pid] works correctly
35+
for cmds in obd.commands.modes:
36+
for cmd in cmds:
37+
mode = cmd.get_mode_int()
38+
pid = cmd.get_pid_int()
39+
assert cmd == obd.commands[mode][pid]
40+
41+
42+
def test_getitem_name():
43+
# ensure that obd.commands[name] works correctly
44+
for cmds in obd.commands.modes:
45+
for cmd in cmds:
46+
assert cmd == obd.commands[cmd.name]
47+
48+
49+
def test_pid_getters():
50+
# ensure that all pid getters are found
51+
pid_getters = obd.commands.pid_getters()
52+
53+
for cmds in obd.commands.modes:
54+
for cmd in cmds:
55+
if cmd.decode == pid:
56+
assert cmd in pid_getters

tests/test_OBD.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
from obd.decoders import noop
66

77

8+
def test_is_connected():
9+
o = obd.OBD("/dev/null")
10+
assert not o.is_connected()
11+
12+
# todo
13+
14+
815
def test_query():
916
# we don't need an actual serial connection
1017
o = obd.OBD("/dev/null")
@@ -26,6 +33,11 @@ def send(cmd):
2633

2734
# test
2835

36+
fromCar = "41 23 AB CD\r\r"
37+
r = o.query(cmd) # make sure unsupported commands don't send
38+
assert toCar[0] == ""
39+
assert r.is_null()
40+
2941
fromCar = "41 23 AB CD\r\r" # preset the response
3042
r = o.query(cmd, True) # run
3143
assert toCar[0] == "0123" # verify that the command was sent correctly
@@ -37,7 +49,7 @@ def send(cmd):
3749
assert r.raw_data == fromCar
3850
assert r.is_null()
3951

40-
fromCar = "totaly not hex!"
52+
fromCar = "totaly not hex!@#$"
4153
r = o.query(cmd, True)
4254
assert r.raw_data == fromCar
4355
assert r.is_null()
@@ -46,3 +58,7 @@ def send(cmd):
4658
r = o.query(cmd, True)
4759
assert r.raw_data == fromCar
4860
assert r.is_null()
61+
62+
63+
def test_load_commands():
64+
pass

0 commit comments

Comments
 (0)