當前位置: 首頁>>代碼示例>>Python>>正文


Python Bookmarks.update_if_outdated方法代碼示例

本文整理匯總了Python中ranger.container.bookmarks.Bookmarks.update_if_outdated方法的典型用法代碼示例。如果您正苦於以下問題:Python Bookmarks.update_if_outdated方法的具體用法?Python Bookmarks.update_if_outdated怎麽用?Python Bookmarks.update_if_outdated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ranger.container.bookmarks.Bookmarks的用法示例。


在下文中一共展示了Bookmarks.update_if_outdated方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testbookmarks

# 需要導入模塊: from ranger.container.bookmarks import Bookmarks [as 別名]
# 或者: from ranger.container.bookmarks.Bookmarks import update_if_outdated [as 別名]
def testbookmarks(tmpdir):
    # Bookmarks point to directory location and allow fast access to
    # 'favorite' directories. They are persisted to a bookmark file, plain text.
    bookmarkfile = tmpdir.join("bookmarkfile")
    bmstore = Bookmarks(str(bookmarkfile))

    # loading an empty bookmark file doesnot crash
    bmstore.load()

    # One can add / remove and check existing of bookmark
    bmstore["h"] = "world"
    assert "h" in bmstore
    del bmstore["h"]

    # Only one letter/digit bookmarks are valid, adding something else fails
    # silently
    bmstore["hello"] = "world"
    assert "hello" not in bmstore

    # The default bookmark is ', remember allows to set it
    bmstore.remember("the milk")
    assert bmstore["'"] == "the milk"

    # We can persist bookmarks to disk and restore them from disk
    bmstore.save()
    secondstore = Bookmarks(str(bookmarkfile))
    secondstore.load()
    assert "'" in secondstore
    assert secondstore["'"] == "the milk"

    # We don't unnecessary update when the file on disk does not change
    origupdate = secondstore.update

    class OutOfDateException(Exception):
        pass

    def crash():
        raise OutOfDateException("Don't access me")
    secondstore.update = crash
    secondstore.update_if_outdated()

    # If the modification time change, we try to read the file
    newtime = time.time() - 5
    os.utime(str(bookmarkfile), (newtime, newtime))
    with pytest.raises(OutOfDateException):
        secondstore.update_if_outdated()
    secondstore.update = origupdate
    secondstore.update_if_outdated()
開發者ID:ajtluser,項目名稱:ranger,代碼行數:50,代碼來源:test_bookmarks.py


注:本文中的ranger.container.bookmarks.Bookmarks.update_if_outdated方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。