def test_to_string_for_dict(self): example = {1: "hello"} res = TLV.to_string(example) self.assertEqual(res, "{\n 1: (5 bytes/<class 'str'>) hello\n}\n") example = {1: "hello", 2: "world"} res = TLV.to_string(example) self.assertEqual( res, "{\n 1: (5 bytes/<class 'str'>) hello\n 2: (5 bytes/<class 'str'>) world\n}\n", )
def write_http(request, expected): body = TLV.encode_list(request) logging.debug("write message: %s", TLV.to_string(TLV.decode_bytes(body))) connection.putrequest("POST", "/pair-setup", skip_accept_encoding=True) connection.putheader("Content-Type", "application/pairing+tlv8") connection.putheader("Content-Length", len(body)) connection.endheaders(body) resp = connection.getresponse() response_tlv = TLV.decode_bytes(resp.read(), expected) logging.debug("response: %s", TLV.to_string(response_tlv)) return response_tlv
def test_to_string_for_list(self): example = [ ( 1, "hello", ), ] res = TLV.to_string(example) self.assertEqual(res, "[\n 1: (5 bytes/<class 'str'>) hello\n]\n") example = [ ( 1, "hello", ), ( 2, "world", ), ] res = TLV.to_string(example) self.assertEqual( res, "[\n 1: (5 bytes/<class 'str'>) hello\n 2: (5 bytes/<class 'str'>) world\n]\n", )
def test_to_string_for_list_bytearray(self): example = [[1, bytearray([0x42, 0x23])]] res = TLV.to_string(example) self.assertEqual(res, "[\n 1: (2 bytes/<class 'bytearray'>) 0x4223\n]\n")
def test_to_string_for_dict_bytearray(self): example = {1: bytearray([0x42, 0x23])} res = TLV.to_string(example) self.assertEqual(res, "{\n 1: (2 bytes/<class 'bytearray'>) 0x4223\n}\n")