def test_command_setters(): """Test setters""" # the setter order should not matter command = t.CommandHeader(0xFFFF) for cmd_type in t.CommandType: for subsys in t.Subsystem: # There's probably no need to iterate over all 256 possible values for cmd_id in (0x00, 0xFF, 0x10, 0x01, 0xF0, 0x0F, 0x22, 0xEE): perms = [ command.with_id(cmd_id).with_type(cmd_type).with_subsystem( subsys), command.with_type(cmd_type).with_id(cmd_id).with_subsystem( subsys), command.with_type(cmd_type).with_subsystem(subsys).with_id( cmd_id), command.with_subsystem(subsys).with_type(cmd_type).with_id( cmd_id), command.with_subsystem(subsys).with_id(cmd_id).with_type( cmd_type), command.with_id(cmd_id).with_subsystem(subsys).with_type( cmd_type), t.CommandHeader(0xFFFF, id=cmd_id, subsystem=subsys, type=cmd_type), ] assert len(set(perms)) == 1 assert perms[0].id == cmd_id assert perms[0].subsystem == subsys assert perms[0].type == cmd_type
def test_command_not_recognized(): command = c.RPCErrorCommands.CommandNotRecognized.Rsp( ErrorCode=c.rpc_error.ErrorCode.InvalidSubsystem, RequestHeader=t.CommandHeader(0xABCD), ) transport_frame = frames.TransportFrame(command.to_frame()) assert transport_frame.serialize()[:-1] == bytes.fromhex( "FE 03 60 00 01 CD AB")
def test_command_header(): """Test CommandHeader class.""" data = b"\x61\x02" extra = b"the rest of data\xaa\x55" r, rest = t.CommandHeader.deserialize(data + extra) assert rest == extra assert r.cmd0 == 0x61 assert r.id == 0x02 r = t.CommandHeader(0x0261) assert r.cmd0 == 0x61 assert r.id == 0x02 new1 = r.with_id(0xFF) assert new1.id == 0xFF assert new1.cmd0 == 0x61 new2 = r.with_id(0x00) assert new2.id == 0x00 assert new2.cmd0 == 0x61