def test_seek(self): fileno, path = tempfile.mkstemp() s = b'a' * 1024 os.write(fileno, b'B' * 15) os.write(fileno, s) os.close(fileno) try: with open(path, 'rb') as f: f.seek(15) native_data = f.read(1024) with open(path, 'rb') as f_raw: f = FileObject(f_raw, 'rb') if hasattr(f, 'seekable'): # Py3 self.assertTrue(f.seekable()) f.seek(15) self.assertEqual(15, f.tell()) fileobj_data = f.read(1024) self.assertEqual(native_data, s) self.assertEqual(native_data, fileobj_data) finally: os.remove(path)
def test_seek(self): fileno, path = tempfile.mkstemp('.gevent.test__fileobject.test_seek') self.addCleanup(os.remove, path) s = b'a' * 1024 os.write(fileno, b'B' * 15) os.write(fileno, s) os.close(fileno) with open(path, 'rb') as f: f.seek(15) native_data = f.read(1024) with open(path, 'rb') as f_raw: try: f = FileObject(f_raw, 'rb') except ValueError: # libuv on Travis can raise EPERM # from FileObjectPosix. I can't produce it on mac os locally, # don't know what the issue is. This started happening on Jan 19, # in the branch that caused all watchers to be explicitly closed. # That shouldn't have any effect on io watchers, though, which were # already being explicitly closed. reraiseFlakyTestRaceConditionLibuv() if PY3 or FileObject is not FileObjectThread: self.assertTrue(f.seekable()) f.seek(15) self.assertEqual(15, f.tell()) fileobj_data = f.read(1024) self.assertEqual(native_data, s) self.assertEqual(native_data, fileobj_data)