1 # pylint: disable=redefined-outer-name
8 from cola
.models
import main
11 from .helper
import app_context
12 from .helper
import Mock
15 # These assertions make pylint happy. It considers them unused imports otherwise.
16 assert app_context
is not None
19 LOCAL_BRANCH
= 'local'
20 REMOTE_BRANCH
= 'remote'
25 """Return a Mock context for testing"""
27 context
.git
= git
.create()
31 def test_project(app_context
):
32 """Test the 'project' attribute."""
33 project
= os
.path
.basename(core
.getcwd())
34 app_context
.model
.set_worktree(core
.getcwd())
35 assert app_context
.model
.project
== project
38 def test_local_branches(app_context
):
39 """Test the 'local_branches' attribute."""
41 app_context
.model
.update_status()
42 assert app_context
.model
.local_branches
== ['main']
45 def test_remote_branches(app_context
):
46 """Test the 'remote_branches' attribute."""
47 app_context
.model
.update_status()
48 assert app_context
.model
.remote_branches
== []
51 helper
.run_git('remote', 'add', 'origin', '.')
52 helper
.run_git('fetch', 'origin')
53 app_context
.model
.update_status()
54 assert app_context
.model
.remote_branches
== ['origin/main']
57 def test_modified(app_context
):
58 """Test the 'modified' attribute."""
59 helper
.write_file('A', 'change')
60 app_context
.model
.update_status()
61 assert app_context
.model
.modified
== ['A']
64 def test_unstaged(app_context
):
65 """Test the 'unstaged' attribute."""
66 helper
.write_file('A', 'change')
67 helper
.write_file('C', 'C')
68 app_context
.model
.update_status()
69 assert app_context
.model
.unstaged
== ['A', 'C']
72 def test_untracked(app_context
):
73 """Test the 'untracked' attribute."""
74 helper
.write_file('C', 'C')
75 app_context
.model
.update_status()
76 assert app_context
.model
.untracked
== ['C']
79 def test_stageable(app_context
):
80 """Test the 'stageable' attribute."""
81 assert not app_context
.model
.is_stageable()
84 def test_remotes(app_context
):
85 """Test the 'remote' attribute."""
86 helper
.run_git('remote', 'add', 'origin', '.')
87 app_context
.model
.update_status()
88 assert app_context
.model
.remotes
== ['origin']
91 def test_currentbranch(app_context
):
92 """Test the 'currentbranch' attribute."""
93 helper
.run_git('checkout', '-b', 'test')
94 app_context
.model
.update_status()
95 assert app_context
.model
.currentbranch
== 'test'
98 def test_tags(app_context
):
99 """Test the 'tags' attribute."""
100 helper
.commit_files()
101 helper
.run_git('tag', 'test')
102 app_context
.model
.update_status()
103 assert app_context
.model
.tags
== ['test']
106 def test_remote_args_fetch(mock_context
):
108 (args
, kwargs
) = main
.remote_args(
111 local_branch
=LOCAL_BRANCH
,
112 remote_branch
=REMOTE_BRANCH
,
115 assert args
== [REMOTE
, 'remote:local']
116 assert kwargs
['verbose']
117 assert 'tags' not in kwargs
118 assert 'rebase' not in kwargs
121 def test_remote_args_fetch_tags(mock_context
):
123 (args
, kwargs
) = main
.remote_args(
127 local_branch
=LOCAL_BRANCH
,
128 remote_branch
=REMOTE_BRANCH
,
131 assert args
== [REMOTE
, 'remote:local']
132 assert kwargs
['verbose']
133 assert kwargs
['tags']
134 assert 'rebase' not in kwargs
137 def test_remote_args_pull(mock_context
):
139 (args
, kwargs
) = main
.remote_args(
144 remote_branch
=REMOTE_BRANCH
,
147 assert args
== [REMOTE
, 'remote']
148 assert kwargs
['verbose']
149 assert 'rebase' not in kwargs
150 assert 'tags' not in kwargs
153 def test_remote_args_pull_rebase(mock_context
):
155 (args
, kwargs
) = main
.remote_args(
161 remote_branch
=REMOTE_BRANCH
,
164 assert args
== [REMOTE
, 'remote']
165 assert kwargs
['verbose']
166 assert kwargs
['rebase']
167 assert 'tags' not in kwargs
170 def test_remote_args_push(mock_context
):
171 # Push, swap local and remote
172 (args
, kwargs
) = main
.remote_args(
175 local_branch
=REMOTE_BRANCH
,
176 remote_branch
=LOCAL_BRANCH
,
179 assert args
== [REMOTE
, 'local:remote']
180 assert kwargs
['verbose']
181 assert 'tags' not in kwargs
182 assert 'rebase' not in kwargs
185 def test_remote_args_push_tags(mock_context
):
186 # Push, swap local and remote
187 (args
, kwargs
) = main
.remote_args(
191 local_branch
=REMOTE_BRANCH
,
192 remote_branch
=LOCAL_BRANCH
,
195 assert args
== [REMOTE
, 'local:remote']
196 assert kwargs
['verbose']
197 assert kwargs
['tags']
198 assert 'rebase' not in kwargs
201 def test_remote_args_push_same_remote_and_local(mock_context
):
202 (args
, kwargs
) = main
.remote_args(
206 local_branch
=LOCAL_BRANCH
,
207 remote_branch
=LOCAL_BRANCH
,
211 assert args
== [REMOTE
, 'local']
212 assert kwargs
['verbose']
213 assert kwargs
['tags']
214 assert 'rebase' not in kwargs
217 def test_remote_args_push_set_upstream(mock_context
):
218 (args
, kwargs
) = main
.remote_args(
222 local_branch
=LOCAL_BRANCH
,
223 remote_branch
=LOCAL_BRANCH
,
228 assert args
== [REMOTE
, 'local']
229 assert kwargs
['verbose']
230 assert kwargs
['tags']
231 assert kwargs
['set_upstream']
232 assert 'rebase' not in kwargs
235 def test_remote_args_rebase_only(mock_context
):
236 (_
, kwargs
) = main
.remote_args(
237 mock_context
, REMOTE
, pull
=True, rebase
=True, ff_only
=True
239 assert kwargs
['rebase']
240 assert 'ff_only' not in kwargs
243 def test_run_remote_action(mock_context
):
244 def passthrough(*args
, **kwargs
):
245 return (args
, kwargs
)
247 (args
, kwargs
) = main
.run_remote_action(
251 local_branch
=LOCAL_BRANCH
,
252 remote_branch
=REMOTE_BRANCH
,
255 assert args
== (REMOTE
, 'remote:local')
256 assert kwargs
['verbose']
257 assert 'tags' not in kwargs
258 assert 'rebase' not in kwargs