Example #1
0
    def test_SuccessfulDecompose(self):
        frames = [
            handling.Data(b"\x01\x02\x03"),
            handling.Data(b"Hello world!"),
            handling.Data(b"")
        ]

        packet = b"\x00\x05\x01\x02\x03\x00\x0eHello world!\x00\x02"

        self.assertEqual(handling.decompose(packet), frames)
Example #2
0
    def test_SuccessfulWithTags(self):
        tree = handling.HandlerNode({
            3:
            handling.HandlerNode(
                {
                    0:
                    handling.HandlerNode(
                        {1: handling.HandlerNode({5: (lambda _, tags: tags)})},
                        "two")
                }, "one")
        })

        self.assertEqual(tree(handling.Data(b"\x03\x00\x01\x05")),
                         ["one", "two"])
Example #3
0
 def test_NotEmptyString(self):
     self.assertEqual(
         handling.Data(b"\x00\x0cHello world!").takeString(),
         "Hello world!")
Example #4
0
 def test_EmptyString(self):
     self.assertEqual(handling.Data(b"\x00\x00").takeString(), "")
Example #5
0
 def test_TooSmall(self):
     with self.assertRaises(handling.EmptyBuffer):
         handling.Data(b"\x01").takeString()
Example #6
0
 def test_SignedAndLarger(self):
     self.assertEqual(
         handling.Data(b"\xff\x00\x00").takeNumeric(1, signed=True), -1)
Example #7
0
 def setUp(self):
     self.data = handling.Data(b"\x01\x02\x03")
Example #8
0
 def test_NonZero(self):
     self.assertTrue(handling.Data(b"\x37").takeBool())
Example #9
0
 def test_Zero(self):
     self.assertFalse(handling.Data(b"\x00").takeBool())
Example #10
0
 def test_NotEmpty(self):
     self.assertEqual(handling.Data(b"\x01\x02\x03").take(), 1)
Example #11
0
 def test_Empty(self):
     with self.assertRaises(handling.EmptyBuffer):
         handling.Data(b"").take()
Example #12
0
 def test_SuccessfulCall(self):
     data = handling.Data(b"\x03\x01\x02\x00")
     self.assertEqual(self.tree(data), [3, 1, 2, 0])
Example #13
0
 def test_EmptyBuffer(self):
     with self.assertRaises(handling.EmptyBuffer):
         self.tree(handling.Data(b"\x00" * 3))
Example #14
0
 def test_UnknownBranch(self):
     with self.assertRaises(handling.UnknownBranch):
         self.tree(handling.Data(b"\x01\x05\x00\x01"))