pylint: remove bad-option-value from the configuration
[git-cola.git] / test / main_model_test.py
blobe1cde576e46182a0ae8c9b1a35336e0eb844ee07
1 # pylint: disable=redefined-outer-name
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 import os
5 import pytest
7 from cola import core
8 from cola import git
9 from cola.models import main
11 from . import helper
12 from .helper import app_context
13 from .helper import Mock
16 # These assertions make flake8 happy. It considers them unused imports otherwise.
17 assert app_context is not None
19 REMOTE = 'server'
20 LOCAL_BRANCH = 'local'
21 REMOTE_BRANCH = 'remote'
24 @pytest.fixture
25 def mock_context():
26 """Return a Mock context for testing"""
27 context = Mock()
28 context.git = git.create()
29 return context
32 def test_project(app_context):
33 """Test the 'project' attribute."""
34 project = os.path.basename(core.getcwd())
35 app_context.model.set_worktree(core.getcwd())
36 assert app_context.model.project == project
39 def test_local_branches(app_context):
40 """Test the 'local_branches' attribute."""
41 helper.commit_files()
42 app_context.model.update_status()
43 assert app_context.model.local_branches == ['main']
46 def test_remote_branches(app_context):
47 """Test the 'remote_branches' attribute."""
48 app_context.model.update_status()
49 assert app_context.model.remote_branches == []
51 helper.commit_files()
52 helper.run_git('remote', 'add', 'origin', '.')
53 helper.run_git('fetch', 'origin')
54 app_context.model.update_status()
55 assert app_context.model.remote_branches == ['origin/main']
58 def test_modified(app_context):
59 """Test the 'modified' attribute."""
60 helper.write_file('A', 'change')
61 app_context.model.update_status()
62 assert app_context.model.modified == ['A']
65 def test_unstaged(app_context):
66 """Test the 'unstaged' attribute."""
67 helper.write_file('A', 'change')
68 helper.write_file('C', 'C')
69 app_context.model.update_status()
70 assert app_context.model.unstaged == ['A', 'C']
73 def test_untracked(app_context):
74 """Test the 'untracked' attribute."""
75 helper.write_file('C', 'C')
76 app_context.model.update_status()
77 assert app_context.model.untracked == ['C']
80 def test_stageable(app_context):
81 """Test the 'stageable' attribute."""
82 assert not app_context.model.is_stageable()
85 def test_remotes(app_context):
86 """Test the 'remote' attribute."""
87 helper.run_git('remote', 'add', 'origin', '.')
88 app_context.model.update_status()
89 assert app_context.model.remotes == ['origin']
92 def test_currentbranch(app_context):
93 """Test the 'currentbranch' attribute."""
94 helper.run_git('checkout', '-b', 'test')
95 app_context.model.update_status()
96 assert app_context.model.currentbranch == 'test'
99 def test_tags(app_context):
100 """Test the 'tags' attribute."""
101 helper.commit_files()
102 helper.run_git('tag', 'test')
103 app_context.model.update_status()
104 assert app_context.model.tags == ['test']
107 def test_remote_args_fetch(mock_context):
108 # Fetch
109 (args, kwargs) = main.remote_args(
110 mock_context,
111 REMOTE,
112 local_branch=LOCAL_BRANCH,
113 remote_branch=REMOTE_BRANCH,
116 assert args == [REMOTE, 'remote:local']
117 assert kwargs['verbose']
118 assert 'tags' not in kwargs
119 assert 'rebase' not in kwargs
122 def test_remote_args_fetch_tags(mock_context):
123 # Fetch tags
124 (args, kwargs) = main.remote_args(
125 mock_context,
126 REMOTE,
127 tags=True,
128 local_branch=LOCAL_BRANCH,
129 remote_branch=REMOTE_BRANCH,
132 assert args == [REMOTE, 'remote:local']
133 assert kwargs['verbose']
134 assert kwargs['tags']
135 assert 'rebase' not in kwargs
138 def test_remote_args_pull(mock_context):
139 # Pull
140 (args, kwargs) = main.remote_args(
141 mock_context,
142 REMOTE,
143 pull=True,
144 local_branch='',
145 remote_branch=REMOTE_BRANCH,
148 assert args == [REMOTE, 'remote']
149 assert kwargs['verbose']
150 assert 'rebase' not in kwargs
151 assert 'tags' not in kwargs
154 def test_remote_args_pull_rebase(mock_context):
155 # Rebasing pull
156 (args, kwargs) = main.remote_args(
157 mock_context,
158 REMOTE,
159 pull=True,
160 rebase=True,
161 local_branch='',
162 remote_branch=REMOTE_BRANCH,
165 assert args == [REMOTE, 'remote']
166 assert kwargs['verbose']
167 assert kwargs['rebase']
168 assert 'tags' not in kwargs
171 def test_remote_args_push(mock_context):
172 # Push, swap local and remote
173 (args, kwargs) = main.remote_args(
174 mock_context,
175 REMOTE,
176 local_branch=REMOTE_BRANCH,
177 remote_branch=LOCAL_BRANCH,
180 assert args == [REMOTE, 'local:remote']
181 assert kwargs['verbose']
182 assert 'tags' not in kwargs
183 assert 'rebase' not in kwargs
186 def test_remote_args_push_tags(mock_context):
187 # Push, swap local and remote
188 (args, kwargs) = main.remote_args(
189 mock_context,
190 REMOTE,
191 tags=True,
192 local_branch=REMOTE_BRANCH,
193 remote_branch=LOCAL_BRANCH,
196 assert args == [REMOTE, 'local:remote']
197 assert kwargs['verbose']
198 assert kwargs['tags']
199 assert 'rebase' not in kwargs
202 def test_remote_args_push_same_remote_and_local(mock_context):
203 (args, kwargs) = main.remote_args(
204 mock_context,
205 REMOTE,
206 tags=True,
207 local_branch=LOCAL_BRANCH,
208 remote_branch=LOCAL_BRANCH,
209 push=True,
212 assert args == [REMOTE, 'local']
213 assert kwargs['verbose']
214 assert kwargs['tags']
215 assert 'rebase' not in kwargs
218 def test_remote_args_push_set_upstream(mock_context):
219 (args, kwargs) = main.remote_args(
220 mock_context,
221 REMOTE,
222 tags=True,
223 local_branch=LOCAL_BRANCH,
224 remote_branch=LOCAL_BRANCH,
225 push=True,
226 set_upstream=True,
229 assert args == [REMOTE, 'local']
230 assert kwargs['verbose']
231 assert kwargs['tags']
232 assert kwargs['set_upstream']
233 assert 'rebase' not in kwargs
236 def test_remote_args_rebase_only(mock_context):
237 (_, kwargs) = main.remote_args(
238 mock_context, REMOTE, pull=True, rebase=True, ff_only=True
240 assert kwargs['rebase']
241 assert 'ff_only' not in kwargs
244 def test_run_remote_action(mock_context):
245 def passthrough(*args, **kwargs):
246 return (args, kwargs)
248 (args, kwargs) = main.run_remote_action(
249 mock_context,
250 passthrough,
251 REMOTE,
252 local_branch=LOCAL_BRANCH,
253 remote_branch=REMOTE_BRANCH,
256 assert args == (REMOTE, 'remote:local')
257 assert kwargs['verbose']
258 assert 'tags' not in kwargs
259 assert 'rebase' not in kwargs