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


Python LockedFD._lockfilepath方法代码示例

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


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

示例1: test_lockedfd

# 需要导入模块: from git.util import LockedFD [as 别名]
# 或者: from git.util.LockedFD import _lockfilepath [as 别名]
    def test_lockedfd(self):
        my_file = tempfile.mktemp()
        orig_data = "hello"
        new_data = "world"
        my_file_fp = open(my_file, "wb")
        my_file_fp.write(orig_data)
        my_file_fp.close()

        try:
            lfd = LockedFD(my_file)
            lockfilepath = lfd._lockfilepath()

            # cannot end before it was started
            self.failUnlessRaises(AssertionError, lfd.rollback)
            self.failUnlessRaises(AssertionError, lfd.commit)

            # open for writing
            assert not os.path.isfile(lockfilepath)
            wfd = lfd.open(write=True)
            assert lfd._fd is wfd
            assert os.path.isfile(lockfilepath)

            # write data and fail
            os.write(wfd, new_data)
            lfd.rollback()
            assert lfd._fd is None
            self._cmp_contents(my_file, orig_data)
            assert not os.path.isfile(lockfilepath)

            # additional call doesnt fail
            lfd.commit()
            lfd.rollback()

            # test reading
            lfd = LockedFD(my_file)
            rfd = lfd.open(write=False)
            assert os.read(rfd, len(orig_data)) == orig_data

            assert os.path.isfile(lockfilepath)
            # deletion rolls back
            del(lfd)
            assert not os.path.isfile(lockfilepath)

            # write data - concurrently
            lfd = LockedFD(my_file)
            olfd = LockedFD(my_file)
            assert not os.path.isfile(lockfilepath)
            wfdstream = lfd.open(write=True, stream=True)       # this time as stream
            assert os.path.isfile(lockfilepath)
            # another one fails
            self.failUnlessRaises(IOError, olfd.open)

            wfdstream.write(new_data)
            lfd.commit()
            assert not os.path.isfile(lockfilepath)
            self._cmp_contents(my_file, new_data)

            # could test automatic _end_writing on destruction
        finally:
            os.remove(my_file)
        # END final cleanup

        # try non-existing file for reading
        lfd = LockedFD(tempfile.mktemp())
        try:
            lfd.open(write=False)
        except OSError:
            assert not os.path.exists(lfd._lockfilepath())
        else:
            self.fail("expected OSError")
开发者ID:JustAnotherChad,项目名称:GitPython,代码行数:72,代码来源:test_util.py


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