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