def test_basic_recordwriter_write_synced(self): test_string = "hello world" with self.EphemeralFile('r+') as fp: RecordWriter.do_write(fp, test_string, StringCodec(), sync=True) fp.seek(0) rr = RecordReader(fp) assert rr.read() == test_string
def test_basic_recordwriter_write_synced(self): test_string = "hello world" with self.EphemeralFile('r+') as fp: RecordWriter.do_write(fp, test_string, StringCodec(), sync=True) fp.seek(0) rr = RecordReader(fp) assert rr.read() == test_string
def test_basic_recordreader_iterator(self): test_strings = ["hello", "world", "etc"] with self.EphemeralFile('r+') as fp: for string in test_strings: RecordWriter.do_write(fp, string, StringCodec(), sync=True) fp.seek(0) rr = RecordReader(fp) assert list(rr) == test_strings
def test_basic_recordreader_iterator(self): test_strings = ["hello", "world", "etc"] with self.EphemeralFile('r+') as fp: for string in test_strings: RecordWriter.do_write(fp, string, StringCodec(), sync=True) fp.seek(0) rr = RecordReader(fp) assert list(rr) == test_strings
def test_basic_recordwriter_write_synced(): test_string = "hello world" with EphemeralFile('w') as fp: fn = fp.name RecordWriter.do_write(fp, test_string, RecordIO.StringCodec(), sync=True) with open(fn) as fpr: rr = RecordReader(fpr) assert rr.read() == test_string
def test_basic_recordwriter_write_fail(self): test_string = "hello" header = struct.pack('>L', len(test_string)) fp = self.mox.CreateMock(file) fp.write(header).AndRaise(IOError) fp.write(header).AndRaise(OSError) self.mox.ReplayAll() assert RecordWriter.do_write(fp, test_string, StringCodec()) == False assert RecordWriter.do_write(fp, test_string, StringCodec()) == False
def test_basic_recordwriter_write_fail(self): test_string = "hello" header = struct.pack('>L', len(test_string)) fp = self.mox.CreateMock(file) fp.write(header).AndRaise(IOError) fp.write(header).AndRaise(OSError) self.mox.ReplayAll() assert RecordWriter.do_write(fp, test_string, StringCodec()) == False assert RecordWriter.do_write(fp, test_string, StringCodec()) == False