prefs: add a Defaults class for holding hard-coded defaults
[git-cola.git] / test / gitcfg_test.py
blob9c55dda16419bcb5e7c862e627e459565960248c
1 from __future__ import absolute_import, division, unicode_literals
2 import unittest
4 from . import helper
7 class GitConfigTestCase(helper.GitRepositoryTestCase):
8 """Tests the cola.gitcmds module."""
10 def test_string(self):
11 """Test string values in get()."""
12 self.run_git('config', 'test.value', 'test')
13 self.assertEqual(self.cfg.get('test.value'), 'test')
15 def test_int(self):
16 """Test int values in get()."""
17 self.run_git('config', 'test.int', '42')
18 self.assertEqual(self.cfg.get('test.int'), 42)
20 def test_true(self):
21 """Test bool values in get()."""
22 self.run_git('config', 'test.bool', 'true')
23 self.assertEqual(self.cfg.get('test.bool'), True)
25 def test_false(self):
26 self.run_git('config', 'test.bool', 'false')
27 self.assertEqual(self.cfg.get('test.bool'), False)
29 def test_yes(self):
30 self.run_git('config', 'test.bool', 'yes')
31 self.assertEqual(self.cfg.get('test.bool'), True)
33 def test_no(self):
34 self.run_git('config', 'test.bool', 'no')
35 self.assertEqual(self.cfg.get('test.bool'), False)
37 def test_bool_no_value(self):
38 self.append_file('.git/config', '[test]\n')
39 self.append_file('.git/config', '\tbool\n')
40 self.assertEqual(self.cfg.get('test.bool'), True)
42 def test_empty_value(self):
43 self.append_file('.git/config', '[test]\n')
44 self.append_file('.git/config', '\tvalue = \n')
45 self.assertEqual(self.cfg.get('test.value'), '')
47 def test_default(self):
48 """Test default values in get()."""
49 self.assertEqual(self.cfg.get('does.not.exist'), None)
50 self.assertEqual(self.cfg.get('does.not.exist', default=42), 42)
52 def test_get_all(self):
53 """Test getting multiple values in get_all()"""
54 self.run_git('config', '--add', 'test.value', 'abc')
55 self.run_git('config', '--add', 'test.value', 'def')
56 expect = ['abc', 'def']
57 self.assertEqual(expect, self.cfg.get_all('test.value'))
59 def assert_color(self, expect, git_value, key='test', default=None):
60 self.run_git('config', 'cola.color.%s' % key, git_value)
61 self.cfg.reset()
62 actual = self.cfg.color(key, default)
63 self.assertEqual(expect, actual)
65 def test_color_rrggbb(self):
66 self.assert_color((0xaa, 0xbb, 0xcc), 'aabbcc')
67 self.assert_color((0xaa, 0xbb, 0xcc), '#aabbcc')
69 def test_color_int(self):
70 self.assert_color((0x10, 0x20, 0x30), '102030')
71 self.assert_color((0x10, 0x20, 0x30), '#102030')
73 def test_guitool_opts(self):
74 self.run_git('config', 'guitool.hello world.cmd', 'hello world')
75 opts = self.cfg.get_guitool_opts('hello world')
76 expect = 'hello world'
77 actual = opts['cmd']
78 self.assertEqual(expect, actual)
80 def test_guitool_names(self):
81 self.run_git('config', 'guitool.hello meow.cmd', 'hello meow')
82 names = self.cfg.get_guitool_names()
83 self.assertTrue('hello meow' in names)
85 def test_guitool_names_mixed_case(self):
86 self.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
87 names = self.cfg.get_guitool_names()
88 self.assertTrue('Meow Cat' in names)
90 def test_find_mixed_case(self):
91 self.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
92 opts = self.cfg.find('guitool.Meow Cat.*')
93 self.assertEqual(opts['guitool.Meow Cat.cmd'], 'cat hello')
95 def test_guitool_opts_mixed_case(self):
96 self.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
97 opts = self.cfg.get_guitool_opts('Meow Cat')
98 self.assertEqual(opts['cmd'], 'cat hello')
101 if __name__ == '__main__':
102 unittest.main()