1 from __future__
import unicode_literals
6 from cola
.settings
import Settings
8 from test
import helper
11 class SettingsTestCase(unittest
.TestCase
):
12 """Tests the cola.settings module"""
14 Settings
._file
= self
._file
= helper
.tmp_path('settings')
15 self
.settings
= self
.new_settings()
18 if os
.path
.exists(self
._file
):
21 def new_settings(self
, **kwargs
):
22 settings
= Settings(**kwargs
)
26 def test_gui_save_restore(self
):
27 """Test saving and restoring gui state"""
28 settings
= self
.new_settings()
29 settings
.gui_state
['test-gui'] = {'foo':'bar'}
32 settings
= self
.new_settings()
33 state
= settings
.gui_state
.get('test-gui', {})
34 self
.assertTrue('foo' in state
)
35 self
.assertEqual(state
['foo'], 'bar')
37 def test_bookmarks_save_restore(self
):
38 """Test the bookmark save/restore feature"""
40 # We automatically purge missing entries so we mock-out
41 # git.is_git_worktree() so that this bookmark is kept.
43 bookmark
= '/tmp/python/thinks/this/exists'
45 def mock_verify(path
):
46 return path
== bookmark
48 settings
= self
.new_settings()
49 settings
.add_bookmark(bookmark
)
52 settings
= self
.new_settings(verify
=mock_verify
)
54 bookmarks
= settings
.bookmarks
55 self
.assertEqual(len(settings
.bookmarks
), 1)
56 self
.assertTrue(bookmark
in bookmarks
)
58 settings
.remove_bookmark(bookmark
)
59 bookmarks
= settings
.bookmarks
60 self
.assertEqual(len(bookmarks
), 0)
61 self
.assertFalse(bookmark
in bookmarks
)
63 def test_bookmarks_removes_missing_entries(self
):
64 """Test that missing entries are removed after a reload"""
65 bookmark
= '/tmp/this/does/not/exist'
66 settings
= self
.new_settings()
67 settings
.add_bookmark(bookmark
)
70 settings
= self
.new_settings()
71 bookmarks
= settings
.bookmarks
72 self
.assertEqual(len(settings
.bookmarks
), 0)
73 self
.assertFalse(bookmark
in bookmarks
)
76 if __name__
== '__main__':