gitcmds_test: apply flake8 suggestions
[git-cola.git] / test / gitcmds_test.py
blob994cde0ab205cab369613cf66623cee9368849bf
1 from __future__ import absolute_import, division, unicode_literals
3 import os
4 import unittest
6 from cola import gitcmds
7 from cola import gitcfg
9 from test import helper
12 class GitCmdsTestCase(helper.GitRepositoryTestCase):
13 """Tests the cola.gitcmds module."""
14 def setUp(self):
15 helper.GitRepositoryTestCase.setUp(self)
16 self.config = gitcfg.GitConfig()
18 def test_currentbranch(self):
19 """Test current_branch()."""
20 self.assertEqual(gitcmds.current_branch(), 'master')
22 def test_branch_list_local(self):
23 """Test branch_list(remote=False)."""
24 self.assertEqual(gitcmds.branch_list(remote=False), ['master'])
26 def test_branch_list_remote(self):
27 """Test branch_list(remote=False)."""
28 self.assertEqual(gitcmds.branch_list(remote=True), [])
29 self.git('remote', 'add', 'origin', '.')
30 self.git('fetch', 'origin')
31 self.assertEqual(gitcmds.branch_list(remote=True), ['origin/master'])
32 self.git('remote', 'rm', 'origin')
33 self.assertEqual(gitcmds.branch_list(remote=True), [])
35 def test_default_remote(self):
36 """Test default_remote()."""
37 self.assertEqual(gitcmds.default_remote(config=self.config), None)
38 self.git('config', 'branch.master.remote', 'test')
39 self.config.reset()
40 self.assertEqual(gitcmds.default_remote(config=self.config), 'test')
42 def test_tracked_branch(self):
43 """Test tracked_branch()."""
44 self.assertEqual(gitcmds.tracked_branch(config=self.config), None)
45 self.git('config', 'branch.master.remote', 'test')
46 self.git('config', 'branch.master.merge', 'refs/heads/master')
47 self.config.reset()
48 self.assertEqual(gitcmds.tracked_branch(config=self.config),
49 'test/master')
51 def test_tracked_branch_other(self):
52 """Test tracked_branch('other')."""
53 self.assertEqual(gitcmds.tracked_branch('other', config=self.config),
54 None)
55 self.git('config', 'branch.other.remote', 'test')
56 self.git('config', 'branch.other.merge', 'refs/heads/other/branch')
57 self.config.reset()
58 self.assertEqual(gitcmds.tracked_branch('other', config=self.config),
59 'test/other/branch')
61 def test_untracked_files(self):
62 """Test untracked_files()."""
63 self.touch('C', 'D', 'E')
64 self.assertEqual(gitcmds.untracked_files(), ['C', 'D', 'E'])
66 def test_all_files(self):
67 self.touch('other-file')
68 all_files = gitcmds.all_files()
70 self.assertTrue('A' in all_files)
71 self.assertTrue('B' in all_files)
72 self.assertTrue('other-file' in all_files)
74 def test_tag_list(self):
75 """Test tag_list()."""
76 self.git('tag', 'a')
77 self.git('tag', 'b')
78 self.git('tag', 'c')
79 self.assertEqual(gitcmds.tag_list(), ['c', 'b', 'a'])
81 def test_merge_message_path(self):
82 """Test merge_message_path()."""
83 self.touch('.git/SQUASH_MSG')
84 self.assertEqual(gitcmds.merge_message_path(),
85 os.path.abspath('.git/SQUASH_MSG'))
86 self.touch('.git/MERGE_MSG')
87 self.assertEqual(gitcmds.merge_message_path(),
88 os.path.abspath('.git/MERGE_MSG'))
89 os.unlink(gitcmds.merge_message_path())
90 self.assertEqual(gitcmds.merge_message_path(),
91 os.path.abspath('.git/SQUASH_MSG'))
92 os.unlink(gitcmds.merge_message_path())
93 self.assertEqual(gitcmds.merge_message_path(), None)
95 def test_all_refs(self):
96 self.git('branch', 'a')
97 self.git('branch', 'b')
98 self.git('branch', 'c')
99 self.git('tag', 'd')
100 self.git('tag', 'e')
101 self.git('tag', 'f')
102 self.git('remote', 'add', 'origin', '.')
103 self.git('fetch', 'origin')
104 refs = gitcmds.all_refs()
105 self.assertEqual(refs,
106 ['a', 'b', 'c', 'master',
107 'origin/a', 'origin/b', 'origin/c', 'origin/master',
108 'd', 'e', 'f'])
110 def test_all_refs_split(self):
111 self.git('branch', 'a')
112 self.git('branch', 'b')
113 self.git('branch', 'c')
114 self.git('tag', 'd')
115 self.git('tag', 'e')
116 self.git('tag', 'f')
117 self.git('remote', 'add', 'origin', '.')
118 self.git('fetch', 'origin')
119 local, remote, tags = gitcmds.all_refs(split=True)
120 self.assertEqual(local, ['a', 'b', 'c', 'master'])
121 self.assertEqual(remote,
122 ['origin/a', 'origin/b', 'origin/c', 'origin/master'])
123 self.assertEqual(tags, ['d', 'e', 'f'])
126 if __name__ == '__main__':
127 unittest.main()