当前位置: 首页>>代码示例>>Python>>正文


Python XRootDPyFile.read方法代码示例

本文整理汇总了Python中xrootdpyfs.XRootDPyFile.read方法的典型用法代码示例。如果您正苦于以下问题:Python XRootDPyFile.read方法的具体用法?Python XRootDPyFile.read怎么用?Python XRootDPyFile.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xrootdpyfs.XRootDPyFile的用法示例。


在下文中一共展示了XRootDPyFile.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_seek_args

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [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)
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:31,代码来源:test_xrdfile.py

示例2: test_read_existing

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [as 别名]
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,代码行数:34,代码来源:test_xrdfile.py

示例3: test_readwrite_unicode

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [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()
开发者ID:inveniosoftware,项目名称:xrootdpyfs,代码行数:37,代码来源:test_xrdfile.py

示例4: test_truncate_read_write2

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [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()
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:31,代码来源:test_xrdfile.py

示例5: test_read_and_write

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [as 别名]
def test_read_and_write(tmppath):
    """Tests that the XRDFile behaves like a regular python file."""
    fd = get_tsta_file(tmppath)
    fb = get_copy_file(fd)
    fp, fc = fd['full_path'], fd['contents']
    fp2 = fb['full_path']

    seekpoint = len(fc)//2
    writestr = "Come what may in May this day says Ray all gay like Jay"

    pfile = open(fp2, 'r+')
    xfile = XRootDPyFile(mkurl(fp), 'r+')

    assert xfile.tell() == pfile.tell()
    assert xfile.read() == pfile.read()
    assert xfile.tell() == pfile.tell()

    xfile.seek(seekpoint), pfile.seek(seekpoint)
    assert xfile.tell() == pfile.tell()
    xfile.write(writestr), pfile.write(writestr)
    assert xfile.tell() == pfile.tell()
    assert xfile.read() == pfile.read()

    xfile.seek(0), pfile.seek(0)
    assert xfile.tell() == pfile.tell()
    assert xfile.read() == pfile.read()
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:28,代码来源:test_xrdfile.py

示例6: test_write_and_read

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [as 别名]
def test_write_and_read(tmppath):
    """Tests that the XRootDPyFile behaves like a regular python file in w+."""
    fd = get_tsta_file(tmppath)
    fb = get_copy_file(fd)
    fp, fc = fd['full_path'], fd['contents']
    fp2 = fb['full_path']

    writestr = "Hello fair mare what fine stairs."
    seekpoint = len(writestr)//2
    # In 'w' (and variant modes) the file's contents are deleted upon opening.

    pfile = open(fp2, 'w+')
    xfile = XRootDPyFile(mkurl(fp), 'w+')

    assert xfile.tell() == pfile.tell()
    assert xfile.read() == pfile.read()
    assert xfile.tell() == pfile.tell()

    xfile.write(writestr), pfile.write(writestr)
    assert xfile.tell() == pfile.tell()
    assert xfile.read() == pfile.read()
    xfile.seek(0), pfile.seek(0)
    assert xfile.read() == pfile.read()
    assert xfile.tell() == pfile.tell()

    xfile.seek(seekpoint), pfile.seek(seekpoint)
    assert xfile.tell() == pfile.tell()
    assert xfile.read() == pfile.read()
    assert xfile.tell() == pfile.tell()
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:31,代码来源:test_xrdfile.py

示例7: test_write_binary

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [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()
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:34,代码来源:test_xrdfile.py

示例8: test_truncate2

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [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
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:16,代码来源:test_xrdfile.py

示例9: test_flush

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [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)
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:35,代码来源:test_xrdfile.py

示例10: test_init_writemode_basic

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [as 别名]
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,代码行数:18,代码来源:test_xrdfile.py

示例11: test_init_append

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [as 别名]
def test_init_append(tmppath):
    """Test for files opened 'a'"""
    fd = get_tsta_file(tmppath)
    fp, fc = fd['full_path'], fd['contents']
    xfile = XRootDPyFile(mkurl(fp), 'a')
    assert xfile.mode == 'a'
    pytest.raises(IOError, xfile.read)
    assert xfile.tell() == len(fc)

    # Seeking is allowed, but writes still go on the end.
    xfile.seek(0)
    assert xfile.tell() == 0
    newcont = u'butterflies'
    xfile.write(newcont)
    assert xfile.tell() == len(fc) + len(newcont)
    # Can't read in this mode.
    xfile.close()
    xfile = XRootDPyFile(mkurl(fp), 'r')
    assert xfile.read() == fc + newcont

    xfile.close()
    xfile = XRootDPyFile(mkurl(fp), 'a')
    xfile.write(fc)
    xfile.seek(0)
    pytest.raises(IOError, xfile.read)
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:27,代码来源:test_xrdfile.py

示例12: test_init_writemode_basic

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [as 别名]
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,代码行数:18,代码来源:test_xrdfile.py

示例13: test_truncate1

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [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)
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:62,代码来源:test_xrdfile.py

示例14: test_seek_and_tell

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [as 别名]
def test_seek_and_tell(tmppath):
    """Basic tests for seek() and tell()."""
    fd = get_tsta_file(tmppath)
    full_path, fc = fd['full_path'], fd['contents']
    xfile = XRootDPyFile(mkurl(full_path))
    assert xfile.tell() == 0

    # Read file, then check the internal position pointer.
    conts = xfile.read()
    assert xfile.tell() == len(fc)
    assert conts == fc

    # Seek to beginning, then verify ipp.
    xfile.seek(0)
    assert xfile.tell() == 0
    assert xfile.read() == fc

    newpos = len(fc)//2
    xfile.seek(newpos)
    conts2 = xfile.read()
    assert conts2 == conts[newpos:]
    assert xfile.tell() == len(fc)

    # # Now with a multiline file!
    fd = get_mltl_file(tmppath)
    full_path, fc = fd['full_path'], fd['contents']
    xfile = XRootDPyFile(mkurl(full_path))

    assert xfile.tell() == 0
    newpos = len(fc)//3
    xfile.seek(newpos)
    assert xfile.tell() == newpos
    nconts = xfile.read()
    assert xfile.tell() == len(fc)
    assert nconts == fc[newpos:]

    # Negative offsets raise an error
    pytest.raises(IOError, xfile.seek, -1)

    # floating point offsets are converted to integers
    xfile.seek(1.1)
    assert xfile.tell() == 1
    xfile.seek(0.999999)
    assert xfile.tell() == 0
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:46,代码来源:test_xrdfile.py

示例15: test_read_binary

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import read [as 别名]
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,代码行数:13,代码来源:test_xrdfile.py


注:本文中的xrootdpyfs.XRootDPyFile.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。