summary refs log tree commit diff stats
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
parent6e5da324285aa8d67dce9647cf094f79dbf7a4e6 (diff)
downloadranger-54e39a0da914d9253c74e480cc4b785d12aad014.tar.gz
bookmarks: add test
-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()
title='Blame the previous revision' href='/danisanti/profani-tty/blame/functionaltests/test_ping.c?id=d4784db7e1cb4d6bb85cbd8a0caddafb7a7afdec'>^
a522d022 ^
f17afcf5 ^


b8c94376 ^
7f98e013 ^
f17afcf5 ^

a522d022 ^
f17afcf5 ^


f189dbc6 ^
6511d61b ^



970ab94e ^
6511d61b ^










f189dbc6 ^
f17afcf5 ^
a48b9fce ^
f17afcf5 ^

7f98e013 ^

f17afcf5 ^



7f98e013 ^
f17afcf5 ^

f189dbc6 ^




a28f0d9e ^
f189dbc6 ^
















a28f0d9e ^
f189dbc6 ^







a28f0d9e ^
f189dbc6 ^




















a28f0d9e ^
f189dbc6 ^















a28f0d9e ^
f189dbc6 ^







a28f0d9e ^
f189dbc6 ^





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170