1 from __future__
import absolute_import
, division
, unicode_literals
5 from cola
.settings
import Settings
10 class SettingsTestCase(unittest
.TestCase
):
11 """Tests the cola.settings module"""
14 Settings
.config_path
= self
._file
= helper
.tmp_path('settings')
15 self
.settings
= Settings
.read()
18 if os
.path
.exists(self
._file
):
21 def test_gui_save_restore(self
):
22 """Test saving and restoring gui state"""
23 settings
= Settings
.read()
24 settings
.gui_state
['test-gui'] = {'foo': 'bar'}
27 settings
= Settings
.read()
28 state
= settings
.gui_state
.get('test-gui', {})
29 self
.assertTrue('foo' in state
)
30 self
.assertEqual(state
['foo'], 'bar')
32 def test_bookmarks_save_restore(self
):
33 """Test the bookmark save/restore feature"""
35 # We automatically purge missing entries so we mock-out
36 # git.is_git_worktree() so that this bookmark is kept.
38 bookmark
= {'path': '/tmp/python/thinks/this/exists', 'name': 'exists'}
40 def mock_verify(path
):
41 return path
== bookmark
['path']
43 settings
= Settings
.read()
44 settings
.add_bookmark(bookmark
['path'], bookmark
['name'])
47 settings
= Settings
.read(verify
=mock_verify
)
49 bookmarks
= settings
.bookmarks
50 self
.assertEqual(len(settings
.bookmarks
), 1)
51 self
.assertTrue(bookmark
in bookmarks
)
53 settings
.remove_bookmark(bookmark
['path'], bookmark
['name'])
54 bookmarks
= settings
.bookmarks
55 self
.assertEqual(len(bookmarks
), 0)
56 self
.assertFalse(bookmark
in bookmarks
)
58 def test_bookmarks_removes_missing_entries(self
):
59 """Test that missing entries are removed after a reload"""
60 # verify returns False so all entries will be removed.
61 bookmark
= {'path': '.', 'name': 'does-not-exist'}
62 settings
= Settings
.read(verify
=lambda x
: False)
63 settings
.add_bookmark(bookmark
['path'], bookmark
['name'])
64 settings
.remove_missing_bookmarks()
67 settings
= Settings
.read()
68 bookmarks
= settings
.bookmarks
69 self
.assertEqual(len(settings
.bookmarks
), 0)
70 self
.assertFalse(bookmark
in bookmarks
)
72 def test_rename_bookmark(self
):
73 settings
= Settings
.read()
74 settings
.add_bookmark('/tmp/repo', 'a')
75 settings
.add_bookmark('/tmp/repo', 'b')
76 settings
.add_bookmark('/tmp/repo', 'c')
78 settings
.rename_bookmark('/tmp/repo', 'b', 'test')
80 expect
= ['a', 'test', 'c']
81 actual
= [i
['name'] for i
in settings
.bookmarks
]
82 self
.assertEqual(expect
, actual
)
85 if __name__
== '__main__':