Example #1
0
    def test_write_frame_slow_for_standard_properties(self):
        HeaderFrame.DEFAULT_PROPERTIES = False
        bit_field = 0
        properties = {}
        now = datetime.utcfromtimestamp(
            long(time.mktime(datetime.now().timetuple())))
        for pname, ptype, reader, writer, mask in HeaderFrame.PROPERTIES:
            bit_field |= mask

            if ptype == 'shortstr':
                properties[pname] = pname
            elif ptype == 'octet':
                properties[pname] = 42
            elif ptype == 'timestamp':
                properties[pname] = now
            elif ptype == 'table':
                properties[pname] = {'foo': 'bar'}

        frame = HeaderFrame(42, 5, 6, 7, properties)
        buf = bytearray()
        frame.write_frame(buf)
        HeaderFrame.DEFAULT_PROPERTIES = True

        reader = Reader(buf)
        assert_equals(2, 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())
        assert_equals(7, reader.read_longlong())
        assert_equals(0b1111111111111100, reader.read_short())

        for pname, ptype, rfunc, wfunc, mask in HeaderFrame.PROPERTIES:
            if ptype == 'shortstr':
                assertEquals(pname, reader.read_shortstr())
            elif ptype == 'octet':
                assertEquals(42, reader.read_octet())
            elif ptype == 'timestamp':
                assertEquals(now, reader.read_timestamp())
            elif ptype == 'table':
                assertEquals({'foo': 'bar'}, reader.read_table())

        end_pos = reader.tell()
        assert_equals(size, end_pos - start_pos)
        assert_equals(0xce, reader.read_octet())
Example #2
0
    def test_write_frame_slow_for_standard_properties(self):
        HeaderFrame.DEFAULT_PROPERTIES = False
        bit_field = 0
        properties = {}
        now = datetime.utcfromtimestamp(
            long(time.mktime(datetime.now().timetuple())))
        for pname, ptype, reader, writer, mask in HeaderFrame.PROPERTIES:
            bit_field |= mask

            if ptype == 'shortstr':
                properties[pname] = pname
            elif ptype == 'octet':
                properties[pname] = 42
            elif ptype == 'timestamp':
                properties[pname] = now
            elif ptype == 'table':
                properties[pname] = {'foo': 'bar'}

        frame = HeaderFrame(42, 5, 6, 7, properties)
        buf = bytearray()
        frame.write_frame(buf)
        HeaderFrame.DEFAULT_PROPERTIES = True

        reader = Reader(buf)
        assert_equals(2, 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())
        assert_equals(7, reader.read_longlong())
        assert_equals(0b1111111111111100, reader.read_short())

        for pname, ptype, rfunc, wfunc, mask in HeaderFrame.PROPERTIES:
            if ptype == 'shortstr':
                assertEquals(pname, reader.read_shortstr())
            elif ptype == 'octet':
                assertEquals(42, reader.read_octet())
            elif ptype == 'timestamp':
                assertEquals(now, reader.read_timestamp())
            elif ptype == 'table':
                assertEquals({'foo': 'bar'}, reader.read_table())

        end_pos = reader.tell()
        assert_equals(size, end_pos - start_pos)
        assert_equals(0xce, reader.read_octet())
Example #3
0
 def test_read_longlong(self):
     b = Reader('\xff\x00\xff\x00\xff\x00\xff\x00')
     assert_equals(18374966859414961920L, b.read_longlong())
     assert_raises(Reader.BufferUnderflow, b.read_longlong)