Exemplo n.º 1
0
 def test_roundtrip(self):
     """
     parse packets, then serialize them again and check
     """
     for idx, packet in enumerate(self.PACKET_LIST):
         parsed = parse_represented_data(packet)
         serialized = parsed.serialize()
         self.assertEqual(
             str(parsed), str(parse_represented_data(serialized)),
             "Parsed representation doesn't match serialized representation (case {})"
             .format(idx))
         self.assertEqual(
             bytearray.fromhex(packet), serialized,
             "Serialized {} message doesn't match original message (case {})"
             .format(parsed.__class__.__name__, idx))
Exemplo n.º 2
0
 def test_parsing_two(self):
     """
     parse some packets
      - from the tutorial
      - from complicated scenarios
      - from failing parsings
     and tell me if they are understood:
     """
     PACKETS = [
         # 06 D1
         '10 02 06 D1 17 00 20 20 20 20 20 20 20 20 20 4B 61 73 73 65 6E '
         '73 63 68 6E 69 74 74 10 03 2F 07',
         # 04 0F
         '10 02 04 0F 37 27 00 04 00 00 00 00 40 00 49 09 78 0C 09 38 48 '
         '0D 04 25 22 F1 F1 59 66 66 66 66 D2 00 21 22 01 00 17 00 01 87 '
         '01 75 0B 61 39 95 19 40 29 60 09 99 14 0E 05 12 8A 02 10 03 90 '
         '8C',
     ]
     idx = 0
     for packet in PACKETS:
         rep = parse_represented_data(packet)
         info(rep)
         if not isinstance(rep, Packet):
             raise AssertionError("Packet could not be parsed: #%s" % idx)
         idx += 1
Exemplo n.º 3
0
    def test_text_encoding_latin1(self):
        packet = '06d10d005465737420e420f620fc20df'

        with enter_context(character_set=CharacterSet.LATIN_1):
            p = parse_represented_data(packet)

        self.assertEqual('Test ä ö ü ß', p.text)
Exemplo n.º 4
0
    def test_text_encoding_utf8(self):
        packet = '06d121005465737420c3a420c3b620c3bc20c39f'

        with enter_context(character_set=CharacterSet.UTF8):
            p = parse_represented_data(packet)

        self.assertEqual('Test ä ö ü ß', p.text)
Exemplo n.º 5
0
    def test_text_encoding_zvt_7bit(self):
        packet = '06d10d0054657374207b207c207d207e'

        with enter_context(character_set=ZVT_7BIT_CHARACTER_SET):
            p = parse_represented_data(packet)

        self.assertEqual('Test ä ö ü ß', p.text)
Exemplo n.º 6
0
 def test_version_completion(self):
     # following completion is sent by the PT with version on
     # statusenquiry:
     data_expected = \
         '10 02 06 0F 0B F0 F0 F7 32 2E 31 34 2E 31 35 00 10 03 B1 11'
     # small test to test the completion with software version to be
     # recognized.
     rep = parse_represented_data(data_expected)
     self.assertEqual(rep.__class__, Completion)
Exemplo n.º 7
0
 def test_all_packets(self):
     """
     Create packets, dump their binary data and compare them to their
     expected versions.
     """
     PACKETS = Packets.packets.values()
     for packet in PACKETS:
         rep = parse_represented_data(conv.toHexString(packet().to_list()))
         self.assertEqual(rep.__class__, packet)
Exemplo n.º 8
0
 def test_all_packets(self):
     """
         create packets, dump their binary data and try to find them
         out again!
     """
     PACKETS = Packets.packets.values()
     for packet in PACKETS:
         rep = parse_represented_data(conv.toHexString(packet().to_list()))
         self.assertEqual(rep.__class__, packet)
Exemplo n.º 9
0
 def test_all_packets(self):
     """
         create packets, dump their binary data and try to find them
         out again!
     """
     PACKETS = Packets.packets.values()
     for packet in PACKETS:
         rep = parse_represented_data(conv.toHexString(packet().to_list()))
         self.assertEqual(rep.__class__,
                              packet)
Exemplo n.º 10
0
 def test_parsing_two(self):
     """
     parse some packets
      - from the tutorial
      - from complicated scenarios
      - from failing parsings
     and tell me if they are understood:
     """
     for idx, packet in enumerate(self.PACKET_LIST):
         rep = parse_represented_data(packet)
         info(rep)
         if not isinstance(rep, Packet):
             raise AssertionError("Packet could not be parsed: #%s" % idx)
Exemplo n.º 11
0
 def test_parsing_two(self):
     """
         parse some packets 
          - from the tutorial 
          - from complicated scenarios
          - from failing parsings
         and tell me if they are understood:
     """
     PACKETS = [
         # 06 D1
         '10 02 06 D1 17 00 20 20 20 20 20 20 20 20 20 4B 61 73 73 65 6E 73 63 68 6E 69 74 74 10 03 2F 07',
         # 04 0F
         '10 02 04 0F 37 27 00 04 00 00 00 00 40 00 49 09 78 0C 09 38 48 0D 04 25 22 F1 F1 59 66 66 66 66'\
         'D2 00 21 22 01 00 17 00 01 87 01 75 0B 61 39 95 19 40 29 60 09 99 14 0E 05 12 8A 02 10 03 90 8C',
                ]
     i = 0
     for packet in PACKETS:
         rep = parse_represented_data(packet)
         logging.info(rep)
         if not isinstance(rep, Packet):
             raise AssertionError, "Packet could not be parsed: #%s" % i
         i += 1
Exemplo n.º 12
0
 def test_version_completion(self):
     # following completion is sent by the PT with version on statusenquiry:
     data_expected = """10 02 06 0F 0B F0 F0 F7 32 2E 31 34 2E 31 35 00 10 03 B1 11"""
     # small test to test the completion with software version to be recognized.
     rep = parse_represented_data(data_expected)
     self.assertEqual(rep.__class__, Completion)
Exemplo n.º 13
0
    def test_text_encoding_default(self):
        packet = '06d10d005465737420842094208120e1'
        p = parse_represented_data(packet)

        self.assertEqual('Test ä ö ü ß', p.text)
Exemplo n.º 14
0
    def test_text_encoding_tlv(self):
        packet = '04ff140a010610240e070c5465737420842094208120e1'
        p = parse_represented_data(packet)

        self.assertEqual('Test ä ö ü ß', p.tlv.x24.x07)