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())
def test_read_timestamp(self): b = Reader('\x00\x00\x00\x00\x4d\x34\xc4\x71') d = datetime(2011, 1, 17, 22, 36, 33) assert_equals(d, b.read_timestamp())