Esempio n. 1
0
 def test_pack(self):
     for o in DATA:
         self.assertEqual(
             pyparcel.pack(o),
             struct.pack(
                 "ifq{}s".format(len(o.c)), o.a, o.b, len(o.c), o.c.encode(ENCODING)
             ),
         )
Esempio n. 2
0
 def test_tuple_of_tuple_pack_unpack(self):
     structure = tuple([
         tuple([int()] * i) for i in range(len(DATA[0]),
                                           len(DATA[-1]) + 1)
     ])
     self.assertEqual(
         tuple(DATA), pyparcel.unpack(pyparcel.pack(tuple(DATA)),
                                      structure))
Esempio n. 3
0
    def test_pack_unpack(self):

        data: List[int] = [
            "",
            "Hello",
            "World",
            "This is a very very very long string",
            "a" * 2**20,
        ]

        for i in data:
            self.assertEqual(i, pyparcel.unpack(pyparcel.pack(i), str()))
Esempio n. 4
0
def main():
    foo: Foo = Foo(8, 5.7, "Hello World")  # Foo(int, float, str)
    data: bytes = pyparcel.pack(
        foo)  # b'\x08\x00\x00\x00ff\xb6@\x0b\x00\x00\x00Hello World'

    # ...

    bar: Foo = Foo()
    pyparcel.unpack(data, bar)  # foo == bar
    # or
    baz: Foo = pyparcel.unpack(data, Foo())  # foo == baz

    assert foo == bar == baz
Esempio n. 5
0
 def test_pack(self):
     data: List[int] = [
         "",
         "Hello",
         "World",
         "Hello World",
         " ",
         "Some sentence here.",
         "abcdefghijklmnopqrstuvwxyz",
         "123456789",
         "`-=[]\\;',./~_+{}|:\"<>?",
         "a" * 2**20,
         " " * 2**20,
     ]
     for i in data:
         self.assertEqual(
             pyparcel.pack(i),
             struct.pack("q{}s".format(len(i)), len(i), i.encode(ENCODING)),
         )
Esempio n. 6
0
    def test_pack_unpack(self):

        data: List[int] = [
            -12345.56789,
            -53.56,
            -30.4,
            -20.5,
            -5.7,
            -1.0,
            -0.2,
            0.0,
            0.2,
            1.0,
            5.7,
            30.4,
            53.56,
            12345.56789,
        ]
        for i in data:
            self.assertEqual(
                round(i, FLOATING_POINT_ACCURACY),
                round(pyparcel.unpack(pyparcel.pack(i), float()),
                      FLOATING_POINT_ACCURACY),
            )
Esempio n. 7
0
 def test_pack_unpack(self):
     for o in DATA:
         self.assertEqual(o, pyparcel.unpack(pyparcel.pack(o), ExampleClassA()))
Esempio n. 8
0
 def test_pack_unpack(self):
     for i in DATA:
         self.assertEqual(i, pyparcel.unpack(pyparcel.pack(i), int()))
Esempio n. 9
0
 def test_pack(self):
     for i in DATA:
         self.assertEqual(pyparcel.pack(i), struct.pack("i", i))
Esempio n. 10
0
 def test_pack_unpack(self):
     for i in DATA:
         self.assertEqual(
             i, pyparcel.unpack(pyparcel.pack(i), tuple([int()] * len(i))))
Esempio n. 11
0
 def test_pack(self):
     for i in DATA:
         assert pyparcel.pack(i) == struct.pack("f", i)