CHANGES: mention translations in the v4.0.2 release notes draft
[git-cola.git] / test / settings_test.py
blob4a1dafc3418b0c45d1747d874c1ad4c532ca1129
1 """Test the cola.settings module"""
2 # pylint: disable=redefined-outer-name
3 from __future__ import absolute_import, division, print_function, unicode_literals
4 import os
6 import pytest
8 from cola.settings import Settings
10 from . import helper
13 @pytest.fixture(autouse=True)
14 def settings_fixture():
15 """Provide Settings that save into a temporary location to all tests"""
16 filename = helper.tmp_path('settings')
17 Settings.config_path = filename
19 yield Settings.read()
21 if os.path.exists(filename):
22 os.remove(filename)
25 def test_gui_save_restore(settings_fixture):
26 """Test saving and restoring gui state"""
27 settings = settings_fixture
28 settings.gui_state['test-gui'] = {'foo': 'bar'}
29 settings.save()
31 settings = Settings.read()
32 state = settings.gui_state.get('test-gui', {})
33 assert 'foo' in state
34 assert state['foo'] == 'bar'
37 def test_bookmarks_save_restore():
38 """Test the bookmark save/restore feature"""
39 # We automatically purge missing entries so we mock-out
40 # git.is_git_worktree() so that this bookmark is kept.
41 bookmark = {'path': '/tmp/python/thinks/this/exists', 'name': 'exists'}
43 def mock_verify(path):
44 return path == bookmark['path']
46 settings = Settings.read()
47 settings.add_bookmark(bookmark['path'], bookmark['name'])
48 settings.save()
50 settings = Settings.read(verify=mock_verify)
52 bookmarks = settings.bookmarks
53 assert len(settings.bookmarks) == 1
54 assert bookmark in bookmarks
56 settings.remove_bookmark(bookmark['path'], bookmark['name'])
57 bookmarks = settings.bookmarks
58 expect = 0
59 actual = len(bookmarks)
60 assert expect == actual
61 assert bookmark not in bookmarks
64 def test_bookmarks_removes_missing_entries():
65 """Test that missing entries are removed after a reload"""
66 # verify returns False so all entries will be removed.
67 bookmark = {'path': '.', 'name': 'does-not-exist'}
68 settings = Settings.read(verify=lambda x: False)
69 settings.add_bookmark(bookmark['path'], bookmark['name'])
70 settings.remove_missing_bookmarks()
71 settings.save()
73 settings = Settings.read()
74 bookmarks = settings.bookmarks
75 expect = 0
76 actual = len(bookmarks)
77 assert expect == actual
78 assert bookmark not in bookmarks
81 def test_rename_bookmark():
82 settings = Settings.read()
83 settings.add_bookmark('/tmp/repo', 'a')
84 settings.add_bookmark('/tmp/repo', 'b')
85 settings.add_bookmark('/tmp/repo', 'c')
87 settings.rename_bookmark('/tmp/repo', 'b', 'test')
89 expect = ['a', 'test', 'c']
90 actual = [i['name'] for i in settings.bookmarks]
91 assert expect == actual