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


Python XRootDPyFile.close方法代码示例

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


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

示例1: test_init_append

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import close [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

示例2: test_flush

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import close [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

示例3: test_truncate1

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import close [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

示例4: test_write

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import close [as 别名]
def test_write(tmppath):
    """Test write()."""
    # With a new file.
    xfile = XRootDPyFile(mkurl(join(tmppath, 'data/nuts')), 'w+')
    assert xfile.size == 0
    conts = xfile.read()
    assert not conts

    nconts = 'Write.'
    xfile.write(nconts)
    assert xfile.tell() == len(nconts)
    assert not xfile.closed
    xfile.seek(0)
    assert xfile.size == len(nconts)
    assert xfile.read() == nconts
    xfile.close()

    # Verify persistence after closing.
    xfile = XRootDPyFile(mkurl(join(tmppath, 'data/nuts')), 'r+')
    assert xfile.size == len(nconts)
    assert xfile.read() == nconts

    # Seek(x>0) followed by a write
    nc2 = 'hello'
    cntr = len(nconts)//2
    xfile.seek(cntr)
    xfile.write(nc2)
    assert xfile.tell() == len(nc2) + cntr
    xfile.seek(0)
    assert xfile.read() == nconts[:cntr] + nc2
    xfile.close()

    # Seek(x>0) followed by a write of len < size-x
    fd = get_tsta_file(tmppath)
    fp, fc = fd['full_path'], fd['contents']
    xfile = XRootDPyFile(mkurl(fp), 'r+')
    assert xfile.read() == fc
    xfile.seek(2)
    nc = 'yo'
    xfile.write(nc)
    assert xfile.tell() == len(nc) + 2
    assert xfile.read() == fc[2+len(nc):]

    # run w/ flushing == true
    xfile.write('', True)

    # 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.write = Mock(return_value=(XRootDStatus(fake_status), None))
    pytest.raises(IOError, xfile.write, '')
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:61,代码来源:test_xrdfile.py

示例5: test__is_open

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

示例6: test_open_close

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

示例7: test_truncate4

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

示例8: test_open_close

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

示例9: test_write_binary

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import close [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

示例10: test_init_newline

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

示例11: test_init_newline

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

示例12: test_init_writemode

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

示例13: test_init_writemode

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

示例14: test_readlines

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import close [as 别名]
def test_readlines(tmppath):
    """Tests readlines()"""
    fd = get_mltl_file(tmppath)
    fb = get_copy_file(fd)
    fp, fc = fd["full_path"], fd["contents"]
    fp2 = fb["full_path"]

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

    assert xfile.readlines() == pfile.readlines()

    xfile.seek(0), pfile.seek(0)
    assert pfile.readlines() == xfile.readlines()

    xfile.close(), pfile.close()

    xfile, pfile = XRootDPyFile(mkurl(fp), "w+"), open(fp2, "w+")
    xfile.seek(0), pfile.seek(0)
    assert xfile.readlines() == pfile.readlines()
开发者ID:inveniosoftware,项目名称:xrootdpyfs,代码行数:21,代码来源:test_xrdfile.py

示例15: test__assert_mode

# 需要导入模块: from xrootdpyfs import XRootDPyFile [as 别名]
# 或者: from xrootdpyfs.XRootDPyFile import close [as 别名]
def test__assert_mode(tmppath):
    """Tests for _assert_mode"""
    fd = get_tsta_file(tmppath)
    full_path, fc = fd['full_path'], fd['contents']
    mode = 'r'
    xfile = XRootDPyFile(mkurl(full_path), mode)

    assert xfile.mode == mode
    assert xfile._assert_mode(mode)
    delattr(xfile, 'mode')
    pytest.raises(AttributeError, xfile._assert_mode, mode)

    xfile.close()
    xfile = XRootDPyFile(mkurl(full_path), 'r')
    assert xfile._assert_mode('r')
    pytest.raises(IOError, xfile._assert_mode, 'w')

    xfile.close()
    xfile = XRootDPyFile(mkurl(full_path), 'w-')
    assert xfile._assert_mode('w-')
    pytest.raises(IOError, xfile._assert_mode, 'r')

    xfile.close()
    xfile = XRootDPyFile(mkurl(full_path), 'a')
    assert xfile._assert_mode('w')
    pytest.raises(IOError, xfile._assert_mode, 'r')
开发者ID:tiborsimko,项目名称:xrootdpyfs,代码行数:28,代码来源:test_xrdfile.py


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