コード例 #1
0
 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",
     )
コード例 #2
0
ファイル: __init__.py プロジェクト: ekos2001/aiohomekit
 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
コード例 #3
0
 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",
     )
コード例 #4
0
 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")
コード例 #5
0
 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")