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_recordwriter_initializing(self): for mode in ('a', 'r+', 'w'): with self.EphemeralFile(mode) as fp: try: RecordWriter(fp) except Exception as e: assert False, ( "Failed to initialize RecordWriter in '%s' mode (exception: %s)" % (mode, e))
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
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_raises_on_readonly_file(self): with self.EphemeralFile('r') as fp: with pytest.raises(RecordIO.InvalidFileHandle): RecordWriter(fp)
def test_raises_if_initialized_with_nil_filehandle(self): with pytest.raises(RecordIO.InvalidFileHandle): RecordWriter(None) with pytest.raises(RecordIO.InvalidFileHandle): RecordReader(None)
def test_recordwriter_works_with_write(): with EphemeralFile('w') as fp: try: RecordWriter(fp) except: assert False, 'Failed to initialize RecordWriter in r+ mode'
def test_raises_on_nonfile(): with pytest.raises(RecordIO.InvalidFileHandle): RecordWriter('/tmp/poop') with pytest.raises(RecordIO.InvalidFileHandle): RecordReader('/tmp/poop')