Merge pull request #1385 from davvid/bindir
[git-cola.git] / test / gitcfg_test.py
blob8605162293baaf7ca6a98a1fbc0fc366074742ca
1 """Test the cola.gitcfg module."""
2 import pathlib
4 from . import helper
5 from .helper import app_context
8 # Prevent unused imports lint errors.
9 assert app_context is not None
12 def assert_color(context, expect, git_value, key='test', default=None):
13 """Helper function for testing color values"""
14 helper.run_git('config', 'cola.color.%s' % key, git_value)
15 context.cfg.reset()
16 actual = context.cfg.color(key, default)
17 assert expect == actual
20 def test_string(app_context):
21 """Test string values in get()."""
22 helper.run_git('config', 'test.value', 'test')
23 assert app_context.cfg.get('test.value') == 'test'
26 def test_int(app_context):
27 """Test int values in get()."""
28 helper.run_git('config', 'test.int', '42')
29 expect = 42
30 actual = app_context.cfg.get('test.int')
31 assert expect == actual
34 def test_true(app_context):
35 """Test bool values in get()."""
36 helper.run_git('config', 'test.bool', 'true')
37 assert app_context.cfg.get('test.bool') is True
40 def test_false(app_context):
41 helper.run_git('config', 'test.bool', 'false')
42 assert app_context.cfg.get('test.bool') is False
45 def test_yes(app_context):
46 helper.run_git('config', 'test.bool', 'yes')
47 assert app_context.cfg.get('test.bool') is True
50 def test_no(app_context):
51 helper.run_git('config', 'test.bool', 'no')
52 assert app_context.cfg.get('test.bool') is False
55 def test_bool_no_value(app_context):
56 helper.append_file('.git/config', '[test]\n')
57 helper.append_file('.git/config', '\tbool\n')
58 assert app_context.cfg.get('test.bool') is True
61 def test_empty_value(app_context):
62 helper.append_file('.git/config', '[test]\n')
63 helper.append_file('.git/config', '\tvalue = \n')
64 assert app_context.cfg.get('test.value') == ''
67 def test_default(app_context):
68 """Test default values in get()."""
69 assert app_context.cfg.get('does.not.exist') is None
70 assert app_context.cfg.get('does.not.exist', default=42) == 42
73 def test_get_all(app_context):
74 """Test getting multiple values in get_all()"""
75 helper.run_git('config', '--add', 'test.value', 'abc')
76 helper.run_git('config', '--add', 'test.value', 'def')
77 expect = ['abc', 'def']
78 assert expect == app_context.cfg.get_all('test.value')
81 def test_color_rrggbb(app_context):
82 assert_color(app_context, (0xAA, 0xBB, 0xCC), 'aabbcc')
83 assert_color(app_context, (0xAA, 0xBB, 0xCC), '#aabbcc')
86 def test_color_int(app_context):
87 assert_color(app_context, (0x10, 0x20, 0x30), '102030')
88 assert_color(app_context, (0x10, 0x20, 0x30), '#102030')
91 def test_guitool_opts(app_context):
92 helper.run_git('config', 'guitool.hello world.cmd', 'hello world')
93 opts = app_context.cfg.get_guitool_opts('hello world')
94 expect = 'hello world'
95 actual = opts['cmd']
96 assert expect == actual
99 def test_guitool_names(app_context):
100 helper.run_git('config', 'guitool.hello meow.cmd', 'hello meow')
101 names = app_context.cfg.get_guitool_names()
102 assert 'hello meow' in names
105 def test_guitool_names_mixed_case(app_context):
106 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
107 names = app_context.cfg.get_guitool_names()
108 assert 'Meow Cat' in names
111 def test_find_mixed_case(app_context):
112 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
113 opts = app_context.cfg.find('guitool.Meow Cat.*')
114 assert opts['guitool.Meow Cat.cmd'] == 'cat hello'
117 def test_guitool_opts_mixed_case(app_context):
118 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
119 opts = app_context.cfg.get_guitool_opts('Meow Cat')
120 assert opts['cmd'] == 'cat hello'
123 def test_hooks(app_context):
124 helper.run_git('config', 'core.hooksPath', '/test/hooks')
125 expect = '/test/hooks'
126 actual = app_context.cfg.hooks()
127 assert expect == actual
130 def test_hooks_lowercase(app_context):
131 helper.run_git('config', 'core.hookspath', '/test/hooks-lowercase')
132 expect = '/test/hooks-lowercase'
133 actual = app_context.cfg.hooks()
134 assert expect == actual
137 def test_hooks_path(app_context):
138 helper.run_git('config', 'core.hooksPath', str(pathlib.Path('/test/hooks')))
139 expect = str(pathlib.Path('/test/hooks/example'))
140 actual = app_context.cfg.hooks_path('example')
141 assert expect == actual
144 def test_hooks_path_lowercase(app_context):
145 helper.run_git(
146 'config', 'core.hookspath', str(pathlib.Path('/test/hooks-lowercase'))
148 expect = str(pathlib.Path('/test/hooks-lowercase/example'))
149 actual = app_context.cfg.hooks_path('example')
150 assert expect == actual