本文整理汇总了Python中xrootdpyfs.XRootDPyFile.flush方法的典型用法代码示例。如果您正苦于以下问题:Python XRootDPyFile.flush方法的具体用法?Python XRootDPyFile.flush怎么用?Python XRootDPyFile.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xrootdpyfs.XRootDPyFile
的用法示例。
在下文中一共展示了XRootDPyFile.flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_flush
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import flush [as 别名]
def test_flush(tmppath):
"""Tests for flush()"""
# Mostly it just ensures calling it doesn't crash the program.
fd = get_tsta_file(tmppath)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path), 'w')
writestr = 'whut'
xfile.flush()
xfile.seek(0, SEEK_END)
xfile.write(writestr)
xfile.flush()
xfile.close()
xfile = XRootDPyFile(mkurl(full_path), 'r')
assert xfile.read() == writestr
# Fake/mock an error response
fake_status = {
"status": 3,
"code": 0,
"ok": False,
"errno": errno.EREMOTE,
"error": True,
"message": '[FATAL] Remote I/O Error',
"fatal": True,
"shellcode": 51
}
# Assign mock return value to the file's sync() function
# (which is called by flush())
xfile._file.sync = Mock(return_value=(XRootDStatus(fake_status), None))
pytest.raises(IOError, xfile.flush)
示例2: test_readwrite_unicode
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import flush [as 别名]
def test_readwrite_unicode(tmppath):
"""Test read/write unicode."""
if sys.getdefaultencoding() != 'ascii':
# Python 2 only problem
raise AssertionError(
"Default system encoding is not ascii. This is likely due to some"
" imported module changing it using sys.setdefaultencoding."
)
fd = get_tsta_file(tmppath)
fb = get_copy_file(fd)
fp, dummy = fd['full_path'], fd['contents']
fp2 = fb['full_path']
unicodestr = u"æøå"
pfile = open(fp2, 'w')
xfile = XRootDPyFile(mkurl(fp), 'w')
pytest.raises(UnicodeEncodeError, pfile.write, unicodestr)
pytest.raises(UnicodeEncodeError, xfile.write, unicodestr)
xfile.close()
xfile = XRootDPyFile(mkurl(fp), 'w+', encoding='utf-8')
xfile.write(unicodestr)
xfile.flush()
xfile.seek(0)
assert unicodestr.encode('utf8') == xfile.read()
xfile.close()
xfile = XRootDPyFile(mkurl(fp), 'w+', errors='ignore')
xfile.write(unicodestr)
xfile.flush()
xfile.seek(0)
assert unicodestr.encode('ascii', 'ignore') == xfile.read()
xfile.close()