submodules: address pylint warnings
[git-cola.git] / test / gitcmds_test.py
blob547e98328d2c1d7427a4d85378f9fe626ff8e8eb
1 from __future__ import absolute_import, division, unicode_literals
2 import os
3 import unittest
5 from cola import gitcmds
7 from . import helper
10 class GitCmdsTestCase(helper.GitRepositoryTestCase):
11 """Tests the cola.gitcmds module."""
13 def test_currentbranch(self):
14 """Test current_branch()."""
15 self.assertEqual(gitcmds.current_branch(self.context), 'main')
17 def test_branch_list_local(self):
18 """Test branch_list(remote=False)."""
19 context = self.context
20 self.commit_files()
21 expect = ['main']
22 actual = gitcmds.branch_list(context, remote=False)
23 self.assertEqual(expect, actual)
25 def test_branch_list_remote(self):
26 """Test branch_list(remote=False)."""
27 context = self.context
28 expect = []
29 actual = gitcmds.branch_list(context, remote=True)
30 self.assertEqual(expect, actual)
32 self.commit_files()
33 self.run_git('remote', 'add', 'origin', '.')
34 self.run_git('fetch', 'origin')
35 expect = ['origin/main']
36 actual = gitcmds.branch_list(context, remote=True)
37 self.assertEqual(expect, actual)
39 self.run_git('remote', 'rm', 'origin')
40 expect = []
41 actual = gitcmds.branch_list(context, remote=True)
42 self.assertEqual(expect, actual)
44 def test_upstream_remote(self):
45 """Test getting the configured upstream remote"""
46 context = self.context
47 self.assertEqual(gitcmds.upstream_remote(context), None)
48 self.run_git('config', 'branch.main.remote', 'test')
49 self.cfg.reset()
50 self.assertEqual(gitcmds.upstream_remote(context), 'test')
52 def test_tracked_branch(self):
53 """Test tracked_branch()."""
54 context = self.context
55 self.assertEqual(gitcmds.tracked_branch(context), None)
56 self.run_git('config', 'branch.main.remote', 'test')
57 self.run_git('config', 'branch.main.merge', 'refs/heads/main')
58 self.cfg.reset()
59 self.assertEqual(gitcmds.tracked_branch(context), 'test/main')
61 def test_tracked_branch_other(self):
62 """Test tracked_branch('other')."""
63 context = self.context
64 self.assertEqual(gitcmds.tracked_branch(context, 'other'), None)
65 self.run_git('config', 'branch.other.remote', 'test')
66 self.run_git('config', 'branch.other.merge', 'refs/heads/other/branch')
67 self.cfg.reset()
68 self.assertEqual(gitcmds.tracked_branch(context, 'other'), 'test/other/branch')
70 def test_untracked_files(self):
71 """Test untracked_files()."""
72 context = self.context
73 self.touch('C', 'D', 'E')
74 self.assertEqual(gitcmds.untracked_files(context), ['C', 'D', 'E'])
76 def test_all_files(self):
77 context = self.context
78 self.touch('other-file')
79 all_files = gitcmds.all_files(context)
81 self.assertTrue('A' in all_files)
82 self.assertTrue('B' in all_files)
83 self.assertTrue('other-file' in all_files)
85 def test_tag_list(self):
86 """Test tag_list()."""
87 context = self.context
88 self.commit_files()
89 self.run_git('tag', 'a')
90 self.run_git('tag', 'b')
91 self.run_git('tag', 'c')
92 self.assertEqual(gitcmds.tag_list(context), ['c', 'b', 'a'])
94 def test_merge_message_path(self):
95 """Test merge_message_path()."""
96 context = self.context
97 self.touch('.git/SQUASH_MSG')
98 self.assertEqual(
99 gitcmds.merge_message_path(context), os.path.abspath('.git/SQUASH_MSG')
101 self.touch('.git/MERGE_MSG')
102 self.assertEqual(
103 gitcmds.merge_message_path(context), os.path.abspath('.git/MERGE_MSG')
105 os.unlink(gitcmds.merge_message_path(context))
106 self.assertEqual(
107 gitcmds.merge_message_path(context), os.path.abspath('.git/SQUASH_MSG')
109 os.unlink(gitcmds.merge_message_path(context))
110 self.assertEqual(gitcmds.merge_message_path(context), None)
112 def test_all_refs(self):
113 self.commit_files()
114 self.run_git('branch', 'a')
115 self.run_git('branch', 'b')
116 self.run_git('branch', 'c')
117 self.run_git('tag', 'd')
118 self.run_git('tag', 'e')
119 self.run_git('tag', 'f')
120 self.run_git('remote', 'add', 'origin', '.')
121 self.run_git('fetch', 'origin')
122 refs = gitcmds.all_refs(self.context)
123 self.assertEqual(
124 refs,
126 'a',
127 'b',
128 'c',
129 'main',
130 'origin/a',
131 'origin/b',
132 'origin/c',
133 'origin/main',
134 'f',
135 'e',
136 'd',
140 def test_all_refs_split(self):
141 self.commit_files()
142 self.run_git('branch', 'a')
143 self.run_git('branch', 'b')
144 self.run_git('branch', 'c')
145 self.run_git('tag', 'd')
146 self.run_git('tag', 'e')
147 self.run_git('tag', 'f')
148 self.run_git('remote', 'add', 'origin', '.')
149 self.run_git('fetch', 'origin')
150 local, remote, tags = gitcmds.all_refs(self.context, split=True)
151 self.assertEqual(local, ['a', 'b', 'c', 'main'])
152 self.assertEqual(remote, ['origin/a', 'origin/b', 'origin/c', 'origin/main'])
153 self.assertEqual(tags, ['f', 'e', 'd'])
156 if __name__ == '__main__':
157 unittest.main()