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_stageable(app_context
):
81 """Test the 'stageable' attribute."""
82 assert not app_context
.model
.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
):
109 (args
, kwargs
) = main
.remote_args(
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
):
124 (args
, kwargs
) = main
.remote_args(
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
):
140 (args
, kwargs
) = main
.remote_args(
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
):
156 (args
, kwargs
) = main
.remote_args(
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(
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(
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(
207 local_branch
=LOCAL_BRANCH
,
208 remote_branch
=LOCAL_BRANCH
,
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(
223 local_branch
=LOCAL_BRANCH
,
224 remote_branch
=LOCAL_BRANCH
,
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(
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