about: apply flake8 suggestions
[git-cola.git] / test / main_model_test.py
blobb6e7796f01aec65e1344cc85d5b275c6b7cb1052
1 from __future__ import absolute_import, division, unicode_literals
3 import os
4 import unittest
6 from cola import core
7 from cola.models import main
9 from test import helper
12 class MainModelTestCase(helper.GitRepositoryTestCase):
13 """Tests the MainModel class."""
15 def setUp(self):
16 helper.GitRepositoryTestCase.setUp(self)
17 self.model = main.MainModel(cwd=core.getcwd())
19 def test_project(self):
20 """Test the 'project' attribute."""
21 project = os.path.basename(self.test_path())
22 self.assertEqual(self.model.project, project)
24 def test_local_branches(self):
25 """Test the 'local_branches' attribute."""
26 self.model.update_status()
27 self.assertEqual(self.model.local_branches, ['master'])
29 def test_remote_branches(self):
30 """Test the 'remote_branches' attribute."""
31 self.model.update_status()
32 self.assertEqual(self.model.remote_branches, [])
34 self.git('remote', 'add', 'origin', '.')
35 self.git('fetch', 'origin')
36 self.model.update_status()
37 self.assertEqual(self.model.remote_branches, ['origin/master'])
39 def test_modified(self):
40 """Test the 'modified' attribute."""
41 self.write_file('A', 'change')
42 self.model.update_status()
43 self.assertEqual(self.model.modified, ['A'])
45 def test_unstaged(self):
46 """Test the 'unstaged' attribute."""
47 self.write_file('A', 'change')
48 self.write_file('C', 'C')
49 self.model.update_status()
50 self.assertEqual(self.model.unstaged, ['A', 'C'])
52 def test_untracked(self):
53 """Test the 'untracked' attribute."""
54 self.write_file('C', 'C')
55 self.model.update_status()
56 self.assertEqual(self.model.untracked, ['C'])
58 def test_remotes(self):
59 """Test the 'remote' attribute."""
60 self.git('remote', 'add', 'origin', '.')
61 self.model.update_status()
62 self.assertEqual(self.model.remotes, ['origin'])
64 def test_currentbranch(self):
65 """Test the 'currentbranch' attribute."""
66 self.git('checkout', '-b', 'test')
67 self.model.update_status()
68 self.assertEqual(self.model.currentbranch, 'test')
70 def test_tags(self):
71 """Test the 'tags' attribute."""
72 self.git('tag', 'test')
73 self.model.update_status()
74 self.assertEqual(self.model.tags, ['test'])
77 class RemoteArgsTestCase(unittest.TestCase):
79 def setUp(self):
80 self.remote = 'server'
81 self.local_branch = 'local'
82 self.remote_branch = 'remote'
84 def test_remote_args_fetch(self):
85 # Fetch
86 (args, kwargs) = \
87 main.remote_args(self.remote,
88 local_branch=self.local_branch,
89 remote_branch=self.remote_branch)
91 self.assertEqual(args, [self.remote, 'remote:local'])
92 self.assertTrue(kwargs['verbose'])
93 self.assertFalse(kwargs['tags'])
94 self.assertFalse(kwargs['rebase'])
96 def test_remote_args_fetch_tags(self):
97 # Fetch tags
98 (args, kwargs) = \
99 main.remote_args(self.remote,
100 tags=True,
101 local_branch=self.local_branch,
102 remote_branch=self.remote_branch)
104 self.assertEqual(args, [self.remote, 'remote:local'])
105 self.assertTrue(kwargs['verbose'])
106 self.assertTrue(kwargs['tags'])
107 self.assertFalse(kwargs['rebase'])
109 def test_remote_args_pull(self):
110 # Pull
111 (args, kwargs) = \
112 main.remote_args(self.remote,
113 pull=True,
114 local_branch='',
115 remote_branch=self.remote_branch)
117 self.assertEqual(args, [self.remote, 'remote'])
118 self.assertTrue(kwargs['verbose'])
119 self.assertFalse(kwargs['rebase'])
120 self.assertFalse(kwargs['tags'])
122 def test_remote_args_pull_rebase(self):
123 # Rebasing pull
124 (args, kwargs) = \
125 main.remote_args(self.remote,
126 pull=True,
127 rebase=True,
128 local_branch='',
129 remote_branch=self.remote_branch)
131 self.assertEqual(args, [self.remote, 'remote'])
132 self.assertTrue(kwargs['verbose'])
133 self.assertTrue(kwargs['rebase'])
134 self.assertFalse(kwargs['tags'])
136 def test_remote_args_push(self):
137 # Push, swap local and remote
138 (args, kwargs) = \
139 main.remote_args(self.remote,
140 local_branch=self.remote_branch,
141 remote_branch=self.local_branch)
143 self.assertEqual(args, [self.remote, 'local:remote'])
144 self.assertTrue(kwargs['verbose'])
145 self.assertFalse(kwargs['tags'])
146 self.assertFalse(kwargs['rebase'])
148 def test_remote_args_push_tags(self):
149 # Push, swap local and remote
150 (args, kwargs) = \
151 main.remote_args(self.remote,
152 tags=True,
153 local_branch=self.remote_branch,
154 remote_branch=self.local_branch)
156 self.assertEqual(args, [self.remote, 'local:remote'])
157 self.assertTrue(kwargs['verbose'])
158 self.assertTrue(kwargs['tags'])
159 self.assertFalse(kwargs['rebase'])
161 def test_run_remote_action(self):
163 def passthrough(*args, **kwargs):
164 return (args, kwargs)
166 (args, kwargs) = \
167 main.run_remote_action(passthrough,
168 self.remote,
169 local_branch=self.local_branch,
170 remote_branch=self.remote_branch)
172 self.assertEqual(args, (self.remote, 'remote:local'))
173 self.assertTrue(kwargs['verbose'])
174 self.assertFalse(kwargs['tags'])
175 self.assertFalse(kwargs['rebase'])
178 if __name__ == '__main__':
179 unittest.main()