Пример #1
0
 def test_serializing(args):
     tag = CompoundTag(tag_name='Test',
                       children=[
                           ByteTag(25, tag_name='dp1'),
                           FloatTag(1.5, tag_name='dp2'),
                           ListTag(ByteTag.clazz_id,
                                   tag_name='dp3',
                                   children=[ByteTag(35)]),
                           CompoundTag(tag_name='dp4',
                                       children=[
                                           ByteArrayTag(tag_name='sub_dp',
                                                        children=[
                                                            ByteTag(10),
                                                            ByteTag(20)
                                                        ])
                                       ])
                       ])
     stream = OutputStream()
     tag.serialize(stream, include_name=True)
     binary_tag = list(stream.get_data())
     expected_tag = [10, 0, 4] + \
         list(b'Test') + \
         [1, 0, 3,] + list(b'dp1') + [25] +\
         [5, 0, 3,] + list(b'dp2') + [63, 192, 0, 0] +\
         [9, 0, 3,] + list(b'dp3') + [1, 0, 0, 0, 1] + [35] +\
         [10, 0, 3,] + list(b'dp4') +\
         [7, 0, 6,] + list(b'sub_dp') + [0, 0, 0, 2, 10, 20] + [0] +\
         [0]
     assert binary_tag == expected_tag, 'Tag ListTag with ListTag elements'
Пример #2
0
 def test_serializing_without_name(args):
     tag = clz(test_val, tag_name='Test')
     stream = OutputStream()
     tag.serialize(stream, include_name=False)
     binary_tag = list(stream.get_data())
     expected_tag = test_bin
     assert binary_tag == expected_tag, f'Tag {clz.clazz_name}'
Пример #3
0
    def test_serializing_compund_data(args):
        tag = ListTag(CompoundTag.clazz_id,
                      tag_name='Test',
                      children=[
                          CompoundTag(children=[
                              ByteTag(25, tag_name='dp1'),
                              ByteTag(31, tag_name='dp2')
                          ]),
                          CompoundTag(children=[
                              ByteTag(25, tag_name='dp3'),
                              ByteTag(31, tag_name='dp4')
                          ])
                      ])
        stream = OutputStream()
        tag.serialize(stream, include_name=True)
        binary_tag = list(stream.get_data())
        expected_tag = [9, 0, 4] + \
            list(b'Test') + \
            [10, 0, 0, 0, 2] +\
            [1, 0, 3,] + list(b'dp1') + [25] +\
            [1, 0, 3,] + list(b'dp2') + [31, 0] +\
            [1, 0, 3,] + list(b'dp3') + [25] +\
            [1, 0, 3,] + list(b'dp4') + [31, 0]

        assert binary_tag == expected_tag, 'Tag ListTag with ListTag elements'
Пример #4
0
 def test_serializing_with_name(args):
     tag = clz(test_val, tag_name='Test')
     stream = OutputStream()
     tag.serialize(stream, include_name=True)
     binary_tag = list(stream.get_data())
     expected_tag = [clz.clazz_id, 0, 4] + \
         list(b'Test') + \
         test_bin
     assert binary_tag == expected_tag, f'Tag {clz.clazz_name}'
Пример #5
0
 def test_serializing(args):
     tag = StringTag('Hello World', tag_name='Test')
     stream = OutputStream()
     tag.serialize(stream, include_name=True)
     binary_tag = list(stream.get_data())
     expected_tag = [8, 0, 4] + \
         list(b'Test') + \
         [0,len('Hello World')] +\
         list(b'Hello World')
     assert binary_tag == expected_tag, 'Tag StringTag'
Пример #6
0
 def test_serializing(args):
     tag = clz('Test',
               children=[clz.clazz_sub_type(v) for v in test_vals])
     stream = OutputStream()
     tag.serialize(stream, include_name=True)
     binary_tag = list(stream.get_data())
     expected_tag = [clz.clazz_id, 0, 4] + \
         list(b'Test') + \
         [0,0,0,len(test_vals)] +\
         [b for sublist in test_bins for b in sublist]
     assert binary_tag == expected_tag, f'Tag {clz.clazz_name}'
Пример #7
0
    def test_serializing_simple_data(args):
        tag = ListTag(FloatTag.clazz_id,
                      tag_name='Test',
                      children=[FloatTag(1.5), FloatTag(11.15)])
        stream = OutputStream()
        tag.serialize(stream, include_name=True)
        binary_tag = list(stream.get_data())
        expected_tag = [9, 0, 4] + \
            list(b'Test') + \
            [5, 0, 0, 0, 2] +\
            [63, 192, 0, 0, 65, 50, 102, 102]

        assert binary_tag == expected_tag, 'Tag ListTag with FloatTag elements'
Пример #8
0
    def test_serializing_list_data(args):
        tag = ListTag(ListTag.clazz_id,
                      tag_name='Test',
                      children=[
                          ListTag(ByteTag.clazz_id,
                                  children=[ByteTag(25),
                                            ByteTag(31)]),
                          ListTag(FloatTag.clazz_id, children=[FloatTag(1.5)])
                      ])
        stream = OutputStream()
        tag.serialize(stream, include_name=True)
        binary_tag = list(stream.get_data())

        expected_tag = [9, 0, 4] + \
            list(b'Test') + \
            [9, 0, 0, 0, 2] +\
            [1, 0, 0, 0, 2] +\
            [25, 31] +\
            [5, 0, 0, 0, 1] +\
            [63, 192, 0, 0]

        assert binary_tag == expected_tag, 'Tag ListTag with ListTag elements'
Пример #9
0
 def test_writing_data(args):
     stream = OutputStream()
     stream.write(b'Hello World')
     stream_data = stream.get_data()
     assert stream_data == b'Hello World'