1 # pylint: disable=redefined-outer-name
2 from __future__
import absolute_import
, division
, print_function
, unicode_literals
9 from cola
.models
import main
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
20 LOCAL_BRANCH
= 'local'
21 REMOTE_BRANCH
= 'remote'
26 """Return a Mock context for testing"""
28 context
.git
= git
.create()
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."""
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
== []
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_remotes(app_context
):
81 """Test the 'remote' attribute."""
82 helper
.run_git('remote', 'add', 'origin', '.')
83 app_context
.model
.update_status()
84 assert app_context
.model
.remotes
== ['origin']
87 def test_currentbranch(app_context
):
88 """Test the 'currentbranch' attribute."""
89 helper
.run_git('checkout', '-b', 'test')
90 app_context
.model
.update_status()
91 assert app_context
.model
.currentbranch
== 'test'
94 def test_tags(app_context
):
95 """Test the 'tags' attribute."""
97 helper
.run_git('tag', 'test')
98 app_context
.model
.update_status()
99 assert app_context
.model
.tags
== ['test']
102 def test_remote_args_fetch(mock_context
):
104 (args
, kwargs
) = main
.remote_args(
107 local_branch
=LOCAL_BRANCH
,
108 remote_branch
=REMOTE_BRANCH
,
111 assert args
== [REMOTE
, 'remote:local']
112 assert kwargs
['verbose']
113 assert 'tags' not in kwargs
114 assert 'rebase' not in kwargs
117 def test_remote_args_fetch_tags(mock_context
):
119 (args
, kwargs
) = main
.remote_args(
123 local_branch
=LOCAL_BRANCH
,
124 remote_branch
=REMOTE_BRANCH
,
127 assert args
== [REMOTE
, 'remote:local']
128 assert kwargs
['verbose']
129 assert kwargs
['tags']
130 assert 'rebase' not in kwargs
133 def test_remote_args_pull(mock_context
):
135 (args
, kwargs
) = main
.remote_args(
140 remote_branch
=REMOTE_BRANCH
,
143 assert args
== [REMOTE
, 'remote']
144 assert kwargs
['verbose']
145 assert 'rebase' not in kwargs
146 assert 'tags' not in kwargs
149 def test_remote_args_pull_rebase(mock_context
):
151 (args
, kwargs
) = main
.remote_args(
157 remote_branch
=REMOTE_BRANCH
,
160 assert args
== [REMOTE
, 'remote']
161 assert kwargs
['verbose']
162 assert kwargs
['rebase']
163 assert 'tags' not in kwargs
166 def test_remote_args_push(mock_context
):
167 # Push, swap local and remote
168 (args
, kwargs
) = main
.remote_args(
171 local_branch
=REMOTE_BRANCH
,
172 remote_branch
=LOCAL_BRANCH
,
175 assert args
== [REMOTE
, 'local:remote']
176 assert kwargs
['verbose']
177 assert 'tags' not in kwargs
178 assert 'rebase' not in kwargs
181 def test_remote_args_push_tags(mock_context
):
182 # Push, swap local and remote
183 (args
, kwargs
) = main
.remote_args(
187 local_branch
=REMOTE_BRANCH
,
188 remote_branch
=LOCAL_BRANCH
,
191 assert args
== [REMOTE
, 'local:remote']
192 assert kwargs
['verbose']
193 assert kwargs
['tags']
194 assert 'rebase' not in kwargs
197 def test_remote_args_push_same_remote_and_local(mock_context
):
198 (args
, kwargs
) = main
.remote_args(
202 local_branch
=LOCAL_BRANCH
,
203 remote_branch
=LOCAL_BRANCH
,
207 assert args
== [REMOTE
, 'local']
208 assert kwargs
['verbose']
209 assert kwargs
['tags']
210 assert 'rebase' not in kwargs
213 def test_remote_args_push_set_upstream(mock_context
):
214 (args
, kwargs
) = main
.remote_args(
218 local_branch
=LOCAL_BRANCH
,
219 remote_branch
=LOCAL_BRANCH
,
224 assert args
== [REMOTE
, 'local']
225 assert kwargs
['verbose']
226 assert kwargs
['tags']
227 assert kwargs
['set_upstream']
228 assert 'rebase' not in kwargs
231 def test_remote_args_rebase_only(mock_context
):
232 (_
, kwargs
) = main
.remote_args(
233 mock_context
, REMOTE
, pull
=True, rebase
=True, ff_only
=True
235 assert kwargs
['rebase']
236 assert 'ff_only' not in kwargs
239 def test_run_remote_action(mock_context
):
240 def passthrough(*args
, **kwargs
):
241 return (args
, kwargs
)
243 (args
, kwargs
) = main
.run_remote_action(
247 local_branch
=LOCAL_BRANCH
,
248 remote_branch
=REMOTE_BRANCH
,
251 assert args
== (REMOTE
, 'remote:local')
252 assert kwargs
['verbose']
253 assert 'tags' not in kwargs
254 assert 'rebase' not in kwargs