dag: add commits_were_invalidated method to Edge
[git-cola.git] / test / gitcfg_test.py
blobe3095a2f23071e6e18c62642d7b6a174e9daf8b9
1 from __future__ import absolute_import, division, unicode_literals
3 import unittest
5 from cola import gitcfg
7 from test import helper
10 class GitConfigTestCase(helper.GitRepositoryTestCase):
11 """Tests the cola.gitcmds module."""
12 def setUp(self):
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')
21 def test_int(self):
22 """Test int values in get()."""
23 self.git('config', 'test.int', '42')
24 self.assertEqual(self.config.get('test.int'), 42)
26 def test_true(self):
27 """Test bool values in get()."""
28 self.git('config', 'test.bool', 'true')
29 self.assertEqual(self.config.get('test.bool'), True)
31 def test_false(self):
32 self.git('config', 'test.bool', 'false')
33 self.assertEqual(self.config.get('test.bool'), False)
35 def test_yes(self):
36 self.git('config', 'test.bool', 'yes')
37 self.assertEqual(self.config.get('test.bool'), True)
39 def test_no(self):
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_get_all(self):
59 """Test getting multiple values in get_all()"""
60 self.git('config', '--add', 'test.value', 'abc')
61 self.git('config', '--add', 'test.value', 'def')
62 expect = ['abc', 'def']
63 self.assertEqual(expect, self.config.get_all('test.value'))
65 def test_guitool_opts(self):
66 self.git('config', 'guitool.hello world.cmd', 'hello world')
67 opts = self.config.get_guitool_opts('hello world')
68 expect = 'hello world'
69 actual = opts['cmd']
70 self.assertEqual(expect, actual)
72 def test_guitool_names(self):
73 self.git('config', 'guitool.hello meow.cmd', 'hello meow')
74 names = self.config.get_guitool_names()
75 self.assertTrue('hello meow' in names)
77 def test_guitool_names_mixed_case(self):
78 self.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
79 names = self.config.get_guitool_names()
80 self.assertTrue('Meow Cat' in names)
82 def test_find_mixed_case(self):
83 self.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
84 opts = self.config.find('guitool.Meow Cat.*')
85 self.assertEqual(opts['guitool.Meow Cat.cmd'], 'cat hello')
87 def test_guitool_opts_mixed_case(self):
88 self.git('config', 'guitool.Meow Cat.cmd', 'cat hello')
89 opts = self.config.get_guitool_opts('Meow Cat')
90 self.assertEqual(opts['cmd'], 'cat hello')
93 if __name__ == '__main__':
94 unittest.main()