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