Makefile: remove references to unused "tags"
[git-cola.git] / test / gitcfg_test.py
blob86dcbf0c0ee538c70538e9d649916ed1af52922d
1 """Test the cola.gitcfg module."""
2 # pylint: disable=redefined-outer-name
4 import pathlib
6 from . import helper
7 from .helper import app_context
10 # These assertions make pylint happy. It considers them unused imports otherwise.
11 assert app_context is not None
14 def assert_color(context, expect, git_value, key='test', default=None):
15 """Helper function for testing color values"""
16 helper.run_git('config', 'cola.color.%s' % key, git_value)
17 context.cfg.reset()
18 actual = context.cfg.color(key, default)
19 assert expect == actual
22 def test_string(app_context):
23 """Test string values in get()."""
24 helper.run_git('config', 'test.value', 'test')
25 assert app_context.cfg.get('test.value') == 'test'
28 def test_int(app_context):
29 """Test int values in get()."""
30 helper.run_git('config', 'test.int', '42')
31 expect = 42
32 actual = app_context.cfg.get('test.int')
33 assert expect == actual
36 def test_true(app_context):
37 """Test bool values in get()."""
38 helper.run_git('config', 'test.bool', 'true')
39 assert app_context.cfg.get('test.bool') is True
42 def test_false(app_context):
43 helper.run_git('config', 'test.bool', 'false')
44 assert app_context.cfg.get('test.bool') is False
47 def test_yes(app_context):
48 helper.run_git('config', 'test.bool', 'yes')
49 assert app_context.cfg.get('test.bool') is True
52 def test_no(app_context):
53 helper.run_git('config', 'test.bool', 'no')
54 assert app_context.cfg.get('test.bool') is False
57 def test_bool_no_value(app_context):
58 helper.append_file('.git/config', '[test]\n')
59 helper.append_file('.git/config', '\tbool\n')
60 assert app_context.cfg.get('test.bool') is True
63 def test_empty_value(app_context):
64 helper.append_file('.git/config', '[test]\n')
65 helper.append_file('.git/config', '\tvalue = \n')
66 assert app_context.cfg.get('test.value') == ''
69 def test_default(app_context):
70 """Test default values in get()."""
71 assert app_context.cfg.get('does.not.exist') is None
72 assert app_context.cfg.get('does.not.exist', default=42) == 42
75 def test_get_all(app_context):
76 """Test getting multiple values in get_all()"""
77 helper.run_git('config', '--add', 'test.value', 'abc')
78 helper.run_git('config', '--add', 'test.value', 'def')
79 expect = ['abc', 'def']
80 assert expect == app_context.cfg.get_all('test.value')
83 def test_color_rrggbb(app_context):
84 assert_color(app_context, (0xAA, 0xBB, 0xCC), 'aabbcc')
85 assert_color(app_context, (0xAA, 0xBB, 0xCC), '#aabbcc')
88 def test_color_int(app_context):
89 assert_color(app_context, (0x10, 0x20, 0x30), '102030')
90 assert_color(app_context, (0x10, 0x20, 0x30), '#102030')
93 def test_guitool_opts(app_context):
94 helper.run_git('config', 'guitool.hello world.cmd', 'hello world')
95 opts = app_context.cfg.get_guitool_opts('hello world')
96 expect = 'hello world'
97 actual = opts['cmd']
98 assert expect == actual
101 def test_guitool_names(app_context):
102 helper.run_git('config', 'guitool.hello meow.cmd', 'hello meow')
103 names = app_context.cfg.get_guitool_names()
104 assert 'hello meow' in names
107 def test_guitool_names_mixed_case(app_context):
108 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
109 names = app_context.cfg.get_guitool_names()
110 assert 'Meow Cat' in names
113 def test_find_mixed_case(app_context):
114 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
115 opts = app_context.cfg.find('guitool.Meow Cat.*')
116 assert opts['guitool.Meow Cat.cmd'] == 'cat hello'
119 def test_guitool_opts_mixed_case(app_context):
120 helper.run_git('config', 'guitool.Meow Cat.cmd', 'cat hello')
121 opts = app_context.cfg.get_guitool_opts('Meow Cat')
122 assert opts['cmd'] == 'cat hello'
125 def test_hooks(app_context):
126 helper.run_git('config', 'core.hooksPath', '/test/hooks')
127 expect = '/test/hooks'
128 actual = app_context.cfg.hooks()
129 assert expect == actual
132 def test_hooks_lowercase(app_context):
133 helper.run_git('config', 'core.hookspath', '/test/hooks-lowercase')
134 expect = '/test/hooks-lowercase'
135 actual = app_context.cfg.hooks()
136 assert expect == actual
139 def test_hooks_path(app_context):
140 helper.run_git('config', 'core.hooksPath', str(pathlib.Path('/test/hooks')))
141 expect = str(pathlib.Path('/test/hooks/example'))
142 actual = app_context.cfg.hooks_path('example')
143 assert expect == actual
146 def test_hooks_path_lowercase(app_context):
147 helper.run_git(
148 'config', 'core.hookspath', str(pathlib.Path('/test/hooks-lowercase'))
150 expect = str(pathlib.Path('/test/hooks-lowercase/example'))
151 actual = app_context.cfg.hooks_path('example')
152 assert expect == actual