|
| 1 | + |
| 2 | +from obd.commands import OBDCommand |
| 3 | +from obd.decoders import noop |
| 4 | + |
| 5 | + |
| 6 | +def test_basic_OBDCommand(): |
| 7 | + # name description mode cmd bytes decoder |
| 8 | + cmd = OBDCommand("Test", "example OBD command", "01", "23", 2, noop) |
| 9 | + assert cmd.name == "Test" |
| 10 | + assert cmd.desc == "example OBD command" |
| 11 | + assert cmd.mode == "01" |
| 12 | + assert cmd.pid == "23" |
| 13 | + assert cmd.bytes == 2 |
| 14 | + assert cmd.decode == noop |
| 15 | + assert cmd.supported == False |
| 16 | + |
| 17 | + assert cmd.get_command() == "0123" |
| 18 | + assert cmd.get_mode_int() == 1 |
| 19 | + assert cmd.get_pid_int() == 35 |
| 20 | + |
| 21 | + cmd = OBDCommand("Test", "example OBD command", "01", "23", 2, noop, True) |
| 22 | + assert cmd.supported == True |
| 23 | + |
| 24 | + |
| 25 | +def test_data_stripping(): |
| 26 | + # name description mode cmd bytes decoder |
| 27 | + cmd = OBDCommand("Test", "example OBD command", "01", "00", 2, noop) |
| 28 | + r = cmd.compute("41 00 01 01\r\n") |
| 29 | + assert not r.isNull() |
| 30 | + assert r.value == "0101" |
| 31 | + |
| 32 | + |
| 33 | +def test_data_not_hex(): |
| 34 | + # name description mode cmd bytes decoder |
| 35 | + cmd = OBDCommand("Test", "example OBD command", "01", "00", 2, noop) |
| 36 | + r = cmd.compute("41 00 wx yz\r\n") |
| 37 | + assert r.isNull() |
| 38 | + |
| 39 | + |
| 40 | +def test_data_length(): |
| 41 | + # name description mode cmd bytes decoder |
| 42 | + cmd = OBDCommand("Test", "example OBD command", "01", "00", 2, noop) |
| 43 | + r = cmd.compute("41 00 01 23 45\r\n") |
| 44 | + assert r.value == "0123" |
| 45 | + r = cmd.compute("41 00 01\r\n") |
| 46 | + assert r.value == "0100" |
0 commit comments