about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorWojciech Siewierski <wojciech.siewierski@onet.pl>2019-01-27 02:46:25 +0100
committerWojciech Siewierski <wojciech.siewierski@onet.pl>2019-01-27 02:46:25 +0100
commit8374ae53f1604f887255bd6214aae2b40b03c6f8 (patch)
treedd93486cf156bc6d91b1b650cfa4569af1ccb945
parent981945a9afe4cca3b2e93ee0a57a22460b68f794 (diff)
downloadranger-8374ae53f1604f887255bd6214aae2b40b03c6f8.tar.gz
Make it easier to test bookmarks by optionally disabling validation
The test bookmarks were intentionally bogus as we cannot reliably predict valid
paths on the test system, so validation doesn't make any sense there.
-rw-r--r--ranger/container/bookmarks.py7
-rw-r--r--tests/ranger/container/test_bookmarks.py4
2 files changed, 6 insertions, 5 deletions
diff --git a/ranger/container/bookmarks.py b/ranger/container/bookmarks.py
index 20809c10..25e81097 100644
--- a/ranger/container/bookmarks.py
+++ b/ranger/container/bookmarks.py
@@ -12,7 +12,7 @@ from ranger.core.shared import FileManagerAware
 ALLOWED_KEYS = string.ascii_letters + string.digits + "`'"
 
 
-class Bookmarks(FileManagerAware):
+class Bookmarks(FileManagerAware):  # pylint: disable=too-many-instance-attributes
     """Bookmarks is a container which associates keys with bookmarks.
 
     A key is a string with: len(key) == 1 and key in ALLOWED_KEYS.
@@ -29,7 +29,7 @@ class Bookmarks(FileManagerAware):
     load_pattern = re.compile(r"^[\d\w']:.")
 
     def __init__(self, bookmarkfile, bookmarktype=str, autosave=False,
-                 nonpersistent_bookmarks=()):
+                 validate=True, nonpersistent_bookmarks=()):
         """Initializes Bookmarks.
 
         <bookmarkfile> specifies the path to the file where
@@ -41,6 +41,7 @@ class Bookmarks(FileManagerAware):
         self.path = bookmarkfile
         self.bookmarktype = bookmarktype
         self.nonpersistent_bookmarks = set(nonpersistent_bookmarks)
+        self.validate = validate
 
     def load(self):
         """Load the bookmarks from path/bookmarks"""
@@ -89,7 +90,7 @@ class Bookmarks(FileManagerAware):
             key = "'"
         if key in self.dct:
             value = self.dct[key]
-            if os.path.isdir(value.path):
+            if not self.validate or os.path.isdir(str(value)):
                 return value
             else:
                 raise KeyError("Cannot open bookmark: `%s'!" % key)
diff --git a/tests/ranger/container/test_bookmarks.py b/tests/ranger/container/test_bookmarks.py
index 64192c06..8c62bd23 100644
--- a/tests/ranger/container/test_bookmarks.py
+++ b/tests/ranger/container/test_bookmarks.py
@@ -12,7 +12,7 @@ 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))
+    bmstore = Bookmarks(str(bookmarkfile), validate=False)
 
     # loading an empty bookmark file doesnot crash
     bmstore.load()
@@ -33,7 +33,7 @@ def testbookmarks(tmpdir):
 
     # We can persist bookmarks to disk and restore them from disk
     bmstore.save()
-    secondstore = Bookmarks(str(bookmarkfile))
+    secondstore = Bookmarks(str(bookmarkfile), validate=False)
     secondstore.load()
     assert "'" in secondstore
     assert secondstore["'"] == "the milk"
b0a216f5 ^


b0b3af33 ^


b0a216f5 ^
b0b3af33 ^

2c5ea01d ^
b0b3af33 ^
2c5ea01d ^
582f3519 ^
b06433bc ^
582f3519 ^

94c5d83e ^
dee6cfa6 ^
e9e4b4ff ^
b0a216f5 ^
a082b66a ^

b0a216f5 ^
e9e4b4ff ^





ad75190c ^
e9e4b4ff ^
c7720fff ^



8d21b83c ^


e9e4b4ff ^
25a4162d ^
e9e4b4ff ^
0c2c782d ^
636d9393 ^
b0a216f5 ^
c0d63e78 ^



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