CHANGES: mention the improvements from #1205 and #1206
[git-cola.git] / test / gitcfg_test.py
blob88358ed6f72d585cc6fc42b390065005afc93309
1 """Test the cola.gitcfg module."""
2 # pylint: disable=redefined-outer-name
3 from __future__ import absolute_import, division, print_function, unicode_literals
5 from . import helper
6 from .helper import app_context
9 # These assertions make flake8 happy. It considers them unused imports otherwise.
10 assert app_context is not None
13 def assert_color(context, expect, git_value, key='test', default=None):
14 """Helper function for testing color values"""
15 helper.run_git('config', 'cola.color.%s' % key, git_value)
16 context.cfg.reset()
17 actual = context.cfg.color(key, default)
18 assert expect == actual
21 def test_string(app_context):
22 """Test string values in get()."""
23 helper.run_git('config', 'test.value', 'test')
24 assert app_context.cfg.get('test.value') == 'test'
27 def test_int(app_context):
28 """Test int values in get()."""
29 helper.run_git('config', 'test.int', '42')
30 expect = 42
31 actual = app_context.cfg.get('test.int')
32 assert expect == actual
35 def test_true(app_context):
36 """Test bool values in get()."""
37 helper.run_git('config', 'test.bool', 'true')
38 assert app_context.cfg.get('test.bool') is True
41 def test_false(app_context):
42 helper.run_git('config', 'test.bool', 'false')
43 assert app_context.cfg.get('test.bool') is False
46 def test_yes(app_context):
47 helper.run_git('config', 'test.bool', 'yes')
48 assert app_context.cfg.get('test.bool') is True
51 def test_no(app_context):
52 helper.run_git('config', 'test.bool', 'no')
53 assert app_context.cfg.get('test.bool') is False
56 def test_bool_no_value(app_context):
57 helper.append_file('.git/config', '[test]\n')
58 helper.append_file('.git/config', '\tbool\n')
59 assert app_context.cfg.get('test.bool') is True
62 def test_empty_value(app_context):
63 helper.append_file('.git/config', '[test]\n')
64 helper.append_file('.git/config', '\tvalue = \n')
65 assert app_context.cfg.get('test.value') == ''
68 def test_default(app_context):
69 """Test default values in get()."""
70 assert app_context.cfg.get('does.not.exist') is None
71 assert app_context.cfg.get('does.not.exist', default=42) == 42
74 def test_get_all(app_context):
75 """Test getting multiple values in get_all()"""
76 helper.run_git('config', '--add', 'test.value', 'abc')
77 helper.run_git('config', '--add', 'test.value', 'def')
78 expect = ['abc', 'def']
79 assert expect == app_context.cfg.get_all('test.value')
82 def test_color_rrggbb(app_context):
83 assert_color(app_context, (0xAA, 0xBB, 0xCC), 'aabbcc')
84 assert_color(app_context, (0xAA, 0xBB, 0xCC), '#aabbcc')
87 def test_color_int(app_context):
88 assert_color(app_context, (0x10, 0x20, 0x30), '102030')
89 assert_color(app_context, (0x10, 0x20, 0x30), '#102030')
92 def test_guitool_opts(app_context):
93 helper.run_git('config', 'guitool.hello world.cmd', 'hello world')
94 opts = app_context.cfg.get_guitool_opts('hello world')
95 expect = 'hello world'
96 actual = opts['cmd']
97 assert expect == actual
100 def test_guitool_names(app_context):
101 helper.run_git('config', 'guitool.hello meow.cmd', 'hello meow')
102 names = app_context.cfg.get_guitool_names()
103 assert 'hello meow' in names
106 def test_guitool_names_mixed_case(app_context):
107 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
108 names = app_context.cfg.get_guitool_names()
109 assert 'Meow Cat' in names
112 def test_find_mixed_case(app_context):
113 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
114 opts = app_context.cfg.find('guitool.Meow Cat.*')
115 assert opts['guitool.Meow Cat.cmd'] == 'cat hello'
118 def test_guitool_opts_mixed_case(app_context):
119 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
120 opts = app_context.cfg.get_guitool_opts('Meow Cat')
121 assert opts['cmd'] == 'cat hello'
124 def test_hooks(app_context):
125 helper.run_git('config', 'core.hooksPath', '/test/hooks')
126 expect = '/test/hooks'
127 actual = app_context.cfg.hooks()
128 assert expect == actual
131 def test_hooks_lowercase(app_context):
132 helper.run_git('config', 'core.hookspath', '/test/hooks-lowercase')
133 expect = '/test/hooks-lowercase'
134 actual = app_context.cfg.hooks()
135 assert expect == actual
138 def test_hooks_path(app_context):
139 helper.run_git('config', 'core.hooksPath', '/test/hooks')
140 expect = '/test/hooks/example'
141 actual = app_context.cfg.hooks_path('example')
142 assert expect == actual
145 def test_hooks_path_lowercase(app_context):
146 helper.run_git('config', 'core.hookspath', '/test/hooks-lowercase')
147 expect = '/test/hooks-lowercase/example'
148 actual = app_context.cfg.hooks_path('example')
149 assert expect == actual