Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
  def test_append_fails_on_errors(self):
    record = 'hello'
    self.mox.StubOutWithMock(RecordIO.Writer, 'do_write')
    RecordIO.Writer.do_write(mox.IsA(file), record, mox.IsA(StringCodec)).AndRaise(IOError)
    RecordIO.Writer.do_write(mox.IsA(file), record, mox.IsA(StringCodec)).AndRaise(OSError)

    self.mox.ReplayAll()

    with RecordioTestBase.EphemeralFile('r+') as fp:
      assert RecordIO.Writer.append(fp.name, record, StringCodec()) == False
      assert RecordIO.Writer.append(fp.name, record, StringCodec()) == False
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 def test_string_codec(self):
     for bad_value in (None, 1234, object):
         with pytest.raises(RecordIO.InvalidTypeException):
             assert StringCodec().encode(bad_value)
         with pytest.raises(RecordIO.InvalidTypeException):
             assert StringCodec().decode(bad_value)