git-cola v1.9.0
[git-cola.git] / test / test_cola_git_ops.py
blobcf946faf72f4f06392603b7e662628edb0ce43c3
1 #!/usr/bin/env python
2 """Tests basic git operations: commit, log, config"""
3 import os
4 import unittest
6 import helper
7 from cola.main.model import MainModel
9 class ColaBasicGitTestCase(helper.GitRepositoryTestCase):
11 def setUp(self):
12 helper.GitRepositoryTestCase.setUp(self, commit=False)
14 def test_git_commit(self):
15 """Test running 'git commit' via cola.git"""
16 self.shell("""
17 echo A > A
18 echo B > B
19 git add A B
20 """)
22 model = MainModel(cwd=os.getcwd())
23 model.git.commit(m='commit test')
24 log = helper.pipe('git log --pretty=oneline | wc -l')
26 self.assertEqual(log.strip(), '1')
28 def test_git_config(self):
29 """Test cola.git.config()"""
30 self.shell('git config section.key value')
31 model = MainModel(cwd=os.getcwd())
32 value = model.git.config('section.key', get=True)
34 self.assertEqual(value, (0, 'value', ''))
36 # Test config_set
37 model.config_set('section.bool', True)
38 value = model.git.config('section.bool', get=True)
40 self.assertEqual(value, (0, 'true', ''))
41 model.config_set('section.bool', False)
43 # Test config_dict
44 config_dict = model.config_dict(local=True)
46 self.assertEqual(config_dict['section_key'], 'value')
47 self.assertEqual(config_dict['section_bool'], False)
49 # Test config_dict --global
50 global_dict = model.config_dict(local=False)
52 self.assertEqual(type(global_dict), dict)
55 if __name__ == '__main__':
56 unittest.main()