Example #1
0
    def test_basic_recordreader_try_read(self):
        test_string = "hello world"
        with self.EphemeralFile('r') as fp:
            fn = fp.name

            rr = RecordReader(fp)
            assert rr.try_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.try_read() == test_string
Example #2
0
  def test_basic_recordreader_try_read(self):
    test_string = "hello world"
    with self.EphemeralFile('r') as fp:
      fn = fp.name

      rr = RecordReader(fp)
      assert rr.try_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.try_read() == test_string
Example #3
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
Example #4
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