5 from cola
import settings
8 class SettingsTestCase(unittest
.TestCase
):
9 """Tests the cola.settings module"""
11 settings
.Settings
._file
= self
._file
= helper
.tmp_path('settings')
12 settings
.Settings
.load_dot_cola
= lambda x
, y
: {}
15 if os
.path
.exists(self
._file
):
18 def model(self
, **kwargs
):
19 return settings
.Settings(**kwargs
)
21 def test_gui_save_restore(self
):
22 """Test saving and restoring gui state"""
24 model
.gui_state
['test-gui'] = {'foo':'bar'}
28 state
= model
.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
= '/tmp/python/thinks/this/exists'
40 def mock_verify(path
):
41 return path
== bookmark
44 model
.add_bookmark(bookmark
)
47 model
= self
.model(verify
=mock_verify
)
49 bookmarks
= model
.bookmarks
50 self
.assertEqual(len(model
.bookmarks
), 1)
51 self
.assertTrue(bookmark
in bookmarks
)
53 model
.remove_bookmark(bookmark
)
54 bookmarks
= model
.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 bookmark
= '/tmp/this/does/not/exist'
62 model
.add_bookmark(bookmark
)
66 bookmarks
= model
.bookmarks
67 self
.assertEqual(len(model
.bookmarks
), 0)
68 self
.assertFalse(bookmark
in bookmarks
)
72 if __name__
== '__main__':