1 from __future__
import absolute_import
, division
, unicode_literals
6 from cola
import gitcfg
8 from test
import helper
11 class GitConfigTestCase(helper
.GitRepositoryTestCase
):
12 """Tests the cola.gitcmds module."""
14 helper
.GitRepositoryTestCase
.setUp(self
)
15 self
.config
= gitcfg
.create(self
.context
)
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')
24 """Test int values in get()."""
25 self
.git('config', 'test.int', '42')
26 self
.assertEqual(self
.config
.get('test.int'), 42)
29 """Test bool values in get()."""
30 self
.git('config', 'test.bool', 'true')
31 self
.assertEqual(self
.config
.get('test.bool'), True)
34 self
.git('config', 'test.bool', 'false')
35 self
.assertEqual(self
.config
.get('test.bool'), False)
38 self
.git('config', 'test.bool', 'yes')
39 self
.assertEqual(self
.config
.get('test.bool'), True)
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
)
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'
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__':