summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorLaurent Charignon <l.charignon@gmail.com>2016-01-31 18:28:35 -0800
committerLaurent Charignon <l.charignon@gmail.com>2016-01-31 18:59:37 -0800
commit54e39a0da914d9253c74e480cc4b785d12aad014 (patch)
tree58c603d0cb7b84a5b6489bbf75f5aee9dc9e60c7 /tests
parent6e5da324285aa8d67dce9647cf094f79dbf7a4e6 (diff)
downloadranger-54e39a0da914d9253c74e480cc4b785d12aad014.tar.gz
bookmarks: add test
Diffstat (limited to 'tests')
-rw-r--r--tests/ranger/container/test_bookmarks.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/ranger/container/test_bookmarks.py b/tests/ranger/container/test_bookmarks.py
new file mode 100644
index 00000000..46c615c6
--- /dev/null
+++ b/tests/ranger/container/test_bookmarks.py
@@ -0,0 +1,52 @@
+import os
+import time
+import pytest
+
+from ranger.container.bookmarks import Bookmarks
+
+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 uneccesary 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()