1 from __future__
import absolute_import
, division
, unicode_literals
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')
16 """Test int values in get()."""
17 self
.run_git('config', 'test.int', '42')
18 self
.assertEqual(self
.cfg
.get('test.int'), 42)
21 """Test bool values in get()."""
22 self
.run_git('config', 'test.bool', 'true')
23 self
.assertEqual(self
.cfg
.get('test.bool'), True)
26 self
.run_git('config', 'test.bool', 'false')
27 self
.assertEqual(self
.cfg
.get('test.bool'), False)
30 self
.run_git('config', 'test.bool', 'yes')
31 self
.assertEqual(self
.cfg
.get('test.bool'), True)
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
)
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'
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')
100 def test_hooks(self
):
101 self
.run_git('config', 'core.hooksPath', '/test/hooks')
102 expect
= '/test/hooks'
103 actual
= self
.cfg
.hooks()
104 assert expect
== actual
106 def test_hooks_lowercase(self
):
107 self
.run_git('config', 'core.hookspath', '/test/hooks-lowercase')
108 expect
= '/test/hooks-lowercase'
109 actual
= self
.cfg
.hooks()
110 assert expect
== actual
112 def test_hooks_path(self
):
113 self
.run_git('config', 'core.hooksPath', '/test/hooks')
114 expect
= '/test/hooks/example'
115 actual
= self
.cfg
.hooks_path('example')
116 assert expect
== actual
118 def test_hooks_path_lowercase(self
):
119 self
.run_git('config', 'core.hookspath', '/test/hooks-lowercase')
120 expect
= '/test/hooks-lowercase/example'
121 actual
= self
.cfg
.hooks_path('example')
122 assert expect
== actual
125 if __name__
== '__main__':