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