本文整理汇总了Python中xrootdpyfs.XRootDPyFile类的典型用法代码示例。如果您正苦于以下问题:Python XRootDPyFile类的具体用法?Python XRootDPyFile怎么用?Python XRootDPyFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XRootDPyFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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
示例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
示例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
示例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)
示例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()
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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]