本文整理汇总了Python中xrootdpyfs.XRootDPyFile.truncate方法的典型用法代码示例。如果您正苦于以下问题:Python XRootDPyFile.truncate方法的具体用法?Python XRootDPyFile.truncate怎么用?Python XRootDPyFile.truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xrootdpyfs.XRootDPyFile
的用法示例。
在下文中一共展示了XRootDPyFile.truncate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_truncate5
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
def test_truncate5(tmppath):
"""Test truncate() (no arg)."""
fd = get_tsta_file(tmppath)
fb = get_copy_file(fd)
fp, fc = fd['full_path'], fd['contents']
fp2 = fb['full_path']
xfa = XRootDPyFile(mkurl(fp), 'r+')
xfb = XRootDPyFile(mkurl(fp2), 'r+')
acnts = xfa.read()
assert acnts == xfb.read()
# internal pointer starts at 0 in all 'r' modes.
xtell = xfa.tell()
assert xfa.tell() == xfb.tell()
# f.truncate() and f.truncate(self.tell()) should be equivalent
xfa.truncate(), xfb.truncate(xfb.tell())
assert xfa.size == xfb.size
assert xfa.tell() == xtell
assert xfb.tell() == xtell
assert xfb.read() == u''
assert xfa.read() == u''
xfa.seek(0), xfb.seek(0)
are = xfa.read()
assert are == fc
assert are == xfb.read()
示例2: test_write_binary
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
def test_write_binary(tmppath):
"""Tests for writing binary data to file."""
fd = get_bin_testfile(tmppath)
fp, fc = fd['full_path'], fd['contents']
# Test w/ confirmed binary data read from a binary file
xf_new = XRootDPyFile(mkurl(join(tmppath, 'data/tmp_bin')), 'wb+')
xf_new.write(fc), xf_new.seek(0)
assert xf_new.read() == fc
xf_new.close()
# Verify persistence.
xf_new = XRootDPyFile(mkurl(join(tmppath, 'data/tmp_bin')), 'r+')
assert xf_new.read() == fc
# Test truncate
xf_new.truncate()
xf_new.seek(0)
assert xf_new.read() == fc
xf_new.close()
# Test with bytearray
xf_new = XRootDPyFile(mkurl(join(tmppath, 'data/tmp_bin')), 'wb+')
barr = bytearray(range(0, 5))
xf_new.write(barr), xf_new.seek(0)
assert xf_new.read() == barr
xf_new.close()
# Verify persistence.
xf_new = XRootDPyFile(mkurl(join(tmppath, 'data/tmp_bin')), 'r')
assert xf_new.read() == barr
xf_new.close()
示例3: test_truncate_read_write2
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
def test_truncate_read_write2(tmppath):
"""Tests behaviour of writing after seek(0) after
reading after truncating."""
fd = get_tsta_file(tmppath)
fb = get_copy_file(fd)
fp, fc = fd['full_path'], fd['contents']
fp2 = fb['full_path']
sp = len(fc)//2
wstr = "I am the string"
pfile = open(fp2, 'r+')
xfile = XRootDPyFile(mkurl(fp), 'r+')
xfile.truncate(sp), pfile.truncate(sp)
assert xfile.tell() == pfile.tell()
assert xfile.read() == pfile.read()
assert xfile.tell() == pfile.tell()
xfile.seek(0), pfile.seek(0)
assert xfile.tell() == pfile.tell()
assert xfile.read() == pfile.read()
xfile.seek(0), pfile.seek(0)
xfile.write(wstr), pfile.write(wstr)
assert xfile.tell() == pfile.tell()
assert xfile.read() == pfile.read()
xfile.seek(0), pfile.seek(0)
assert xfile.read() == pfile.read()
示例4: test_seek_args
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
def test_seek_args(tmppath):
"""Test seek() with a non-default whence argument."""
fd = get_tsta_file(tmppath)
fb = get_copy_file(fd)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path), 'r+')
pfile = open(fb['full_path'], 'r+')
xfile.truncate(3), pfile.truncate(3)
xfile.seek(2, SEEK_END), pfile.seek(2, SEEK_END)
assert xfile.tell() == pfile.tell()
xfile.seek(3, SEEK_CUR), pfile.seek(3, SEEK_CUR)
assert xfile.tell() == pfile.tell()
xfile.seek(8, SEEK_SET), pfile.seek(8, SEEK_SET)
assert xfile.tell() == pfile.tell()
xfile.truncate(3), pfile.truncate(3)
xfile.read(), pfile.read()
assert xfile.tell() == pfile.tell()
xfile.seek(8, SEEK_END), pfile.seek(8, SEEK_END)
assert xfile.tell() == pfile.tell()
xfile.seek(4, SEEK_CUR), pfile.seek(4, SEEK_CUR)
assert xfile.tell() == pfile.tell()
pytest.raises(NotImplementedError, xfile.seek, 0, 8)
示例5: test_truncate3
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
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]
示例6: test_truncate2
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
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
示例7: test_truncate1
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
def test_truncate1(tmppath):
"""Test truncate(0)."""
fd = get_tsta_file(tmppath)
full_path, fc = fd['full_path'], fd['contents']
xfile = XRootDPyFile(mkurl(full_path), 'r+')
# r+ opens for r/w, and won't truncate the file automatically.
assert xfile.read() == fc
assert xfile.tell() == len(fc)
xfile.seek(0) # Reset ipp.
assert xfile.tell() == 0
# Truncate it to size 0.
xfile.truncate(0)
assert xfile.size == 0
assert xfile.tell() == 0
assert xfile.read() == ''
assert xfile.tell() == 0
xfile.close()
# Re-open same file.
xfile = XRootDPyFile(mkurl(full_path), 'r+')
assert xfile.size == 0
assert xfile.read() == ''
# Truncate it again!
xfile.truncate(0)
assert xfile.size == 0
assert xfile.read() == ''
# Truncate it twice.
xfile.truncate(0)
assert xfile.size == 0
assert xfile.read() == ''
# Truncate to 1.
xfile.truncate(1)
assert xfile.tell() == 0
assert xfile.size == 1
xfile.seek(0)
assert xfile.read() == '\x00'
assert xfile.tell() == 1
xfile.close()
xfile = XRootDPyFile(mkurl(full_path), 'r+')
assert xfile.size == 1
assert xfile.read() == '\x00'
# Mock it.
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.truncate = Mock(return_value=(XRootDStatus(fake_status), None))
pytest.raises(IOError, xfile.truncate, 0)
示例8: test_seek_past_eof_wr
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
def test_seek_past_eof_wr(tmppath):
"""Tests read/write/truncate behaviour after seeking past the EOF, 'w+'"""
fd = get_tsta_file(tmppath)
fb = get_copy_file(fd)
fp, fc = fd['full_path'], u''
fp2 = fb['full_path']
wstr = "www"
eof = len(fc)
skpnt = len(fc)+4
pfile = open(fp2, 'w+')
xfile = XRootDPyFile(mkurl(fp), 'w+')
xfile.seek(skpnt), pfile.seek(skpnt)
assert xfile.tell() == pfile.tell()
assert xfile.read() == pfile.read()
assert xfile.tell() == pfile.tell()
assert xfile.tell() == skpnt
xfile.write(wstr), pfile.write(wstr)
assert xfile.tell() == pfile.tell()
xfile.seek(eof), pfile.seek(eof)
assert xfile.read() == pfile.read() == '\x00'*(skpnt-eof) + wstr
assert xfile.tell() == pfile.tell()
xfile.seek(0), pfile.seek(0)
assert xfile.read() == pfile.read()
xfile.truncate(skpnt), pfile.truncate(skpnt)
assert xfile.tell() == pfile.tell() == skpnt + len(wstr)
xfile.write(wstr), pfile.write(wstr)
expected = fc + '\x00'*(skpnt-eof+len(wstr)) + wstr
xfile.seek(0), pfile.seek(0)
assert xfile.read() == pfile.read() == expected
示例9: test_seek_past_eof_rw
# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import truncate [as 别名]
def test_seek_past_eof_rw(tmppath):
"""Tests read/write/truncate behaviour after seeking past the EOF, 'r+'."""
fd = get_tsta_file(tmppath)
fb = get_copy_file(fd)
fp, fc = fd["full_path"], fd["contents"]
fp2 = fb["full_path"]
wstr = "www"
eof = len(fc)
skpnt = len(fc) + 4
pfile = open(fp2, "r+")
xfile = XRootDPyFile(mkurl(fp), "r+")
xfile.seek(skpnt), pfile.seek(skpnt)
assert xfile.tell() == pfile.tell()
assert xfile.read() == pfile.read()
assert xfile.tell() == pfile.tell()
assert xfile.tell() == skpnt
xfile.write(wstr), pfile.write(wstr)
assert xfile.tell() == pfile.tell()
xfile.seek(eof), pfile.seek(eof)
assert xfile.read() == pfile.read() == "\x00" * (skpnt - eof) + wstr
assert xfile.tell() == pfile.tell()
xfile.seek(0), pfile.seek(0)
assert xfile.read() == pfile.read()
xfile.truncate(skpnt), pfile.truncate(skpnt)
assert xfile.tell() == pfile.tell() == skpnt + len(wstr)
xfile.write(wstr), pfile.write(wstr)
expected = fc + "\x00" * (skpnt - eof + len(wstr)) + wstr
xfile.seek(0), pfile.seek(0)
assert xfile.read() == pfile.read() == expected