1 from __future__
import absolute_import
, division
, unicode_literals
6 from cola
.settings
import Settings
11 class SettingsTestCase(unittest
.TestCase
):
12 """Tests the cola.settings module"""
15 Settings
.config_path
= self
._file
= helper
.tmp_path('settings')
16 self
.settings
= self
.new_settings()
19 if os
.path
.exists(self
._file
):
22 def new_settings(self
, **kwargs
):
23 settings
= Settings(**kwargs
)
27 def test_gui_save_restore(self
):
28 """Test saving and restoring gui state"""
29 settings
= self
.new_settings()
30 settings
.gui_state
['test-gui'] = {'foo': 'bar'}
33 settings
= self
.new_settings()
34 state
= settings
.gui_state
.get('test-gui', {})
35 self
.assertTrue('foo' in state
)
36 self
.assertEqual(state
['foo'], 'bar')
38 def test_bookmarks_save_restore(self
):
39 """Test the bookmark save/restore feature"""
41 # We automatically purge missing entries so we mock-out
42 # git.is_git_worktree() so that this bookmark is kept.
44 bookmark
= {'path': '/tmp/python/thinks/this/exists',
47 def mock_verify(path
):
48 return path
== bookmark
['path']
50 settings
= self
.new_settings()
51 settings
.add_bookmark(bookmark
['path'], bookmark
['name'])
54 settings
= self
.new_settings(verify
=mock_verify
)
56 bookmarks
= settings
.bookmarks
57 self
.assertEqual(len(settings
.bookmarks
), 1)
58 self
.assertTrue(bookmark
in bookmarks
)
60 settings
.remove_bookmark(bookmark
['path'], bookmark
['name'])
61 bookmarks
= settings
.bookmarks
62 self
.assertEqual(len(bookmarks
), 0)
63 self
.assertFalse(bookmark
in bookmarks
)
65 def test_bookmarks_removes_missing_entries(self
):
66 """Test that missing entries are removed after a reload"""
67 bookmark
= {'path': '/tmp/this/does/not/exist', 'name': 'notexist'}
68 settings
= self
.new_settings()
69 settings
.add_bookmark(bookmark
['path'], bookmark
['name'])
72 settings
= self
.new_settings()
73 bookmarks
= settings
.bookmarks
74 self
.assertEqual(len(settings
.bookmarks
), 0)
75 self
.assertFalse(bookmark
in bookmarks
)
77 def test_rename_bookmark(self
):
78 settings
= self
.new_settings()
79 settings
.add_bookmark('/tmp/repo', 'a')
80 settings
.add_bookmark('/tmp/repo', 'b')
81 settings
.add_bookmark('/tmp/repo', 'c')
83 settings
.rename_bookmark('/tmp/repo', 'b', 'test')
85 expect
= ['a', 'test', 'c']
86 actual
= [i
['name'] for i
in settings
.bookmarks
]
87 self
.assertEqual(expect
, actual
)
90 if __name__
== '__main__':