shortcuts: Move the keyboard shortcuts into an html file
[git-cola.git] / test / test_cola_gitcmds.py
blobf43a6219c0fd2d6dff83e7dd7f5524201964c274
1 import os
2 import time
3 import unittest
5 import helper
6 from cola import gitcmds
7 from cola import gitcfg
10 class GitCmdsTestCase(helper.GitRepositoryTestCase):
11 """Tests the cola.gitcmds module."""
12 def setUp(self):
13 helper.GitRepositoryTestCase.setUp(self)
14 self.config = gitcfg.GitConfig()
16 def test_currentbranch(self):
17 """Test current_branch()."""
18 self.assertEqual(gitcmds.current_branch(), 'master')
20 def test_branch_list_local(self):
21 """Test branch_list(remote=False)."""
22 self.assertEqual(gitcmds.branch_list(remote=False), ['master'])
24 def test_branch_list_remote(self):
25 """Test branch_list(remote=False)."""
26 self.assertEqual(gitcmds.branch_list(remote=True), [])
27 self.shell("""
28 git remote add origin . &&
29 git fetch origin > /dev/null 2>&1
30 """)
31 self.assertEqual(gitcmds.branch_list(remote=True), ['origin/master'])
32 self.shell('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.shell('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.shell("""
46 git config branch.master.remote test &&
47 git config branch.master.merge refs/heads/master
48 """)
49 self.config.reset()
50 self.assertEqual(gitcmds.tracked_branch(config=self.config),
51 'test/master')
53 def test_tracked_branch_other(self):
54 """Test tracked_branch('other')."""
55 self.assertEqual(gitcmds.tracked_branch('other', config=self.config),
56 None)
57 self.shell("""
58 git config branch.other.remote test &&
59 git config branch.other.merge refs/heads/other/branch
60 """)
61 self.config.reset()
62 self.assertEqual(gitcmds.tracked_branch('other', config=self.config),
63 'test/other/branch')
65 def test_untracked_files(self):
66 """Test untracked_files()."""
67 self.shell('touch C D E')
68 self.assertEqual(gitcmds.untracked_files(), ['C', 'D', 'E'])
70 def test_tag_list(self):
71 """Test tag_list()."""
72 self.shell('git tag a && git tag b && git tag c')
73 self.assertEqual(gitcmds.tag_list(), ['c', 'b', 'a'])
75 def test_merge_message_path(self):
76 """Test merge_message_path()."""
77 self.shell('touch .git/SQUASH_MSG')
78 self.assertEqual(gitcmds.merge_message_path(),
79 os.path.abspath('.git/SQUASH_MSG'))
80 self.shell('touch .git/MERGE_MSG')
81 self.assertEqual(gitcmds.merge_message_path(),
82 os.path.abspath('.git/MERGE_MSG'))
83 os.unlink(gitcmds.merge_message_path())
84 self.assertEqual(gitcmds.merge_message_path(),
85 os.path.abspath('.git/SQUASH_MSG'))
86 os.unlink(gitcmds.merge_message_path())
87 self.assertEqual(gitcmds.merge_message_path(), None)
89 def test_all_refs(self):
90 self.shell("""
91 git branch a &&
92 git branch b &&
93 git branch c &&
94 git tag d &&
95 git tag e &&
96 git tag f &&
97 git remote add origin . &&
98 git fetch origin > /dev/null 2>&1
99 """)
100 refs = gitcmds.all_refs()
101 self.assertEqual(refs,
102 ['a', 'b', 'c', 'master',
103 'origin/a', 'origin/b', 'origin/c', 'origin/master',
104 'd', 'e', 'f'])
106 def test_all_refs_split(self):
107 self.shell("""
108 git branch a &&
109 git branch b &&
110 git branch c &&
111 git tag d &&
112 git tag e &&
113 git tag f &&
114 git remote add origin . &&
115 git fetch origin > /dev/null 2>&1
116 """)
117 local, remote, tags = gitcmds.all_refs(split=True)
118 self.assertEqual(local, ['a', 'b', 'c', 'master'])
119 self.assertEqual(remote, ['origin/a', 'origin/b', 'origin/c', 'origin/master'])
120 self.assertEqual(tags, ['d', 'e', 'f'])
123 if __name__ == '__main__':
124 unittest.main()