xbase: make "Ctrl+Enter" apply changes and rebase
[git-cola.git] / test / test_cola_settings.py
blobb7ef174032274855b0676afe8a7dcd9208395517
1 import unittest
2 import os
4 from cola import git
5 from cola import settings
6 import helper
8 class SettingsTestCase(unittest.TestCase):
9 """Tests the cola.settings module"""
10 def setUp(self):
11 settings.Settings._file = self._file = helper.tmp_path('settings')
12 settings.Settings.load_dot_cola = lambda x, y: {}
14 def tearDown(self):
15 if os.path.exists(self._file):
16 os.remove(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"""
23 model = self.model()
24 model.gui_state['test-gui'] = {'foo':'bar'}
25 model.save()
27 model = self.model()
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
43 model = self.model()
44 model.add_bookmark(bookmark)
45 model.save()
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'
61 model = self.model()
62 model.add_bookmark(bookmark)
63 model.save()
65 model = self.model()
66 bookmarks = model.bookmarks
67 self.assertEqual(len(model.bookmarks), 0)
68 self.assertFalse(bookmark in bookmarks)
72 if __name__ == '__main__':
73 unittest.main()