forked from git-cola/git-cola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_test.py
91 lines (66 loc) · 2.82 KB
/
settings_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from __future__ import absolute_import, division, unicode_literals
import unittest
import os
from cola.settings import Settings
from test import helper
class SettingsTestCase(unittest.TestCase):
"""Tests the cola.settings module"""
def setUp(self):
Settings._file = self._file = helper.tmp_path('settings')
self.settings = self.new_settings()
def tearDown(self):
if os.path.exists(self._file):
os.remove(self._file)
def new_settings(self, **kwargs):
settings = Settings(**kwargs)
settings.load()
return settings
def test_gui_save_restore(self):
"""Test saving and restoring gui state"""
settings = self.new_settings()
settings.gui_state['test-gui'] = {'foo': 'bar'}
settings.save()
settings = self.new_settings()
state = settings.gui_state.get('test-gui', {})
self.assertTrue('foo' in state)
self.assertEqual(state['foo'], 'bar')
def test_bookmarks_save_restore(self):
"""Test the bookmark save/restore feature"""
# We automatically purge missing entries so we mock-out
# git.is_git_worktree() so that this bookmark is kept.
bookmark = {'path': '/tmp/python/thinks/this/exists',
'name': 'exists'}
def mock_verify(path):
return path == bookmark['path']
settings = self.new_settings()
settings.add_bookmark(bookmark['path'], bookmark['name'])
settings.save()
settings = self.new_settings(verify=mock_verify)
bookmarks = settings.bookmarks
self.assertEqual(len(settings.bookmarks), 1)
self.assertTrue(bookmark in bookmarks)
settings.remove_bookmark(bookmark['path'], bookmark['name'])
bookmarks = settings.bookmarks
self.assertEqual(len(bookmarks), 0)
self.assertFalse(bookmark in bookmarks)
def test_bookmarks_removes_missing_entries(self):
"""Test that missing entries are removed after a reload"""
bookmark = {'path': '/tmp/this/does/not/exist', 'name': 'notexist'}
settings = self.new_settings()
settings.add_bookmark(bookmark['path'], bookmark['name'])
settings.save()
settings = self.new_settings()
bookmarks = settings.bookmarks
self.assertEqual(len(settings.bookmarks), 0)
self.assertFalse(bookmark in bookmarks)
def test_rename_bookmark(self):
settings = self.new_settings()
settings.add_bookmark('/tmp/repo', 'a')
settings.add_bookmark('/tmp/repo', 'b')
settings.add_bookmark('/tmp/repo', 'c')
settings.rename_bookmark('/tmp/repo', 'b', 'test')
expect = ['a', 'test', 'c']
actual = [i['name'] for i in settings.bookmarks]
self.assertEqual(expect, actual)
if __name__ == '__main__':
unittest.main()