Merge branch 'default-repo'
[git-cola.git] / test / settings_test.py
blob430692a39afd38a6c62ac58a4bd29131b11415f9
1 from __future__ import unicode_literals
3 import unittest
4 import os
6 from cola.settings import Settings
8 from test import helper
11 class SettingsTestCase(unittest.TestCase):
12 """Tests the cola.settings module"""
13 def setUp(self):
14 Settings._file = self._file = helper.tmp_path('settings')
15 self.settings = self.new_settings()
17 def tearDown(self):
18 if os.path.exists(self._file):
19 os.remove(self._file)
21 def new_settings(self, **kwargs):
22 settings = Settings(**kwargs)
23 settings.load()
24 return settings
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'}
30 settings.save()
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)
50 settings.save()
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)
68 settings.save()
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__':
77 unittest.main()