about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-01 19:25:47 +0100
committerhut <hut@lavabit.com>2010-01-01 19:25:47 +0100
commit0a1bc7598776c360b469a64316a1c69c0a914b5f (patch)
treed4c2da5c32d5216a2d6d478f0ed5ea41f85d8bec
parentd955e3f04a2b0509e8053a15a1f916bfb5677af2 (diff)
downloadranger-0a1bc7598776c360b469a64316a1c69c0a914b5f.tar.gz
bookmarks: added testcase, documentation, setting
-rw-r--r--ranger/container/bookmarks.py8
-rw-r--r--ranger/defaults/options.py1
-rw-r--r--ranger/fm.py2
-rw-r--r--ranger/shared/settings.py2
-rw-r--r--test/tc_bookmarks.py73
5 files changed, 81 insertions, 5 deletions
diff --git a/ranger/container/bookmarks.py b/ranger/container/bookmarks.py
index 738efe46..98fdc402 100644
--- a/ranger/container/bookmarks.py
+++ b/ranger/container/bookmarks.py
@@ -98,6 +98,7 @@ class Bookmarks(object):
 			return
 
 		for key in set(self.dct.keys()) | set(real_dict.keys()):
+			# set some variables
 			if key in self.dct:
 				current = self.dct[key]
 			else:
@@ -113,13 +114,14 @@ class Bookmarks(object):
 			else:
 				real = None
 
+			# determine if there have been changes
 			if current == original and current != real:
-				continue
+				continue   # another ranger instance has changed the bookmark
 
 			if key not in self.dct:
-				del real_dict[key]
+				del real_dict[key]   # the user has deleted it
 			else:
-				real_dict[key] = current
+				real_dict[key] = current   # the user has changed it
 
 		self._set_dict(real_dict, original=real_dict_copy)
 
diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py
index d4172eee..6467369b 100644
--- a/ranger/defaults/options.py
+++ b/ranger/defaults/options.py
@@ -11,6 +11,7 @@ directories_first = True
 preview_files = False
 max_history_size = 20
 auto_load_preview = True
+autosave_bookmarks = True
 
 max_dirsize_for_autopreview = None
 sort = 'basename'
diff --git a/ranger/fm.py b/ranger/fm.py
index 2fb7e21c..e70e9f3c 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -33,7 +33,7 @@ class FM(Actions):
 			self.bookmarks = Bookmarks(
 					bookmarkfile=relpath_conf('bookmarks'),
 					bookmarktype=Directory,
-					autosave=False)
+					autosave=self.settings.autosave_bookmarks)
 			self.bookmarks.load()
 
 		else:
diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py
index ec7abedf..644d1318 100644
--- a/ranger/shared/settings.py
+++ b/ranger/shared/settings.py
@@ -3,7 +3,7 @@ show_hidden scroll_offset
 directories_first sort reverse
 preview_files max_history_size colorscheme
 collapse_preview auto_load_preview
-max_dirsize_for_autopreview
+max_dirsize_for_autopreview autosave_bookmarks
 apps keys
 """.split()
 
diff --git a/test/tc_bookmarks.py b/test/tc_bookmarks.py
new file mode 100644
index 00000000..a0f6bf30
--- /dev/null
+++ b/test/tc_bookmarks.py
@@ -0,0 +1,73 @@
+if __name__ == '__main__': from __init__ import init; init()
+
+from os.path import realpath, join, dirname
+import unittest
+import os
+import time
+
+from ranger.container.bookmarks import Bookmarks
+
+TESTDIR = realpath(join(dirname(__file__), 'testdir'))
+BMFILE = join(TESTDIR, 'bookmarks')
+
+class TestDisplayable(unittest.TestCase):
+	def setUp(self):
+		try:
+			os.remove(BMFILE)
+		except:
+			pass
+
+	def tearDown(self):
+		try:
+			os.remove(BMFILE)
+		except:
+			pass
+	
+	def test_adding_bookmarks(self):
+		bm = Bookmarks(BMFILE, str, autosave=False)
+		bm.load()
+		bm['a'] = 'fooo'
+		self.assertEqual(bm['a'], 'fooo')
+
+	def test_sharing_bookmarks_between_instances(self):
+		bm = Bookmarks(BMFILE, str, autosave=True)
+		bm2 = Bookmarks(BMFILE, str, autosave=True)
+
+		bm.load()
+		bm2.load()
+		bm['a'] = 'fooo'
+		self.assertRaises(KeyError, bm2.__getitem__, 'a')
+
+		bm.save()
+		bm2.load()
+		self.assertEqual(bm['a'], bm2['a'])
+
+		bm2['a'] = 'bar'
+
+		bm.save()
+		bm2.save()
+		bm.load()
+		bm2.load()
+
+		self.assertEqual(bm['a'], bm2['a'])
+	
+	def test_messing_around(self):
+		bm = Bookmarks(BMFILE, str, autosave=False)
+		bm2 = Bookmarks(BMFILE, str, autosave=False)
+
+		bm.load()
+		bm['a'] = 'car'
+
+		bm2.load()
+		self.assertRaises(KeyError, bm2.__getitem__, 'a')
+
+		bm2.save()
+		bm.update()
+		bm.save()
+		bm.load()
+		bm2.load()
+
+		self.assertEqual(bm['a'], bm2['a'])
+
+if __name__ == '__main__':
+	unittest.main()