File: stdlib_test.py

package info (click to toggle)
jsonpickle 3.0.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,184 kB
  • sloc: python: 6,088; javascript: 654; makefile: 90; sh: 17
file content (55 lines) | stat: -rw-r--r-- 1,663 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""Test miscellaneous objects from the standard library"""

import unittest
import uuid

import jsonpickle


class UUIDTestCase(unittest.TestCase):
    def test_random_uuid(self):
        u = uuid.uuid4()
        encoded = jsonpickle.encode(u)
        decoded = jsonpickle.decode(encoded)

        expect = u.hex
        actual = decoded.hex
        self.assertEqual(expect, actual)

    def test_known_uuid(self):
        expect = '28b56adbd18f44e2a5556bba2f23e6f6'
        exemplar = uuid.UUID(expect)
        encoded = jsonpickle.encode(exemplar)
        decoded = jsonpickle.decode(encoded)

        actual = decoded.hex
        self.assertEqual(expect, actual)


class BytesTestCase(unittest.TestCase):
    def test_bytestream(self):
        expect = (
            b'\x89HDF\r\n\x1a\n\x00\x00\x00\x00\x00\x08\x08\x00'
            b'\x04\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00'
            b'\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xffh'
            b'\x848\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff'
            b'\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00`\x00\x00'
            b'\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00'
            b'\x00\x88\x00\x00\x00\x00\x00\x00\x00\xa8\x02\x00'
            b'\x00\x00\x00\x00\x00\x01\x00\x01\x00'
        )
        encoded = jsonpickle.encode(expect)
        actual = jsonpickle.decode(encoded)
        self.assertEqual(expect, actual)


def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(UUIDTestCase))
    suite.addTest(unittest.makeSuite(BytesTestCase))
    return suite


if __name__ == '__main__':
    unittest.main(defaultTest='suite')