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