gitcmds: "globals to locals" micro-optimization
[git-cola.git] / test / test_cola_gitcmds.py
blob9e8ab319c498d39c8bf18cdf455df12dd794a6d1
1 import os
2 import unittest
4 import helper
5 from cola import gitcmds
8 class GitCmdsTestCase(helper.GitRepositoryTestCase):
9 """Tests the cola.gitcmds module."""
10 def test_currentbranch(self):
11 """Test current_branch()."""
12 self.assertEqual(gitcmds.current_branch(), 'master')
14 def test_branch_list_local(self):
15 """Test branch_list(remote=False)."""
16 self.assertEqual(gitcmds.branch_list(remote=False), ['master'])
18 def test_branch_list_remote(self):
19 """Test branch_list(remote=False)."""
20 self.assertEqual(gitcmds.branch_list(remote=True), [])
21 self.shell("""
22 git remote add origin . &&
23 git fetch origin > /dev/null 2>&1
24 """)
25 self.assertEqual(gitcmds.branch_list(remote=True), ['origin/master'])
26 self.shell('git remote rm origin')
27 self.assertEqual(gitcmds.branch_list(remote=True), [])
29 def test_default_remote(self):
30 """Test default_remote()."""
31 self.assertEqual(gitcmds.default_remote(), None)
32 self.shell('git config branch.master.remote test')
33 self.assertEqual(gitcmds.default_remote(), 'test')
35 def test_tracked_branch(self):
36 """Test tracked_branch()."""
37 self.assertEqual(gitcmds.tracked_branch(), None)
38 self.shell("""
39 git config branch.master.remote test &&
40 git config branch.master.merge refs/heads/master
41 """)
42 self.assertEqual(gitcmds.tracked_branch(), 'test/master')
44 def test_tracked_branch_other(self):
45 """Test tracked_branch('other')."""
46 self.assertEqual(gitcmds.tracked_branch('other'), None)
47 self.shell("""
48 git config branch.other.remote test &&
49 git config branch.other.merge refs/heads/other/branch
50 """)
51 self.assertEqual(gitcmds.tracked_branch('other'), 'test/other/branch')
53 def test_untracked_files(self):
54 """Test untracked_files()."""
55 self.shell('touch C D E')
56 self.assertEqual(gitcmds.untracked_files(), ['C', 'D', 'E'])
58 def test_tag_list(self):
59 """Test tag_list()."""
60 self.shell('git tag a && git tag b && git tag c')
61 self.assertEqual(gitcmds.tag_list(), ['c', 'b', 'a'])
63 def test_merge_message_path(self):
64 """Test merge_message_path()."""
65 self.shell('touch .git/SQUASH_MSG')
66 self.assertEqual(gitcmds.merge_message_path(),
67 os.path.abspath('.git/SQUASH_MSG'))
68 self.shell('touch .git/MERGE_MSG')
69 self.assertEqual(gitcmds.merge_message_path(),
70 os.path.abspath('.git/MERGE_MSG'))
71 os.unlink(gitcmds.merge_message_path())
72 self.assertEqual(gitcmds.merge_message_path(),
73 os.path.abspath('.git/SQUASH_MSG'))
74 os.unlink(gitcmds.merge_message_path())
75 self.assertEqual(gitcmds.merge_message_path(), None)
77 def test_all_refs(self):
78 self.shell("""
79 git branch a &&
80 git branch b &&
81 git branch c &&
82 git tag d &&
83 git tag e &&
84 git tag f &&
85 git remote add origin . &&
86 git fetch origin > /dev/null 2>&1
87 """)
88 refs = gitcmds.all_refs()
89 self.assertEqual(refs,
90 ['a', 'b', 'c', 'master',
91 'origin/a', 'origin/b', 'origin/c', 'origin/master',
92 'd', 'e', 'f'])
94 def test_all_refs_split(self):
95 self.shell("""
96 git branch a &&
97 git branch b &&
98 git branch c &&
99 git tag d &&
100 git tag e &&
101 git tag f &&
102 git remote add origin . &&
103 git fetch origin > /dev/null 2>&1
104 """)
105 local, remote, tags = gitcmds.all_refs(split=True)
106 self.assertEqual(local, ['a', 'b', 'c', 'master'])
107 self.assertEqual(remote, ['origin/a', 'origin/b', 'origin/c', 'origin/master'])
108 self.assertEqual(tags, ['d', 'e', 'f'])
111 if __name__ == '__main__':
112 unittest.main()