1 from __future__
import absolute_import
, division
, unicode_literals
5 from cola
import gitcfg
7 from test
import helper
10 class GitConfigTestCase(helper
.GitRepositoryTestCase
):
11 """Tests the cola.gitcmds module."""
13 helper
.GitRepositoryTestCase
.setUp(self
)
14 self
.config
= gitcfg
.current()
16 def test_string(self
):
17 """Test string values in get()."""
18 self
.git('config', 'test.value', 'test')
19 self
.assertEqual(self
.config
.get('test.value'), 'test')
22 """Test int values in get()."""
23 self
.git('config', 'test.int', '42')
24 self
.assertEqual(self
.config
.get('test.int'), 42)
27 """Test bool values in get()."""
28 self
.git('config', 'test.bool', 'true')
29 self
.assertEqual(self
.config
.get('test.bool'), True)
32 self
.git('config', 'test.bool', 'false')
33 self
.assertEqual(self
.config
.get('test.bool'), False)
36 self
.git('config', 'test.bool', 'yes')
37 self
.assertEqual(self
.config
.get('test.bool'), True)
40 self
.git('config', 'test.bool', 'no')
41 self
.assertEqual(self
.config
.get('test.bool'), False)
43 def test_bool_no_value(self
):
44 self
.append_file('.git/config', '[test]\n')
45 self
.append_file('.git/config', '\tbool\n')
46 self
.assertEqual(self
.config
.get('test.bool'), True)
48 def test_empty_value(self
):
49 self
.append_file('.git/config', '[test]\n')
50 self
.append_file('.git/config', '\tvalue = \n')
51 self
.assertEqual(self
.config
.get('test.value'), '')
53 def test_default(self
):
54 """Test default values in get()."""
55 self
.assertEqual(self
.config
.get('does.not.exist'), None)
56 self
.assertEqual(self
.config
.get('does.not.exist', default
=42), 42)
58 def test_guitool_opts(self
):
59 self
.git('config', 'guitool.hello world.cmd', 'hello world')
60 opts
= self
.config
.get_guitool_opts('hello world')
61 expect
= 'hello world'
63 self
.assertEqual(expect
, actual
)
65 def test_guitool_names(self
):
66 self
.git('config', 'guitool.hello meow.cmd', 'hello meow')
67 names
= self
.config
.get_guitool_names()
68 self
.assertTrue('hello meow' in names
)
70 def test_guitool_names_mixed_case(self
):
71 self
.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
72 names
= self
.config
.get_guitool_names()
73 self
.assertTrue('Meow Cat' in names
)
75 def test_find_mixed_case(self
):
76 self
.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
77 opts
= self
.config
.find('guitool.Meow Cat.*')
78 self
.assertEqual(opts
['guitool.Meow Cat.cmd'], 'cat hello')
80 def test_guitool_opts_mixed_case(self
):
81 self
.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
82 opts
= self
.config
.get_guitool_opts('Meow Cat')
83 self
.assertEqual(opts
['cmd'], 'cat hello')
86 if __name__
== '__main__':