本文整理汇总了Python中xrootdpyfs.XRootDPyFile类的典型用法代码示例。如果您正苦于以下问题:Python XRootDPyFile类的具体用法?Python XRootDPyFile怎么用?Python XRootDPyFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XRootDPyFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_writelines
def test_writelines(tmppath):
"""Test writelines()."""
xfile = XRootDPyFile(mkurl(join(tmppath, "data/multiline.txt")), 'r')
yfile = XRootDPyFile(mkurl(join(tmppath, "data/newfile.txt")), 'w+')
yfile.writelines(xfile.xreadlines())
xfile.seek(0), yfile.seek(0)
assert xfile.readlines() == yfile.readlines()
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:7,代码来源:test_xrdfile.py
示例2: test__is_open
def test__is_open(tmppath):
"""Test _is_open()"""
fd = get_tsta_file(tmppath)
full_path = fd['full_path']
xfile = XRootDPyFile(mkurl(full_path))
assert not xfile.closed
xfile.close()
assert xfile.closed
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:8,代码来源:test_xrdfile.py
示例3: test_open_close
def test_open_close(tmppath):
"""Test close() on an open file."""
fd = get_tsta_file(tmppath)
full_path = fd["full_path"]
xfile = XRootDPyFile(mkurl(full_path))
assert xfile
assert not xfile.closed
xfile.close()
assert xfile.closed
开发者ID:inveniosoftware,项目名称:xrootdpyfs,代码行数:9,代码来源:test_xrdfile.py
示例4: test_read_binary
def test_read_binary(tmppath):
"""Tests reading binary data from an existing file."""
fd = get_bin_testfile(tmppath)
fb = get_copy_file(fd, binary=True)
fp, fc = fd['full_path'], fd['contents']
fp2 = fb['full_path']
pfile = open(fp2, 'rb')
xfile = XRootDPyFile(mkurl(fp), 'rb')
assert xfile.read() == pfile.read() == fc
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:11,代码来源:test_xrdfile.py
示例5: test_truncate4
def test_truncate4(tmppath):
"""Verifies that truncate() raises errors on non-truncatable files."""
fd = get_mltl_file(tmppath)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path), 'r')
pytest.raises(IOError, xfile.truncate, 0)
xfile.close()
xfile = XRootDPyFile(mkurl(full_path), 'w-')
pytest.raises(IOError, xfile.truncate, 0)
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:11,代码来源:test_xrdfile.py
示例6: test_open_close
def test_open_close(tmppath):
"""Test close() on an open file."""
fd = get_tsta_file(tmppath)
full_path = fd['full_path']
xfile = XRootDPyFile(mkurl(full_path))
assert xfile
assert not xfile.closed
xfile.close()
assert xfile.closed
# Multiple calls to closed do nothing.
xfile.close()
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:11,代码来源:test_xrdfile.py
示例7: test_xreadlines
def test_xreadlines(tmppath):
"""Tests xreadlines()"""
fp = get_mltl_file(tmppath)['full_path']
xfile = XRootDPyFile(mkurl(fp), 'r')
rl = xfile.readlines()
xfile.seek(0)
xl = xfile.xreadlines()
assert xl != rl
assert list(xl) == rl
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:11,代码来源:test_xrdfile.py
示例8: test_init_readmode_basic
def test_init_readmode_basic(tmppath):
# Non-existing file causes what?
# Resource not found error.
fn, fp, fc = "nope", "data/", ""
full_path = join(tmppath, fp, fn)
pytest.raises(ResourceNotFoundError, XRootDPyFile, mkurl(full_path), mode="r")
# Existing file can be read?
fd = get_tsta_file(tmppath)
full_path, fc = fd["full_path"], fd["contents"]
xfile = XRootDPyFile(mkurl(full_path), mode="r")
assert xfile
assert xfile.read() == fc
开发者ID:inveniosoftware,项目名称:xrootdpyfs,代码行数:13,代码来源:test_xrdfile.py
示例9: test_init_readmode_basic
def test_init_readmode_basic(tmppath):
# Non-existing file causes what?
# Resource not found error.
fn, fp, fc = 'nope', 'data/', ''
full_path = join(tmppath, fp, fn)
pytest.raises(ResourceNotFoundError, XRootDPyFile, mkurl(full_path),
mode='r')
# Existing file can be read?
fd = get_tsta_file(tmppath)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path), mode='r')
assert xfile
assert xfile.read() == fc
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:14,代码来源:test_xrdfile.py
示例10: test_init_writemode_basic
def test_init_writemode_basic(tmppath):
# Non-existing file is created.
fn, fp, fc = "nope", "data/", ""
full_path = join(tmppath, fp, fn)
xfile = XRootDPyFile(mkurl(full_path), mode="w+")
assert xfile
assert xfile.read() == fc
# Existing file is truncated
fd = get_tsta_file(tmppath)
full_path = fd["full_path"]
xfile = XRootDPyFile(mkurl(full_path), mode="w+")
assert xfile
assert xfile.read() == ""
assert xfile.size == 0
assert xfile.tell() == 0
开发者ID:inveniosoftware,项目名称:xrootdpyfs,代码行数:16,代码来源:test_xrdfile.py
示例11: test_init_writemode_basic
def test_init_writemode_basic(tmppath):
# Non-existing file is created.
fn, fp, fc = 'nope', 'data/', ''
full_path = join(tmppath, fp, fn)
xfile = XRootDPyFile(mkurl(full_path), mode='w+')
assert xfile
assert xfile.read() == fc
# Existing file is truncated
fd = get_tsta_file(tmppath)
full_path = fd['full_path']
xfile = XRootDPyFile(mkurl(full_path), mode='w+')
assert xfile
assert xfile.read() == ''
assert xfile.size == 0
assert xfile.tell() == 0
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:16,代码来源:test_xrdfile.py
示例12: test_init_writemode
def test_init_writemode(tmppath):
"""Tests for opening files in 'w(+)'"""
fd = get_tsta_file(tmppath)
fp, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(fp), 'w')
pytest.raises(IOError, xfile.read)
xfile.seek(1)
conts = 'what'
xfile.write(conts)
assert xfile.tell() == 1 + len(conts)
assert xfile.size == 1 + len(conts)
xfile.close()
xfile = XRootDPyFile(mkurl(fp), 'r')
fc = xfile.read()
assert fc == '\x00'+conts
assert not fc == conts
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:17,代码来源:test_xrdfile.py
示例13: test_init_writemode
def test_init_writemode(tmppath):
"""Tests for opening files in 'w(+)'"""
fd = get_tsta_file(tmppath)
fp, fc = fd["full_path"], fd["contents"]
xfile = XRootDPyFile(mkurl(fp), "w")
pytest.raises(IOError, xfile.read)
xfile.seek(1)
conts = "what"
xfile.write(conts)
assert xfile.tell() == 1 + len(conts)
assert xfile.size == 1 + len(conts)
xfile.close()
xfile = XRootDPyFile(mkurl(fp), "r")
fc = xfile.read()
assert fc == "\x00" + conts
assert not fc == conts
开发者ID:inveniosoftware,项目名称:xrootdpyfs,代码行数:17,代码来源:test_xrdfile.py
示例14: test_read_existing
def test_read_existing(tmppath):
"""Test read() on an existing non-empty file."""
fd = get_tsta_file(tmppath)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path))
res = xfile.read()
assert res == fc
# After having read the entire file, the file pointer is at the
# end of the file and consecutive reads return the empty string.
assert xfile.read() == ''
# reset ipp to start
xfile.seek(0)
assert xfile.read(1) == fc[0]
assert xfile.read(2) == fc[1:3]
overflow_read = xfile.read(len(fc))
assert overflow_read == fc[3:]
# Mock an error, yayy!
fake_status = {
"status": 3,
"code": 0,
"ok": False,
"errno": errno.EREMOTE,
"error": True,
"message": '[FATAL] Remote I/O Error',
"fatal": True,
"shellcode": 51
}
xfile._file.read = Mock(return_value=(XRootDStatus(fake_status), None))
pytest.raises(IOError, xfile.read)
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:32,代码来源:test_xrdfile.py
示例15: test_truncate3
def test_truncate3(tmppath):
"""Test truncate(0 < size < self._size)."""
fd = get_mltl_file(tmppath)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path), 'r+')
initcp = xfile.tell()
newsiz = len(fc)//2
xfile.truncate(newsiz)
assert xfile.tell() == initcp
xfile.seek(0) # reset the internal pointer before reading
assert xfile.read() == fc[:newsiz]
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:13,代码来源:test_xrdfile.py
示例16: test_truncate2
def test_truncate2(tmppath):
"""Test truncate(self._size)."""
fd = get_tsta_file(tmppath)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path), 'r+')
conts = xfile.read()
assert conts == fc
newsize = xfile.size
xfile.truncate(newsize)
assert xfile.tell() == newsize
assert xfile.size == len(fc)
xfile.seek(0)
assert xfile.read() == conts
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:14,代码来源:test_xrdfile.py
示例17: test_init_newline
def test_init_newline(tmppath):
"""Tests fs.open() with specified newline parameter."""
fd = get_tsta_file(tmppath)
fp, fc = fd["full_path"], fd["contents"]
xfile = XRootDPyFile(mkurl(fp))
assert xfile._newline == "\n"
xfile.close()
xfile = XRootDPyFile(mkurl(fp), newline="\n")
assert xfile._newline == "\n"
xfile.close()
pytest.raises(UnsupportedError, XRootDPyFile, mkurl(fp), mode="r", newline="what")
开发者ID:inveniosoftware,项目名称:xrootdpyfs,代码行数:14,代码来源:test_xrdfile.py
示例18: test_init_newline
def test_init_newline(tmppath):
"""Tests fs.open() with specified newline parameter."""
fd = get_tsta_file(tmppath)
fp, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(fp))
assert xfile._newline == '\n'
xfile.close()
xfile = XRootDPyFile(mkurl(fp), newline='\n')
assert xfile._newline == '\n'
xfile.close()
pytest.raises(UnsupportedError, XRootDPyFile, mkurl(fp), mode='r',
newline='what')
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:15,代码来源:test_xrdfile.py
示例19: test_size
def test_size(tmppath):
"""Tests for the size property size."""
fd = get_tsta_file(tmppath)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path))
assert xfile.size == len(fc)
# Length of empty file
xfile = XRootDPyFile(mkurl(join(tmppath, fd['dir'], 'whut')), 'w+')
assert xfile.size == len('')
# Length of multiline file
fd = get_mltl_file(tmppath)
fpp, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(fpp))
assert xfile.size == len(fc)
# Mock the error
fake_status = {
"status": 3,
"code": 0,
"ok": False,
"errno": errno.EREMOTE,
"error": True,
"message": '[FATAL] Remote I/O Error',
"fatal": True,
"shellcode": 51
}
xfile.close()
xfile = XRootDPyFile(mkurl(full_path))
xfile._file.stat = Mock(return_value=(XRootDStatus(fake_status), None))
try:
xfile.size
assert False
except IOError:
assert True
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:37,代码来源:test_xrdfile.py
示例20: test_readwrite_unicode
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()
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:35,代码来源:test_xrdfile.py
注:本文中的xrootdpyfs.XRootDPyFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论