sequenceeditor: use qtutils.SimpleTask instead of a raw Thread
[git-cola.git] / test / settings_test.py
blobd40b05adf9e2253be20abf1d24af8be332686e8a
1 """Test the cola.settings module"""
2 # pylint: disable=redefined-outer-name
3 import os
5 import pytest
7 from cola.settings import Settings
9 from . import helper
12 @pytest.fixture(autouse=True)
13 def settings_fixture():
14 """Provide Settings that save into a temporary location to all tests"""
15 filename = helper.tmp_path('settings')
16 Settings.config_path = filename
18 yield Settings.read()
20 if os.path.exists(filename):
21 os.remove(filename)
24 def test_gui_save_restore(settings_fixture):
25 """Test saving and restoring gui state"""
26 settings = settings_fixture
27 settings.gui_state['test-gui'] = {'foo': 'bar'}
28 settings.save()
30 settings = Settings.read()
31 state = settings.gui_state.get('test-gui', {})
32 assert 'foo' in state
33 assert state['foo'] == 'bar'
36 def test_bookmarks_save_restore():
37 """Test the bookmark save/restore feature"""
38 # We automatically purge missing entries so we mock-out
39 # git.is_git_worktree() so that this bookmark is kept.
40 bookmark = {'path': '/tmp/python/thinks/this/exists', 'name': 'exists'}
42 def mock_verify(path):
43 return path == bookmark['path']
45 settings = Settings.read()
46 settings.add_bookmark(bookmark['path'], bookmark['name'])
47 settings.save()
49 settings = Settings.read(verify=mock_verify)
51 bookmarks = settings.bookmarks
52 assert len(settings.bookmarks) == 1
53 assert bookmark in bookmarks
55 settings.remove_bookmark(bookmark['path'], bookmark['name'])
56 bookmarks = settings.bookmarks
57 expect = 0
58 actual = len(bookmarks)
59 assert expect == actual
60 assert bookmark not in bookmarks
63 def test_bookmarks_removes_missing_entries():
64 """Test that missing entries are removed after a reload"""
65 # verify returns False so all entries will be removed.
66 bookmark = {'path': '.', 'name': 'does-not-exist'}
67 settings = Settings.read(verify=lambda x: False)
68 settings.add_bookmark(bookmark['path'], bookmark['name'])
69 settings.remove_missing_bookmarks()
70 settings.save()
72 settings = Settings.read()
73 bookmarks = settings.bookmarks
74 expect = 0
75 actual = len(bookmarks)
76 assert expect == actual
77 assert bookmark not in bookmarks
80 def test_rename_bookmark():
81 settings = Settings.read()
82 settings.add_bookmark('/tmp/repo', 'a')
83 settings.add_bookmark('/tmp/repo', 'b')
84 settings.add_bookmark('/tmp/repo', 'c')
86 settings.rename_bookmark('/tmp/repo', 'b', 'test')
88 expect = ['a', 'test', 'c']
89 actual = [i['name'] for i in settings.bookmarks]
90 assert expect == actual