本文整理汇总了Python中os.SEEK_DATA属性的典型用法代码示例。如果您正苦于以下问题:Python os.SEEK_DATA属性的具体用法?Python os.SEEK_DATA怎么用?Python os.SEEK_DATA使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类os
的用法示例。
在下文中一共展示了os.SEEK_DATA属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fs_holes
# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_DATA [as 别名]
def test_fs_holes(self):
# Even if the filesystem doesn't report holes,
# if the OS supports it the SEEK_* constants
# will be defined and will have a consistent
# behaviour:
# os.SEEK_DATA = current position
# os.SEEK_HOLE = end of file position
with open(support.TESTFN, 'r+b') as fp:
fp.write(b"hello")
fp.flush()
size = fp.tell()
fno = fp.fileno()
try :
for i in range(size):
self.assertEqual(i, os.lseek(fno, i, os.SEEK_DATA))
self.assertLessEqual(size, os.lseek(fno, i, os.SEEK_HOLE))
self.assertRaises(OSError, os.lseek, fno, size, os.SEEK_DATA)
self.assertRaises(OSError, os.lseek, fno, size, os.SEEK_HOLE)
except OSError :
# Some OSs claim to support SEEK_HOLE/SEEK_DATA
# but it is not true.
# For instance:
# http://lists.freebsd.org/pipermail/freebsd-amd64/2012-January/014332.html
raise unittest.SkipTest("OSError raised!")
示例2: test_seek_unsupported
# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_DATA [as 别名]
def test_seek_unsupported(self, pyqiodev):
"""Test seeking with unsupported whence arguments."""
# pylint: disable=no-member,useless-suppression
if hasattr(os, 'SEEK_HOLE'):
whence = os.SEEK_HOLE
elif hasattr(os, 'SEEK_DATA'):
whence = os.SEEK_DATA
# pylint: enable=no-member,useless-suppression
else:
pytest.skip("Needs os.SEEK_HOLE or os.SEEK_DATA available.")
pyqiodev.open(QIODevice.ReadOnly)
with pytest.raises(io.UnsupportedOperation):
pyqiodev.seek(0, whence)