def test_corrupt_index(self, tmpfile): with io.open(tmpfile, 'wb') as f: f.write(FORMAT_STRING) write_i64(f, FORMAT_VERSION) f.write(b'foo') pytest.raises_regexp(IOError, 'unable to read index', File, tmpfile)
def test_read_write_i64(): stream = BytesIO() write_i64(stream, 10) assert stream.tell() == 8 stream.seek(0) assert read_i64(stream) == 10 write_i64(stream, 11, 12, 13) assert stream.tell() == 32 stream.seek(8) assert read_i64(stream, 2) == (11, 12) assert read_i64(stream, 1) == (13,) assert read_i64(stream, 0) == ()
def test_is_blox(tmpfile): assert is_blox(tmpfile) assert not is_blox('/foo/bar/baz') with io.open(tmpfile, 'wb') as f: f.write(b'foo') assert not is_blox(tmpfile) with io.open(tmpfile, 'wb') as f: f.write(FORMAT_STRING) assert not is_blox(tmpfile) with io.open(tmpfile, 'wb') as f: f.write(FORMAT_STRING) write_i64(f, FORMAT_VERSION) assert is_blox(tmpfile)
def test_format_signature(self, tmpfile): with io.open(tmpfile, 'wb') as f: f.write(b'foo') pytest.raises_regexp(IOError, 'unrecognized file format', File, tmpfile) with open(tmpfile, 'wb') as f: f.write(FORMAT_STRING) f.write(b'foo') pytest.raises_regexp(IOError, 'unable to read file version', File, tmpfile) with open(tmpfile, 'wb') as f: f.write(FORMAT_STRING) write_i64(f, 0) pytest.raises_regexp(IOError, r'incompatible version: 0 \(expected {}\)' .format(FORMAT_VERSION), File, tmpfile)
def _write_index(self): self._handle.truncate() write_json(self._handle, self._index) write_i64(self._handle, self._seek)
def _write_signature(self): self._handle.seek(0) self._handle.write(FORMAT_STRING) write_i64(self._handle, FORMAT_VERSION) self._seek = 16