def test_basic_recordwriter_write(self): test_string = "hello world" with self.EphemeralFile('r+') as fp: rw = RecordWriter(fp) rw.write(test_string) fp.seek(0) rr = RecordReader(fp) assert rr.read() == test_string
def test_basic_recordwriter_write(): test_string = "hello world" with EphemeralFile('w') as fp: fn = fp.name rw = RecordWriter(fp) rw.write(test_string) rw.close() with open(fn) as fpr: rr = RecordReader(fpr) assert rr.read() == test_string
def test_basic_recordwriter_write_synced_raises(self): test_string = "hello world" self.mox.StubOutWithMock(os, 'fsync') with RecordioTestBase.EphemeralFile('r+') as fp: os.fsync(fp.fileno()).AndRaise(OSError) self.mox.ReplayAll() rw = RecordWriter(FileLike(fp)) rw.set_sync(True) rw.write(test_string) fp.seek(0) rr = RecordReader(fp) assert rr.read() == test_string
def test_basic_recordreader_read(self): test_string = "hello world" with self.EphemeralFile('r') as fp: fn = fp.name rr = RecordReader(fp) assert rr.read() is None rr.close() with open(fn, 'w') as fpw: rw = RecordWriter(fpw) rw.write(test_string) with open(fn) as fpr: rr = RecordReader(fpr) assert rr.read() == test_string
def test_recordwriter_framing(self): test_string_1 = "hello world" test_string_2 = "ahoy ahoy, bonjour" with self.EphemeralFile('w') as fp: fn = fp.name rw = RecordWriter(fp) rw.write(test_string_1) rw.close() with open(fn, 'a') as fpa: rw = RecordWriter(fpa) rw.write(test_string_2) with open(fn) as fpr: rr = RecordReader(fpr) assert rr.read() == test_string_1 assert rr.read() == test_string_2