示例#1
0
    def test_simple(self):
        pairs = [
            ('a', 'test'),
            ('a2', b'\xd0\xb0\xd0\xb1\xd0\xb2\xd0\xb3'.decode('utf-8')),
            ('bb', 1),
            ('bb2', -500),
            ('ccc', 1.0),
            ('dddd', vdf.POINTER(1234)),
            ('fffff', vdf.COLOR(1234)),
            ('gggggg', vdf.UINT_64(1234)),
            ('hhhhhhh', vdf.INT_64(-1234)),
        ]

        data = OrderedDict(pairs)
        data['level1-1'] = OrderedDict(pairs)
        data['level1-1']['level2-1'] = OrderedDict(pairs)
        data['level1-1']['level2-2'] = OrderedDict(pairs)
        data['level1-2'] = OrderedDict(pairs)

        result = vdf.binary_loads(vdf.binary_dumps(data), mapper=OrderedDict)

        self.assertEqual(data, result)

        result = vdf.binary_loads(vdf.binary_dumps(data, alt_format=True), mapper=OrderedDict, alt_format=True)

        self.assertEqual(data, result)

        result = vdf.vbkv_loads(vdf.vbkv_dumps(data), mapper=OrderedDict)

        self.assertEqual(data, result)
示例#2
0
    def test_simple(self):
        pairs = [
            ('a', 'test'),
            ('a2', b'\xff\xfe0\x041\x042\x043\x04'.decode('utf-16')),
            ('bb', 1),
            ('bb2', -500),
            ('ccc', 1.0),
            ('dddd', vdf.POINTER(1234)),
            ('fffff', vdf.COLOR(1234)),
            ('gggggg', vdf.UINT_64(1234)),
            ('hhhhhhh', vdf.INT_64(-1234)),
        ]

        data = OrderedDict(pairs)
        data['level1-1'] = OrderedDict(pairs)
        data['level1-1']['level2-1'] = OrderedDict(pairs)
        data['level1-1']['level2-2'] = OrderedDict(pairs)
        data['level1-2'] = OrderedDict(pairs)

        result = vdf.binary_loads(vdf.binary_dumps(data), mapper=OrderedDict)

        self.assertEqual(data, result)

        result = vdf.binary_loads(vdf.binary_dumps(data, alt_format=True),
                                  mapper=OrderedDict,
                                  alt_format=True)

        self.assertEqual(data, result)

        result = vdf.vbkv_loads(vdf.vbkv_dumps(data), mapper=OrderedDict)

        self.assertEqual(data, result)
示例#3
0
 def test_vbkv_empty(self):
     with self.assertRaises(ValueError):
         vdf.vbkv_loads(b'')
示例#4
0
 def test_vbkv_loads_invalid_checksum(self):
     with self.assertRaises(ValueError):
         vdf.vbkv_loads(b'VBKV\x01\x02\x03\x04\x00a\x00\x0b\x0b')
示例#5
0
 def test_vbkv_loads_invalid_header(self):
     with self.assertRaises(ValueError):
         vdf.vbkv_loads(b'DD1235764tdffhghsdf')
示例#6
0
 def test_vbkv_empty(self):
     with self.assertRaises(ValueError):
         vdf.vbkv_loads(b'')
示例#7
0
 def test_vbkv_loads_invalid_checksum(self):
     with self.assertRaises(ValueError):
         vdf.vbkv_loads(b'VBKV\x01\x02\x03\x04\x00a\x00\x0b\x0b')
示例#8
0
 def test_vbkv_loads_invalid_header(self):
     with self.assertRaises(ValueError):
         vdf.vbkv_loads(b'DD1235764tdffhghsdf')