stash: pylint updates
[git-cola.git] / test / gitcfg_test.py
blobf20806df33f7ab0e3beddc3b3968dabd8216fa94
1 from __future__ import absolute_import, division, unicode_literals
2 import unittest
4 import mock
6 from cola import gitcfg
8 from test import helper
11 class GitConfigTestCase(helper.GitRepositoryTestCase):
12 """Tests the cola.gitcmds module."""
13 def setUp(self):
14 helper.GitRepositoryTestCase.setUp(self)
15 self.config = gitcfg.create(self.context)
16 self.config.reset()
18 def test_string(self):
19 """Test string values in get()."""
20 self.git('config', 'test.value', 'test')
21 self.assertEqual(self.config.get('test.value'), 'test')
23 def test_int(self):
24 """Test int values in get()."""
25 self.git('config', 'test.int', '42')
26 self.assertEqual(self.config.get('test.int'), 42)
28 def test_true(self):
29 """Test bool values in get()."""
30 self.git('config', 'test.bool', 'true')
31 self.assertEqual(self.config.get('test.bool'), True)
33 def test_false(self):
34 self.git('config', 'test.bool', 'false')
35 self.assertEqual(self.config.get('test.bool'), False)
37 def test_yes(self):
38 self.git('config', 'test.bool', 'yes')
39 self.assertEqual(self.config.get('test.bool'), True)
41 def test_no(self):
42 self.git('config', 'test.bool', 'no')
43 self.assertEqual(self.config.get('test.bool'), False)
45 def test_bool_no_value(self):
46 self.append_file('.git/config', '[test]\n')
47 self.append_file('.git/config', '\tbool\n')
48 self.assertEqual(self.config.get('test.bool'), True)
50 def test_empty_value(self):
51 self.append_file('.git/config', '[test]\n')
52 self.append_file('.git/config', '\tvalue = \n')
53 self.assertEqual(self.config.get('test.value'), '')
55 def test_default(self):
56 """Test default values in get()."""
57 self.assertEqual(self.config.get('does.not.exist'), None)
58 self.assertEqual(self.config.get('does.not.exist', default=42), 42)
60 def test_get_all(self):
61 """Test getting multiple values in get_all()"""
62 self.git('config', '--add', 'test.value', 'abc')
63 self.git('config', '--add', 'test.value', 'def')
64 expect = ['abc', 'def']
65 self.assertEqual(expect, self.config.get_all('test.value'))
67 def assert_color(self, expect, git_value, key='test', default=None):
68 self.git('config', 'cola.color.%s' % key, git_value)
69 self.config.reset()
70 actual = self.config.color(key, None)
71 self.assertEqual(expect, actual)
73 def test_color_rrggbb(self):
74 self.assert_color((0xaa, 0xbb, 0xcc), 'aabbcc')
75 self.assert_color((0xaa, 0xbb, 0xcc), '#aabbcc')
77 def test_color_int(self):
78 self.assert_color((0x10, 0x20, 0x30), '102030')
79 self.assert_color((0x10, 0x20, 0x30), '#102030')
81 def test_guitool_opts(self):
82 self.git('config', 'guitool.hello world.cmd', 'hello world')
83 opts = self.config.get_guitool_opts('hello world')
84 expect = 'hello world'
85 actual = opts['cmd']
86 self.assertEqual(expect, actual)
88 def test_guitool_names(self):
89 self.git('config', 'guitool.hello meow.cmd', 'hello meow')
90 names = self.config.get_guitool_names()
91 self.assertTrue('hello meow' in names)
93 def test_guitool_names_mixed_case(self):
94 self.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
95 names = self.config.get_guitool_names()
96 self.assertTrue('Meow Cat' in names)
98 def test_find_mixed_case(self):
99 self.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
100 opts = self.config.find('guitool.Meow Cat.*')
101 self.assertEqual(opts['guitool.Meow Cat.cmd'], 'cat hello')
103 def test_guitool_opts_mixed_case(self):
104 self.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
105 opts = self.config.get_guitool_opts('Meow Cat')
106 self.assertEqual(opts['cmd'], 'cat hello')
109 if __name__ == '__main__':
110 unittest.main()