示例#1
0
    def test_filelike_dup_raises(self):
        self.mox.StubOutWithMock(os, 'fdopen')
        self.mox.StubOutWithMock(os, 'close')
        os.fdopen(mox.IsA(int), mox.IsA(str)).AndRaise(OSError)
        os.close(mox.IsA(int)).AndRaise(OSError)

        self.mox.ReplayAll()

        with RecordioTestBase.EphemeralFile('r+') as fp:
            fl = FileLike(fp)
            with pytest.raises(FileLike.Error):
                fl.dup()
示例#2
0
  def test_filelike_dup_raises(self):
    self.mox.StubOutWithMock(os, 'fdopen')
    self.mox.StubOutWithMock(os, 'close')
    os.fdopen(mox.IsA(int), mox.IsA(str)).AndRaise(OSError)
    os.close(mox.IsA(int)).AndRaise(OSError)

    self.mox.ReplayAll()

    with RecordioTestBase.EphemeralFile('r+') as fp:
      fl = FileLike(fp)
      with pytest.raises(FileLike.Error):
        fl.dup()
示例#3
0
 def test_premature_end_of_stream(self):
     with self.EphemeralFile('r+') as fp:
         fpr = FileLike.get(fp)
         fpr = fp
         fpr.write(struct.pack('>L', 1))
         fpr.seek(0)
         rr = RecordReader(fpr)
         with pytest.raises(RecordIO.PrematureEndOfStream):
             rr.read()
示例#4
0
 def test_premature_end_of_stream(self):
   with self.EphemeralFile('r+') as fp:
     fpr = FileLike.get(fp)
     fpr = fp
     fpr.write(struct.pack('>L', 1))
     fpr.seek(0)
     rr = RecordReader(fpr)
     with pytest.raises(RecordIO.PrematureEndOfStream):
       rr.read()
示例#5
0
    def test_record_too_large(self):
        with self.EphemeralFile('r+') as fp:
            fpw = FileLike.get(fp)
            fpw.write(struct.pack('>L', RecordIO.MAXIMUM_RECORD_SIZE + 1))
            fpw.write('a')
            fpw.flush()
            fpw.seek(0)

            rr = RecordReader(fp)
            with pytest.raises(RecordIO.RecordSizeExceeded):
                rr.read()
示例#6
0
  def test_record_too_large(self):
    with self.EphemeralFile('r+') as fp:
      fpw = FileLike.get(fp)
      fpw.write(struct.pack('>L', RecordIO.MAXIMUM_RECORD_SIZE+1))
      fpw.write('a')
      fpw.flush()
      fpw.seek(0)

      rr = RecordReader(fp)
      with pytest.raises(RecordIO.RecordSizeExceeded):
        rr.read()
示例#7
0
    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
示例#8
0
    def test_bad_header_size(self):
        with self.EphemeralFile('r+') as fp:
            fpw = FileLike.get(fp)
            fpw.write(struct.pack('>L', RecordIO.MAXIMUM_RECORD_SIZE))
            fpw._fp.truncate(RecordIO.RECORD_HEADER_SIZE - 1)
            fpw.flush()
            fpw.seek(0)

            rr = RecordReader(fp)
            with pytest.raises(RecordIO.PrematureEndOfStream):
                rr.read()
            assert fpw.tell() != 0
            fpw.seek(0)
            assert rr.try_read() is None
            assert fpw.tell() == 0
示例#9
0
  def test_bad_header_size(self):
    with self.EphemeralFile('r+') as fp:
      fpw = FileLike.get(fp)
      fpw.write(struct.pack('>L', RecordIO.MAXIMUM_RECORD_SIZE))
      fpw._fp.truncate(RecordIO.RECORD_HEADER_SIZE - 1)
      fpw.flush()
      fpw.seek(0)

      rr = RecordReader(fp)
      with pytest.raises(RecordIO.PrematureEndOfStream):
        rr.read()
      assert fpw.tell() != 0
      fpw.seek(0)
      assert rr.try_read() is None
      assert fpw.tell() == 0