extras: pylint updates
[git-cola.git] / test / main_model_test.py
blob6c070c401b8d4cf56ec45e3294a61cff73852c56
1 from __future__ import absolute_import, division, unicode_literals
3 import os
4 import unittest
6 from cola import core
7 from cola.models import main
9 from . import helper
12 class MainModelTestCase(helper.GitRepositoryTestCase):
13 """Tests the MainModel class."""
15 def test_project(self):
16 """Test the 'project' attribute."""
17 project = os.path.basename(self.test_path())
18 self.model.set_worktree(core.getcwd())
19 self.assertEqual(self.model.project, project)
21 def test_local_branches(self):
22 """Test the 'local_branches' attribute."""
23 self.commit_files()
24 self.model.update_status()
25 self.assertEqual(self.model.local_branches, ['master'])
27 def test_remote_branches(self):
28 """Test the 'remote_branches' attribute."""
29 self.model.update_status()
30 self.assertEqual(self.model.remote_branches, [])
32 self.commit_files()
33 self.run_git('remote', 'add', 'origin', '.')
34 self.run_git('fetch', 'origin')
35 self.model.update_status()
36 self.assertEqual(self.model.remote_branches, ['origin/master'])
38 def test_modified(self):
39 """Test the 'modified' attribute."""
40 self.write_file('A', 'change')
41 self.model.update_status()
42 self.assertEqual(self.model.modified, ['A'])
44 def test_unstaged(self):
45 """Test the 'unstaged' attribute."""
46 self.write_file('A', 'change')
47 self.write_file('C', 'C')
48 self.model.update_status()
49 self.assertEqual(self.model.unstaged, ['A', 'C'])
51 def test_untracked(self):
52 """Test the 'untracked' attribute."""
53 self.write_file('C', 'C')
54 self.model.update_status()
55 self.assertEqual(self.model.untracked, ['C'])
57 def test_remotes(self):
58 """Test the 'remote' attribute."""
59 self.run_git('remote', 'add', 'origin', '.')
60 self.model.update_status()
61 self.assertEqual(self.model.remotes, ['origin'])
63 def test_currentbranch(self):
64 """Test the 'currentbranch' attribute."""
65 self.run_git('checkout', '-b', 'test')
66 self.model.update_status()
67 self.assertEqual(self.model.currentbranch, 'test')
69 def test_tags(self):
70 """Test the 'tags' attribute."""
71 self.commit_files()
72 self.run_git('tag', 'test')
73 self.model.update_status()
74 self.assertEqual(self.model.tags, ['test'])
77 class RemoteArgsTestCase(unittest.TestCase):
79 def setUp(self):
80 self.remote = 'server'
81 self.local_branch = 'local'
82 self.remote_branch = 'remote'
84 def test_remote_args_fetch(self):
85 # Fetch
86 (args, kwargs) = \
87 main.remote_args(self.remote,
88 local_branch=self.local_branch,
89 remote_branch=self.remote_branch)
91 self.assertEqual(args, [self.remote, 'remote:local'])
92 self.assertTrue(kwargs['verbose'])
93 self.assertFalse('tags' in kwargs)
94 self.assertFalse('rebase' in kwargs)
96 def test_remote_args_fetch_tags(self):
97 # Fetch tags
98 (args, kwargs) = \
99 main.remote_args(self.remote,
100 tags=True,
101 local_branch=self.local_branch,
102 remote_branch=self.remote_branch)
104 self.assertEqual(args, [self.remote, 'remote:local'])
105 self.assertTrue(kwargs['verbose'])
106 self.assertTrue(kwargs['tags'])
107 self.assertFalse('rebase' in kwargs)
109 def test_remote_args_pull(self):
110 # Pull
111 (args, kwargs) = \
112 main.remote_args(self.remote,
113 pull=True,
114 local_branch='',
115 remote_branch=self.remote_branch)
117 self.assertEqual(args, [self.remote, 'remote'])
118 self.assertTrue(kwargs['verbose'])
119 self.assertFalse('rebase' in kwargs)
120 self.assertFalse('tags' in kwargs)
122 def test_remote_args_pull_rebase(self):
123 # Rebasing pull
124 (args, kwargs) = \
125 main.remote_args(self.remote,
126 pull=True,
127 rebase=True,
128 local_branch='',
129 remote_branch=self.remote_branch)
131 self.assertEqual(args, [self.remote, 'remote'])
132 self.assertTrue(kwargs['verbose'])
133 self.assertTrue(kwargs['rebase'])
134 self.assertFalse('tags' in kwargs)
136 def test_remote_args_push(self):
137 # Push, swap local and remote
138 (args, kwargs) = \
139 main.remote_args(self.remote,
140 local_branch=self.remote_branch,
141 remote_branch=self.local_branch)
143 self.assertEqual(args, [self.remote, 'local:remote'])
144 self.assertTrue(kwargs['verbose'])
145 self.assertFalse('tags' in kwargs)
146 self.assertFalse('rebase' in kwargs)
148 def test_remote_args_push_tags(self):
149 # Push, swap local and remote
150 (args, kwargs) = \
151 main.remote_args(self.remote,
152 tags=True,
153 local_branch=self.remote_branch,
154 remote_branch=self.local_branch)
156 self.assertEqual(args, [self.remote, 'local:remote'])
157 self.assertTrue(kwargs['verbose'])
158 self.assertTrue(kwargs['tags'])
159 self.assertFalse('rebase' in kwargs)
161 def test_remote_args_push_same_remote_and_local(self):
162 (args, kwargs) = \
163 main.remote_args(self.remote,
164 tags=True,
165 local_branch=self.local_branch,
166 remote_branch=self.local_branch,
167 push=True)
169 self.assertEqual(args, [self.remote, 'local'])
170 self.assertTrue(kwargs['verbose'])
171 self.assertTrue(kwargs['tags'])
172 self.assertFalse('rebase' in kwargs)
174 def test_remote_args_push_set_upstream(self):
175 (args, kwargs) = \
176 main.remote_args(self.remote,
177 tags=True,
178 local_branch=self.local_branch,
179 remote_branch=self.local_branch,
180 push=True,
181 set_upstream=True)
183 self.assertEqual(args, [self.remote, 'local'])
184 self.assertTrue(kwargs['verbose'])
185 self.assertTrue(kwargs['tags'])
186 self.assertTrue(kwargs['set_upstream'])
187 self.assertFalse('rebase' in kwargs)
189 def test_remote_args_rebase_only(self):
190 (_, kwargs) = \
191 main.remote_args(self.remote,
192 pull=True,
193 rebase=True,
194 ff_only=True)
195 self.assertTrue(kwargs['rebase'])
196 self.assertFalse('ff_only' in kwargs)
198 def test_run_remote_action(self):
200 def passthrough(*args, **kwargs):
201 return (args, kwargs)
203 (args, kwargs) = \
204 main.run_remote_action(passthrough,
205 self.remote,
206 local_branch=self.local_branch,
207 remote_branch=self.remote_branch)
209 self.assertEqual(args, (self.remote, 'remote:local'))
210 self.assertTrue(kwargs['verbose'])
211 self.assertFalse('tags' in kwargs)
212 self.assertFalse('rebase' in kwargs)
215 if __name__ == '__main__':
216 unittest.main()