本文整理汇总了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()