Exemple #1
0
    def test_read(self):
        b = Reader('foo')
        assert_equals('foo', b.read(3))

        b = Reader('foo')
        assert_equals('fo', b.read(2))

        b = Reader('foo')
        assert_raises(Reader.BufferUnderflow, b.read, 4)
Exemple #2
0
    def test_write_frame(self):
        args = mock()
        expect(args.buffer).returns('hello')

        frame = MethodFrame(42, 5, 6, args)
        buf = bytearray()
        frame.write_frame(buf)

        reader = Reader(buf)
        assert_equals(1, reader.read_octet())
        assert_equals(42, reader.read_short())
        size = reader.read_long()
        start_pos = reader.tell()
        assert_equals(5, reader.read_short())
        assert_equals(6, reader.read_short())
        args_pos = reader.tell()
        assert_equals('hello', reader.read(size - (args_pos - start_pos)))
        assert_equals(0xce, reader.read_octet())