@@ -14,7 +14,12 @@ def test_list_integrity():
1414
1515 # make sure the command tables are in mode & PID order
1616 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
17+
18+ if len (cmds ) > 1 :
19+ assert pid == cmd .pid , "The index in the list must also be the PID: %s" % cmd .name
20+ else :
21+ # lone commands in a mode are allowed to have no PID
22+ assert (pid == cmd .pid ) or (cmd .pid is None )
1823
1924 # make sure all the fields are set
2025 assert cmd .name != "" , "Command names must not be null"
@@ -50,9 +55,12 @@ def test_getitem():
5055 continue # this command is reserved
5156
5257 # by [mode][pid]
53- mode = cmd .mode
54- pid = cmd .pid
55- assert cmd == obd .commands [mode ][pid ], "mode %d, PID %d could not be accessed through __getitem__" % (mode , pid )
58+ if (cmd .pid is None ) and (len (cmds ) == 1 ):
59+ # lone commands in a mode have no PID, and report a pid
60+ # value of None, but can still be accessed by PID 0
61+ assert cmd == obd .commands [cmd .mode ][0 ], "lone command in mode %d could not be accessed through __getitem__" % mode
62+ else :
63+ assert cmd == obd .commands [cmd .mode ][cmd .pid ], "mode %d, PID %d could not be accessed through __getitem__" % (mode , pid )
5664
5765 # by [name]
5866 assert cmd == obd .commands [cmd .name ], "command name %s could not be accessed through __getitem__" % (cmd .name )
@@ -70,9 +78,12 @@ def test_contains():
7078 assert obd .commands .has_command (cmd )
7179
7280 # by (mode, pid)
73- mode = cmd .mode
74- pid = cmd .pid
75- assert obd .commands .has_pid (mode , pid )
81+ if cmd .pid is None :
82+ # lone commands in a mode can have no PID, and report None
83+ # but these commands can still be looked up by (mode, pid=0)
84+ assert obd .commands .has_pid (cmd .mode , 0 )
85+ else :
86+ assert obd .commands .has_pid (cmd .mode , cmd .pid )
7687
7788 # by (name)
7889 assert obd .commands .has_name (cmd .name )
0 commit comments