Show More
@@ -6,7 +6,7 b' Tests so called "in memory changesets" c' | |||||
6 | import time |
|
6 | import time | |
7 | import datetime |
|
7 | import datetime | |
8 |
|
8 | |||
9 | from kallithea.lib.vcs.utils.compat import unittest |
|
9 | import pytest | |
10 |
|
10 | |||
11 | from kallithea.lib import vcs |
|
11 | from kallithea.lib import vcs | |
12 | from kallithea.lib.vcs.exceptions import EmptyRepositoryError |
|
12 | from kallithea.lib.vcs.exceptions import EmptyRepositoryError | |
@@ -38,7 +38,7 b' class InMemoryChangesetTestMixin(object)' | |||||
38 | def get_backend(self): |
|
38 | def get_backend(self): | |
39 | return vcs.get_backend(self.backend_alias) |
|
39 | return vcs.get_backend(self.backend_alias) | |
40 |
|
40 | |||
41 |
def set |
|
41 | def setup_method(self): | |
42 | Backend = self.get_backend() |
|
42 | Backend = self.get_backend() | |
43 | self.repo_path = get_new_dir(str(time.time())) |
|
43 | self.repo_path = get_new_dir(str(time.time())) | |
44 | self.repo = Backend(self.repo_path, create=True) |
|
44 | self.repo = Backend(self.repo_path, create=True) | |
@@ -62,14 +62,17 b' class InMemoryChangesetTestMixin(object)' | |||||
62 | changeset = self.imc.commit(message=message, author=author) |
|
62 | changeset = self.imc.commit(message=message, author=author) | |
63 |
|
63 | |||
64 | newtip = self.repo.get_changeset() |
|
64 | newtip = self.repo.get_changeset() | |
65 |
|
|
65 | assert changeset == newtip | |
66 |
|
|
66 | assert rev_count + 1 == len(self.repo.revisions) | |
67 |
|
|
67 | assert newtip.message == message | |
68 |
|
|
68 | assert newtip.author == author | |
69 | self.assertTrue(not any((self.imc.added, self.imc.changed, |
|
69 | assert not any(( | |
70 |
self.imc. |
|
70 | self.imc.added, | |
|
71 | self.imc.changed, | |||
|
72 | self.imc.removed | |||
|
73 | )) | |||
71 | for node in to_add: |
|
74 | for node in to_add: | |
72 |
|
|
75 | assert newtip.get_node(node.path).content == node.content | |
73 |
|
76 | |||
74 | def test_add_in_bulk(self): |
|
77 | def test_add_in_bulk(self): | |
75 | rev_count = len(self.repo.revisions) |
|
78 | rev_count = len(self.repo.revisions) | |
@@ -81,23 +84,26 b' class InMemoryChangesetTestMixin(object)' | |||||
81 | changeset = self.imc.commit(message=message, author=author) |
|
84 | changeset = self.imc.commit(message=message, author=author) | |
82 |
|
85 | |||
83 | newtip = self.repo.get_changeset() |
|
86 | newtip = self.repo.get_changeset() | |
84 |
|
|
87 | assert changeset == newtip | |
85 |
|
|
88 | assert rev_count + 1 == len(self.repo.revisions) | |
86 |
|
|
89 | assert newtip.message == message | |
87 |
|
|
90 | assert newtip.author == author | |
88 | self.assertTrue(not any((self.imc.added, self.imc.changed, |
|
91 | assert not any(( | |
89 |
self.imc. |
|
92 | self.imc.added, | |
|
93 | self.imc.changed, | |||
|
94 | self.imc.removed | |||
|
95 | )) | |||
90 | for node in to_add: |
|
96 | for node in to_add: | |
91 |
|
|
97 | assert newtip.get_node(node.path).content == node.content | |
92 |
|
98 | |||
93 | def test_add_actually_adds_all_nodes_at_second_commit_too(self): |
|
99 | def test_add_actually_adds_all_nodes_at_second_commit_too(self): | |
94 | self.imc.add(FileNode('foo/bar/image.png', content='\0')) |
|
100 | self.imc.add(FileNode('foo/bar/image.png', content='\0')) | |
95 | self.imc.add(FileNode('foo/README.txt', content='readme!')) |
|
101 | self.imc.add(FileNode('foo/README.txt', content='readme!')) | |
96 | changeset = self.imc.commit(u'Initial', u'joe.doe@example.com') |
|
102 | changeset = self.imc.commit(u'Initial', u'joe.doe@example.com') | |
97 |
|
|
103 | assert isinstance(changeset.get_node('foo'), DirNode) | |
98 |
|
|
104 | assert isinstance(changeset.get_node('foo/bar'), DirNode) | |
99 |
|
|
105 | assert changeset.get_node('foo/bar/image.png').content == '\0' | |
100 |
|
|
106 | assert changeset.get_node('foo/README.txt').content == 'readme!' | |
101 |
|
107 | |||
102 | # commit some more files again |
|
108 | # commit some more files again | |
103 | to_add = [ |
|
109 | to_add = [ | |
@@ -109,11 +115,11 b' class InMemoryChangesetTestMixin(object)' | |||||
109 | ] |
|
115 | ] | |
110 | self.imc.add(*to_add) |
|
116 | self.imc.add(*to_add) | |
111 | changeset = self.imc.commit(u'Another', u'joe.doe@example.com') |
|
117 | changeset = self.imc.commit(u'Another', u'joe.doe@example.com') | |
112 |
|
|
118 | changeset.get_node('foo/bar/foobaz/bar').content == 'foo' | |
113 |
|
|
119 | changeset.get_node('foo/bar/another/bar').content == 'foo' | |
114 |
|
|
120 | changeset.get_node('foo/baz.txt').content == 'foo' | |
115 |
|
|
121 | changeset.get_node('foobar/foobaz/file').content == 'foo' | |
116 |
|
|
122 | changeset.get_node('foobar/barbaz').content == 'foo' | |
117 |
|
123 | |||
118 | def test_add_non_ascii_files(self): |
|
124 | def test_add_non_ascii_files(self): | |
119 | rev_count = len(self.repo.revisions) |
|
125 | rev_count = len(self.repo.revisions) | |
@@ -128,28 +134,32 b' class InMemoryChangesetTestMixin(object)' | |||||
128 | changeset = self.imc.commit(message=message, author=author) |
|
134 | changeset = self.imc.commit(message=message, author=author) | |
129 |
|
135 | |||
130 | newtip = self.repo.get_changeset() |
|
136 | newtip = self.repo.get_changeset() | |
131 |
|
|
137 | assert changeset == newtip | |
132 |
|
|
138 | assert rev_count + 1 == len(self.repo.revisions) | |
133 |
|
|
139 | assert newtip.message == message | |
134 |
|
|
140 | assert newtip.author == author | |
135 | self.assertTrue(not any((self.imc.added, self.imc.changed, |
|
141 | assert not any(( | |
136 |
self.imc. |
|
142 | self.imc.added, | |
|
143 | self.imc.changed, | |||
|
144 | self.imc.removed | |||
|
145 | )) | |||
137 | for node in to_add: |
|
146 | for node in to_add: | |
138 |
|
|
147 | assert newtip.get_node(node.path).content == node.content | |
139 |
|
148 | |||
140 | def test_add_raise_already_added(self): |
|
149 | def test_add_raise_already_added(self): | |
141 | node = FileNode('foobar', content='baz') |
|
150 | node = FileNode('foobar', content='baz') | |
142 | self.imc.add(node) |
|
151 | self.imc.add(node) | |
143 |
|
|
152 | with pytest.raises(NodeAlreadyAddedError): | |
|
153 | self.imc.add(node) | |||
144 |
|
154 | |||
145 | def test_check_integrity_raise_already_exist(self): |
|
155 | def test_check_integrity_raise_already_exist(self): | |
146 | node = FileNode('foobar', content='baz') |
|
156 | node = FileNode('foobar', content='baz') | |
147 | self.imc.add(node) |
|
157 | self.imc.add(node) | |
148 | self.imc.commit(message=u'Added foobar', author=unicode(self)) |
|
158 | self.imc.commit(message=u'Added foobar', author=unicode(self)) | |
149 | self.imc.add(node) |
|
159 | self.imc.add(node) | |
150 |
|
|
160 | with pytest.raises(NodeAlreadyExistsError): | |
151 | message='new message', |
|
161 | self.imc.commit(message='new message', | |
152 | author=str(self)) |
|
162 | author=str(self)) | |
153 |
|
163 | |||
154 | def test_change(self): |
|
164 | def test_change(self): | |
155 | self.imc.add(FileNode('foo/bar/baz', content='foo')) |
|
165 | self.imc.add(FileNode('foo/bar/baz', content='foo')) | |
@@ -162,10 +172,9 b' class InMemoryChangesetTestMixin(object)' | |||||
162 | self.imc.commit(u'Changed %s' % node.path, u'joe.doe@example.com') |
|
172 | self.imc.commit(u'Changed %s' % node.path, u'joe.doe@example.com') | |
163 |
|
173 | |||
164 | newtip = self.repo.get_changeset() |
|
174 | newtip = self.repo.get_changeset() | |
165 |
|
|
175 | assert tip != newtip | |
166 |
|
|
176 | assert tip.id != newtip.id | |
167 |
|
|
177 | assert newtip.get_node('foo/bar/baz').content == 'My **changed** content' | |
168 | 'My **changed** content') |
|
|||
169 |
|
178 | |||
170 | def test_change_non_ascii(self): |
|
179 | def test_change_non_ascii(self): | |
171 | to_add = [ |
|
180 | to_add = [ | |
@@ -189,17 +198,16 b' class InMemoryChangesetTestMixin(object)' | |||||
189 | u'joe.doe@example.com') |
|
198 | u'joe.doe@example.com') | |
190 |
|
199 | |||
191 | newtip = self.repo.get_changeset() |
|
200 | newtip = self.repo.get_changeset() | |
192 |
|
|
201 | assert tip != newtip | |
193 |
|
|
202 | assert tip.id != newtip.id | |
194 |
|
203 | |||
195 |
|
|
204 | assert newtip.get_node('ΕΌΓ³Εwik/zwierzΔ tko').content == 'My **changed** content' | |
196 | 'My **changed** content') |
|
205 | assert newtip.get_node('ΕΌΓ³Εwik/zwierzΔ tko_uni').content == 'My **changed** content' | |
197 | self.assertEqual(newtip.get_node('ΕΌΓ³Εwik/zwierzΔ tko_uni').content, |
|
|||
198 | 'My **changed** content') |
|
|||
199 |
|
206 | |||
200 | def test_change_raise_empty_repository(self): |
|
207 | def test_change_raise_empty_repository(self): | |
201 | node = FileNode('foobar') |
|
208 | node = FileNode('foobar') | |
202 |
|
|
209 | with pytest.raises(EmptyRepositoryError): | |
|
210 | self.imc.change(node) | |||
203 |
|
211 | |||
204 | def test_check_integrity_change_raise_node_does_not_exist(self): |
|
212 | def test_check_integrity_change_raise_node_does_not_exist(self): | |
205 | node = FileNode('foobar', content='baz') |
|
213 | node = FileNode('foobar', content='baz') | |
@@ -207,9 +215,8 b' class InMemoryChangesetTestMixin(object)' | |||||
207 | self.imc.commit(message=u'Added foobar', author=unicode(self)) |
|
215 | self.imc.commit(message=u'Added foobar', author=unicode(self)) | |
208 | node = FileNode('not-foobar', content='') |
|
216 | node = FileNode('not-foobar', content='') | |
209 | self.imc.change(node) |
|
217 | self.imc.change(node) | |
210 |
|
|
218 | with pytest.raises(NodeDoesNotExistError): | |
211 | message='Changed not existing node', |
|
219 | self.imc.commit(message='Changed not existing node', author=str(self)) | |
212 | author=str(self)) |
|
|||
213 |
|
220 | |||
214 | def test_change_raise_node_already_changed(self): |
|
221 | def test_change_raise_node_already_changed(self): | |
215 | node = FileNode('foobar', content='baz') |
|
222 | node = FileNode('foobar', content='baz') | |
@@ -217,37 +224,42 b' class InMemoryChangesetTestMixin(object)' | |||||
217 | self.imc.commit(message=u'Added foobar', author=unicode(self)) |
|
224 | self.imc.commit(message=u'Added foobar', author=unicode(self)) | |
218 | node = FileNode('foobar', content='more baz') |
|
225 | node = FileNode('foobar', content='more baz') | |
219 | self.imc.change(node) |
|
226 | self.imc.change(node) | |
220 |
|
|
227 | with pytest.raises(NodeAlreadyChangedError): | |
|
228 | self.imc.change(node) | |||
221 |
|
229 | |||
222 | def test_check_integrity_change_raise_node_not_changed(self): |
|
230 | def test_check_integrity_change_raise_node_not_changed(self): | |
223 | self.test_add() # Performs first commit |
|
231 | self.test_add() # Performs first commit | |
224 |
|
232 | |||
225 | node = FileNode(self.nodes[0].path, content=self.nodes[0].content) |
|
233 | node = FileNode(self.nodes[0].path, content=self.nodes[0].content) | |
226 | self.imc.change(node) |
|
234 | self.imc.change(node) | |
227 |
|
|
235 | with pytest.raises(NodeNotChangedError): | |
228 | message=u'Trying to mark node as changed without touching it', |
|
236 | self.imc.commit( | |
229 | author=unicode(self)) |
|
237 | message=u'Trying to mark node as changed without touching it', | |
|
238 | author=unicode(self) | |||
|
239 | ) | |||
230 |
|
240 | |||
231 | def test_change_raise_node_already_removed(self): |
|
241 | def test_change_raise_node_already_removed(self): | |
232 | node = FileNode('foobar', content='baz') |
|
242 | node = FileNode('foobar', content='baz') | |
233 | self.imc.add(node) |
|
243 | self.imc.add(node) | |
234 | self.imc.commit(message=u'Added foobar', author=unicode(self)) |
|
244 | self.imc.commit(message=u'Added foobar', author=unicode(self)) | |
235 | self.imc.remove(FileNode('foobar')) |
|
245 | self.imc.remove(FileNode('foobar')) | |
236 |
|
|
246 | with pytest.raises(NodeAlreadyRemovedError): | |
|
247 | self.imc.change(node) | |||
237 |
|
248 | |||
238 | def test_remove(self): |
|
249 | def test_remove(self): | |
239 | self.test_add() # Performs first commit |
|
250 | self.test_add() # Performs first commit | |
240 |
|
251 | |||
241 | tip = self.repo.get_changeset() |
|
252 | tip = self.repo.get_changeset() | |
242 | node = self.nodes[0] |
|
253 | node = self.nodes[0] | |
243 |
|
|
254 | assert node.content == tip.get_node(node.path).content | |
244 | self.imc.remove(node) |
|
255 | self.imc.remove(node) | |
245 | self.imc.commit(message=u'Removed %s' % node.path, author=unicode(self)) |
|
256 | self.imc.commit(message=u'Removed %s' % node.path, author=unicode(self)) | |
246 |
|
257 | |||
247 | newtip = self.repo.get_changeset() |
|
258 | newtip = self.repo.get_changeset() | |
248 |
|
|
259 | assert tip != newtip | |
249 |
|
|
260 | assert tip.id != newtip.id | |
250 |
|
|
261 | with pytest.raises(NodeDoesNotExistError): | |
|
262 | newtip.get_node(node.path) | |||
251 |
|
263 | |||
252 | def test_remove_last_file_from_directory(self): |
|
264 | def test_remove_last_file_from_directory(self): | |
253 | node = FileNode('omg/qwe/foo/bar', content='foobar') |
|
265 | node = FileNode('omg/qwe/foo/bar', content='foobar') | |
@@ -256,44 +268,54 b' class InMemoryChangesetTestMixin(object)' | |||||
256 |
|
268 | |||
257 | self.imc.remove(node) |
|
269 | self.imc.remove(node) | |
258 | tip = self.imc.commit(u'removed', u'joe doe') |
|
270 | tip = self.imc.commit(u'removed', u'joe doe') | |
259 | self.assertRaises(NodeDoesNotExistError, tip.get_node, 'omg/qwe/foo/bar') |
|
271 | with pytest.raises(NodeDoesNotExistError): | |
|
272 | tip.get_node('omg/qwe/foo/bar') | |||
260 |
|
273 | |||
261 | def test_remove_raise_node_does_not_exist(self): |
|
274 | def test_remove_raise_node_does_not_exist(self): | |
262 | self.imc.remove(self.nodes[0]) |
|
275 | self.imc.remove(self.nodes[0]) | |
263 |
|
|
276 | with pytest.raises(NodeDoesNotExistError): | |
264 | message='Trying to remove node at empty repository', |
|
277 | self.imc.commit( | |
265 | author=str(self)) |
|
278 | message='Trying to remove node at empty repository', | |
|
279 | author=str(self) | |||
|
280 | ) | |||
266 |
|
281 | |||
267 | def test_check_integrity_remove_raise_node_does_not_exist(self): |
|
282 | def test_check_integrity_remove_raise_node_does_not_exist(self): | |
268 | self.test_add() # Performs first commit |
|
283 | self.test_add() # Performs first commit | |
269 |
|
284 | |||
270 | node = FileNode('no-such-file') |
|
285 | node = FileNode('no-such-file') | |
271 | self.imc.remove(node) |
|
286 | self.imc.remove(node) | |
272 |
|
|
287 | with pytest.raises(NodeDoesNotExistError): | |
273 | message=u'Trying to remove not existing node', |
|
288 | self.imc.commit( | |
274 | author=unicode(self)) |
|
289 | message=u'Trying to remove not existing node', | |
|
290 | author=unicode(self) | |||
|
291 | ) | |||
275 |
|
292 | |||
276 | def test_remove_raise_node_already_removed(self): |
|
293 | def test_remove_raise_node_already_removed(self): | |
277 | self.test_add() # Performs first commit |
|
294 | self.test_add() # Performs first commit | |
278 |
|
295 | |||
279 | node = FileNode(self.nodes[0].path) |
|
296 | node = FileNode(self.nodes[0].path) | |
280 | self.imc.remove(node) |
|
297 | self.imc.remove(node) | |
281 |
|
|
298 | with pytest.raises(NodeAlreadyRemovedError): | |
|
299 | self.imc.remove(node) | |||
282 |
|
300 | |||
283 | def test_remove_raise_node_already_changed(self): |
|
301 | def test_remove_raise_node_already_changed(self): | |
284 | self.test_add() # Performs first commit |
|
302 | self.test_add() # Performs first commit | |
285 |
|
303 | |||
286 | node = FileNode(self.nodes[0].path, content='Bending time') |
|
304 | node = FileNode(self.nodes[0].path, content='Bending time') | |
287 | self.imc.change(node) |
|
305 | self.imc.change(node) | |
288 |
|
|
306 | with pytest.raises(NodeAlreadyChangedError): | |
|
307 | self.imc.remove(node) | |||
289 |
|
308 | |||
290 | def test_reset(self): |
|
309 | def test_reset(self): | |
291 | self.imc.add(FileNode('foo', content='bar')) |
|
310 | self.imc.add(FileNode('foo', content='bar')) | |
292 | #self.imc.change(FileNode('baz', content='new')) |
|
311 | #self.imc.change(FileNode('baz', content='new')) | |
293 | #self.imc.remove(FileNode('qwe')) |
|
312 | #self.imc.remove(FileNode('qwe')) | |
294 | self.imc.reset() |
|
313 | self.imc.reset() | |
295 | self.assertTrue(not any((self.imc.added, self.imc.changed, |
|
314 | assert not any(( | |
296 |
self.imc. |
|
315 | self.imc.added, | |
|
316 | self.imc.changed, | |||
|
317 | self.imc.removed | |||
|
318 | )) | |||
297 |
|
319 | |||
298 | def test_multiple_commits(self): |
|
320 | def test_multiple_commits(self): | |
299 | N = 3 # number of commits to perform |
|
321 | N = 3 # number of commits to perform | |
@@ -304,16 +326,16 b' class InMemoryChangesetTestMixin(object)' | |||||
304 | node = FileNode(fname, content=content) |
|
326 | node = FileNode(fname, content=content) | |
305 | self.imc.add(node) |
|
327 | self.imc.add(node) | |
306 | commit = self.imc.commit(u"Commit no. %s" % (x + 1), author=u'vcs') |
|
328 | commit = self.imc.commit(u"Commit no. %s" % (x + 1), author=u'vcs') | |
307 |
|
|
329 | assert last != commit | |
308 | last = commit |
|
330 | last = commit | |
309 |
|
331 | |||
310 | # Check commit number for same repo |
|
332 | # Check commit number for same repo | |
311 |
|
|
333 | assert len(self.repo.revisions) == N | |
312 |
|
334 | |||
313 | # Check commit number for recreated repo |
|
335 | # Check commit number for recreated repo | |
314 | backend = self.get_backend() |
|
336 | backend = self.get_backend() | |
315 | repo = backend(self.repo_path) |
|
337 | repo = backend(self.repo_path) | |
316 |
|
|
338 | assert len(repo.revisions) == N | |
317 |
|
339 | |||
318 | def test_date_attr(self): |
|
340 | def test_date_attr(self): | |
319 | node = FileNode('foobar.txt', content='Foobared!') |
|
341 | node = FileNode('foobar.txt', content='Foobared!') | |
@@ -322,10 +344,10 b' class InMemoryChangesetTestMixin(object)' | |||||
322 | commit = self.imc.commit(u"Committed at time when I was born ;-)", |
|
344 | commit = self.imc.commit(u"Committed at time when I was born ;-)", | |
323 | author=u'lb <lb@example.com>', date=date) |
|
345 | author=u'lb <lb@example.com>', date=date) | |
324 |
|
346 | |||
325 |
|
|
347 | assert commit.date == date | |
326 |
|
348 | |||
327 |
|
349 | |||
328 |
class BackendBaseTestCase( |
|
350 | class BackendBaseTestCase(object): | |
329 | """ |
|
351 | """ | |
330 | Base test class for tests which requires repository. |
|
352 | Base test class for tests which requires repository. | |
331 | """ |
|
353 | """ | |
@@ -361,7 +383,7 b' class BackendBaseTestCase(unittest.TestC' | |||||
361 | repo_path = get_new_dir(key) |
|
383 | repo_path = get_new_dir(key) | |
362 | return repo_path |
|
384 | return repo_path | |
363 |
|
385 | |||
364 |
def set |
|
386 | def setup_method(self): | |
365 | Backend = self.get_backend() |
|
387 | Backend = self.get_backend() | |
366 | self.backend_class = Backend |
|
388 | self.backend_class = Backend | |
367 | self.repo_path = self.get_new_repo_path() |
|
389 | self.repo_path = self.get_new_repo_path() | |
@@ -387,6 +409,5 b' for alias in SCM_TESTS:' | |||||
387 | attrs = { |
|
409 | attrs = { | |
388 | 'backend_alias': alias, |
|
410 | 'backend_alias': alias, | |
389 | } |
|
411 | } | |
390 |
cls_name = ''.join(('%s in memory changeset |
|
412 | cls_name = ''.join(('test %s in memory changeset' % alias).title().split()) | |
391 |
|
|
413 | globals()[cls_name] = type(cls_name, (InMemoryChangesetTestMixin,), attrs) | |
392 | globals()[cls_name] = type(cls_name, bases, attrs) |
|
@@ -1,7 +1,7 b'' | |||||
1 | import stat |
|
1 | import stat | |
2 | import mimetypes |
|
2 | import mimetypes | |
3 |
|
3 | |||
4 | from kallithea.lib.vcs.utils.compat import unittest |
|
4 | import pytest | |
5 |
|
5 | |||
6 | from kallithea.lib.vcs.nodes import DirNode |
|
6 | from kallithea.lib.vcs.nodes import DirNode | |
7 | from kallithea.lib.vcs.nodes import FileNode |
|
7 | from kallithea.lib.vcs.nodes import FileNode | |
@@ -10,7 +10,7 b' from kallithea.lib.vcs.nodes import Node' | |||||
10 | from kallithea.lib.vcs.nodes import NodeKind |
|
10 | from kallithea.lib.vcs.nodes import NodeKind | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | class NodeBasicTest(unittest.TestCase): |
|
13 | class TestNodeBasic(object): | |
14 |
|
14 | |||
15 | def test_init(self): |
|
15 | def test_init(self): | |
16 | """ |
|
16 | """ | |
@@ -21,37 +21,41 b' class NodeBasicTest(unittest.TestCase):' | |||||
21 | '/foo/bar' |
|
21 | '/foo/bar' | |
22 | ) |
|
22 | ) | |
23 | for path in wrong_paths: |
|
23 | for path in wrong_paths: | |
24 | self.assertRaises(NodeError, Node, path, NodeKind.FILE) |
|
24 | with pytest.raises(NodeError): | |
|
25 | Node(path, NodeKind.FILE) | |||
25 |
|
26 | |||
26 | wrong_paths = ( |
|
27 | wrong_paths = ( | |
27 | '/foo/', |
|
28 | '/foo/', | |
28 | '/foo/bar/' |
|
29 | '/foo/bar/' | |
29 | ) |
|
30 | ) | |
30 | for path in wrong_paths: |
|
31 | for path in wrong_paths: | |
31 | self.assertRaises(NodeError, Node, path, NodeKind.DIR) |
|
32 | with pytest.raises(NodeError): | |
|
33 | Node(path, NodeKind.DIR) | |||
32 |
|
34 | |||
33 | def test_name(self): |
|
35 | def test_name(self): | |
34 | node = Node('', NodeKind.DIR) |
|
36 | node = Node('', NodeKind.DIR) | |
35 |
|
|
37 | assert node.name == '' | |
36 |
|
38 | |||
37 | node = Node('path', NodeKind.FILE) |
|
39 | node = Node('path', NodeKind.FILE) | |
38 |
|
|
40 | assert node.name == 'path' | |
39 |
|
41 | |||
40 | node = Node('path/', NodeKind.DIR) |
|
42 | node = Node('path/', NodeKind.DIR) | |
41 |
|
|
43 | assert node.name == 'path' | |
42 |
|
44 | |||
43 | node = Node('some/path', NodeKind.FILE) |
|
45 | node = Node('some/path', NodeKind.FILE) | |
44 |
|
|
46 | assert node.name == 'path' | |
45 |
|
47 | |||
46 | node = Node('some/path/', NodeKind.DIR) |
|
48 | node = Node('some/path/', NodeKind.DIR) | |
47 |
|
|
49 | assert node.name == 'path' | |
48 |
|
50 | |||
49 | def test_root_node(self): |
|
51 | def test_root_node(self): | |
50 | self.assertRaises(NodeError, Node, '', NodeKind.FILE) |
|
52 | with pytest.raises(NodeError): | |
|
53 | Node('', NodeKind.FILE) | |||
51 |
|
54 | |||
52 | def test_kind_setter(self): |
|
55 | def test_kind_setter(self): | |
53 | node = Node('', NodeKind.DIR) |
|
56 | node = Node('', NodeKind.DIR) | |
54 | self.assertRaises(NodeError, setattr, node, 'kind', NodeKind.FILE) |
|
57 | with pytest.raises(NodeError): | |
|
58 | setattr(node, 'kind', NodeKind.FILE) | |||
55 |
|
59 | |||
56 | def _test_parent_path(self, node_path, expected_parent_path): |
|
60 | def _test_parent_path(self, node_path, expected_parent_path): | |
57 | """ |
|
61 | """ | |
@@ -59,11 +63,10 b' class NodeBasicTest(unittest.TestCase):' | |||||
59 | """ |
|
63 | """ | |
60 | node = Node(node_path, NodeKind.DIR) |
|
64 | node = Node(node_path, NodeKind.DIR) | |
61 | parent_path = node.get_parent_path() |
|
65 | parent_path = node.get_parent_path() | |
62 |
|
|
66 | assert parent_path.endswith('/') or node.is_root() and parent_path == '' | |
63 | node.is_root() and parent_path == '') |
|
67 | assert parent_path == expected_parent_path, \ | |
64 | self.assertEqual(parent_path, expected_parent_path, |
|
68 | "Node's path is %r and parent path is %r but should be %r" \ | |
65 | "Node's path is %r and parent path is %r but should be %r" |
|
69 | % (node.path, parent_path, expected_parent_path) | |
66 | % (node.path, parent_path, expected_parent_path)) |
|
|||
67 |
|
70 | |||
68 | def test_parent_path(self): |
|
71 | def test_parent_path(self): | |
69 | test_paths = ( |
|
72 | test_paths = ( | |
@@ -80,7 +83,8 b' class NodeBasicTest(unittest.TestCase):' | |||||
80 | if not path.endswith('/'): |
|
83 | if not path.endswith('/'): | |
81 | pytest.fail("Trailing slash tests needs paths to end with slash") |
|
84 | pytest.fail("Trailing slash tests needs paths to end with slash") | |
82 | for kind in NodeKind.FILE, NodeKind.DIR: |
|
85 | for kind in NodeKind.FILE, NodeKind.DIR: | |
83 | self.assertRaises(NodeError, Node, path=path, kind=kind) |
|
86 | with pytest.raises(NodeError): | |
|
87 | Node(path=path, kind=kind) | |||
84 |
|
88 | |||
85 | def test_trailing_slash(self): |
|
89 | def test_trailing_slash(self): | |
86 | for path in ('/', 'foo/', 'foo/bar/', 'foo/bar/biz/'): |
|
90 | for path in ('/', 'foo/', 'foo/bar/', 'foo/bar/biz/'): | |
@@ -89,20 +93,22 b' class NodeBasicTest(unittest.TestCase):' | |||||
89 |
|
93 | |||
90 | def test_is_file(self): |
|
94 | def test_is_file(self): | |
91 | node = Node('any', NodeKind.FILE) |
|
95 | node = Node('any', NodeKind.FILE) | |
92 |
|
|
96 | assert node.is_file() | |
93 |
|
97 | |||
94 | node = FileNode('any') |
|
98 | node = FileNode('any') | |
95 |
|
|
99 | assert node.is_file() | |
96 | self.assertRaises(AttributeError, getattr, node, 'nodes') |
|
100 | with pytest.raises(AttributeError): | |
|
101 | getattr(node, 'nodes') | |||
97 |
|
102 | |||
98 | def test_is_dir(self): |
|
103 | def test_is_dir(self): | |
99 | node = Node('any_dir', NodeKind.DIR) |
|
104 | node = Node('any_dir', NodeKind.DIR) | |
100 |
|
|
105 | assert node.is_dir() | |
101 |
|
106 | |||
102 | node = DirNode('any_dir') |
|
107 | node = DirNode('any_dir') | |
103 |
|
108 | |||
104 |
|
|
109 | assert node.is_dir() | |
105 | self.assertRaises(NodeError, getattr, node, 'content') |
|
110 | with pytest.raises(NodeError): | |
|
111 | getattr(node, 'content') | |||
106 |
|
112 | |||
107 | def test_dir_node_iter(self): |
|
113 | def test_dir_node_iter(self): | |
108 | nodes = [ |
|
114 | nodes = [ | |
@@ -122,32 +128,34 b' class NodeBasicTest(unittest.TestCase):' | |||||
122 | Without link to changeset nodes should raise NodeError. |
|
128 | Without link to changeset nodes should raise NodeError. | |
123 | """ |
|
129 | """ | |
124 | node = FileNode('anything') |
|
130 | node = FileNode('anything') | |
125 | self.assertRaises(NodeError, getattr, node, 'state') |
|
131 | with pytest.raises(NodeError): | |
|
132 | getattr(node, 'state') | |||
126 | node = DirNode('anything') |
|
133 | node = DirNode('anything') | |
127 | self.assertRaises(NodeError, getattr, node, 'state') |
|
134 | with pytest.raises(NodeError): | |
|
135 | getattr(node, 'state') | |||
128 |
|
136 | |||
129 | def test_file_node_stat(self): |
|
137 | def test_file_node_stat(self): | |
130 | node = FileNode('foobar', 'empty... almost') |
|
138 | node = FileNode('foobar', 'empty... almost') | |
131 | mode = node.mode # default should be 0100644 |
|
139 | mode = node.mode # default should be 0100644 | |
132 |
|
|
140 | assert mode & stat.S_IRUSR | |
133 |
|
|
141 | assert mode & stat.S_IWUSR | |
134 |
|
|
142 | assert mode & stat.S_IRGRP | |
135 |
|
|
143 | assert mode & stat.S_IROTH | |
136 |
|
|
144 | assert not mode & stat.S_IWGRP | |
137 |
|
|
145 | assert not mode & stat.S_IWOTH | |
138 |
|
|
146 | assert not mode & stat.S_IXUSR | |
139 |
|
|
147 | assert not mode & stat.S_IXGRP | |
140 |
|
|
148 | assert not mode & stat.S_IXOTH | |
141 |
|
149 | |||
142 | def test_file_node_is_executable(self): |
|
150 | def test_file_node_is_executable(self): | |
143 | node = FileNode('foobar', 'empty... almost', mode=0100755) |
|
151 | node = FileNode('foobar', 'empty... almost', mode=0100755) | |
144 |
|
|
152 | assert node.is_executable | |
145 |
|
153 | |||
146 | node = FileNode('foobar', 'empty... almost', mode=0100500) |
|
154 | node = FileNode('foobar', 'empty... almost', mode=0100500) | |
147 |
|
|
155 | assert node.is_executable | |
148 |
|
156 | |||
149 | node = FileNode('foobar', 'empty... almost', mode=0100644) |
|
157 | node = FileNode('foobar', 'empty... almost', mode=0100644) | |
150 |
|
|
158 | assert not node.is_executable | |
151 |
|
159 | |||
152 | def test_mimetype(self): |
|
160 | def test_mimetype(self): | |
153 | py_node = FileNode('test.py') |
|
161 | py_node = FileNode('test.py') | |
@@ -159,22 +167,22 b' class NodeBasicTest(unittest.TestCase):' | |||||
159 | my_node3 = FileNode('myfile3') |
|
167 | my_node3 = FileNode('myfile3') | |
160 | my_node3._content = '\0foobar' |
|
168 | my_node3._content = '\0foobar' | |
161 |
|
169 | |||
162 |
|
|
170 | assert py_node.mimetype == mimetypes.guess_type(py_node.name)[0] | |
163 |
|
|
171 | assert py_node.get_mimetype() == mimetypes.guess_type(py_node.name) | |
164 |
|
172 | |||
165 |
|
|
173 | assert tar_node.mimetype == mimetypes.guess_type(tar_node.name)[0] | |
166 |
|
|
174 | assert tar_node.get_mimetype() == mimetypes.guess_type(tar_node.name) | |
167 |
|
175 | |||
168 |
|
|
176 | assert my_node2.mimetype == 'text/plain' | |
169 |
|
|
177 | assert my_node2.get_mimetype() == ('text/plain', None) | |
170 |
|
178 | |||
171 |
|
|
179 | assert my_node3.mimetype == 'application/octet-stream' | |
172 |
|
|
180 | assert my_node3.get_mimetype() == ('application/octet-stream', None) | |
173 |
|
181 | |||
174 |
|
182 | |||
175 | class NodeContentTest(unittest.TestCase): |
|
183 | class TestNodeContent(object): | |
176 |
|
184 | |||
177 | def test_if_binary(self): |
|
185 | def test_if_binary(self): | |
178 | data = """\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f??a\x00\x00\x00\x04gAMA\x00\x00\xaf?7\x05\x8a?\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq?e<\x00\x00\x025IDAT8?\xa5\x93?K\x94Q\x14\x87\x9f\xf7?Q\x1bs4?\x03\x9a\xa8?B\x02\x8b$\x10[U;i\x13?6h?&h[?"\x14j?\xa2M\x7fB\x14F\x9aQ?&\x842?\x0b\x89"\x82??!?\x9c!\x9c2l??{N\x8bW\x9dY\xb4\t/\x1c?=\x9b?}????\xa9*;9!?\x83\x91?[?\\v*?D\x04\'`EpNp\xa2X\'U?pVq"Sw.\x1e?\x08\x01D?jw????\xbc??7{|\x9b?\x89$\x01??W@\x15\x9c\x05q`Lt/\x97?\x94\xa1d?\x18~?\x18?\x18W[%\xb0?\x83??\x14\x88\x8dB?\xa6H\tL\tl\x19>/\x01`\xac\xabx?\x9cl\nx\xb0\x98\x07\x95\x88D$"q[\x19?d\x00(o\n\xa0??\x7f\xb9\xa4?\x1bF\x1f\x8e\xac\xa8?j??eUU}?.?\x9f\x8cE??x\x94??\r\xbdtoJU5"0N\x10U?\x00??V\t\x02\x9f\x81?U?\x00\x9eM\xae2?r\x9b7\x83\x82\x8aP3????.?&"?\xb7ZP \x0c<?O\xa5\t}\xb8?\x99\xa6?\x87?\x1di|/\xa0??0\xbe\x1fp?d&\x1a\xad\x95\x8a\x07?\t*\x10??b:?d?.\x13C\x8a?\x12\xbe\xbf\x8e?{???\x08?\x80\xa7\x13+d\x13>J?\x80\x15T\x95\x9a\x00??S\x8c\r?\xa1\x03\x07?\x96\x9b\xa7\xab=E??\xa4\xb3?\x19q??B\x91=\x8d??k?J\x0bV"??\xf7x?\xa1\x00?\\.\x87\x87???\x02F@D\x99],??\x10#?X\xb7=\xb9\x10?Z\x1by???cI??\x1ag?\x92\xbc?T?t[\x92\x81?<_\x17~\x92\x88?H%?\x10Q\x02\x9f\n\x81qQ\x0bm?\x1bX?\xb1AK\xa6\x9e\xb9?u\xb2?1\xbe|/\x92M@\xa2!F?\xa9>"\r<DT?>\x92\x8e?>\x9a9Qv\x127?a\xac?Y?8?:??]X???9\x80\xb7?u?\x0b#BZ\x8d=\x1d?p\x00\x00\x00\x00IEND\xaeB`\x82""" |
|
186 | data = """\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f??a\x00\x00\x00\x04gAMA\x00\x00\xaf?7\x05\x8a?\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq?e<\x00\x00\x025IDAT8?\xa5\x93?K\x94Q\x14\x87\x9f\xf7?Q\x1bs4?\x03\x9a\xa8?B\x02\x8b$\x10[U;i\x13?6h?&h[?"\x14j?\xa2M\x7fB\x14F\x9aQ?&\x842?\x0b\x89"\x82??!?\x9c!\x9c2l??{N\x8bW\x9dY\xb4\t/\x1c?=\x9b?}????\xa9*;9!?\x83\x91?[?\\v*?D\x04\'`EpNp\xa2X\'U?pVq"Sw.\x1e?\x08\x01D?jw????\xbc??7{|\x9b?\x89$\x01??W@\x15\x9c\x05q`Lt/\x97?\x94\xa1d?\x18~?\x18?\x18W[%\xb0?\x83??\x14\x88\x8dB?\xa6H\tL\tl\x19>/\x01`\xac\xabx?\x9cl\nx\xb0\x98\x07\x95\x88D$"q[\x19?d\x00(o\n\xa0??\x7f\xb9\xa4?\x1bF\x1f\x8e\xac\xa8?j??eUU}?.?\x9f\x8cE??x\x94??\r\xbdtoJU5"0N\x10U?\x00??V\t\x02\x9f\x81?U?\x00\x9eM\xae2?r\x9b7\x83\x82\x8aP3????.?&"?\xb7ZP \x0c<?O\xa5\t}\xb8?\x99\xa6?\x87?\x1di|/\xa0??0\xbe\x1fp?d&\x1a\xad\x95\x8a\x07?\t*\x10??b:?d?.\x13C\x8a?\x12\xbe\xbf\x8e?{???\x08?\x80\xa7\x13+d\x13>J?\x80\x15T\x95\x9a\x00??S\x8c\r?\xa1\x03\x07?\x96\x9b\xa7\xab=E??\xa4\xb3?\x19q??B\x91=\x8d??k?J\x0bV"??\xf7x?\xa1\x00?\\.\x87\x87???\x02F@D\x99],??\x10#?X\xb7=\xb9\x10?Z\x1by???cI??\x1ag?\x92\xbc?T?t[\x92\x81?<_\x17~\x92\x88?H%?\x10Q\x02\x9f\n\x81qQ\x0bm?\x1bX?\xb1AK\xa6\x9e\xb9?u\xb2?1\xbe|/\x92M@\xa2!F?\xa9>"\r<DT?>\x92\x8e?>\x9a9Qv\x127?a\xac?Y?8?:??]X???9\x80\xb7?u?\x0b#BZ\x8d=\x1d?p\x00\x00\x00\x00IEND\xaeB`\x82""" | |
179 | filenode = FileNode('calendar.png', content=data) |
|
187 | filenode = FileNode('calendar.png', content=data) | |
180 |
|
|
188 | assert filenode.is_binary |
@@ -1,6 +1,6 b'' | |||||
1 | import datetime |
|
1 | import datetime | |
2 |
|
2 | |||
3 | from kallithea.lib.vcs.utils.compat import unittest |
|
3 | import pytest | |
4 |
|
4 | |||
5 | from kallithea.lib.vcs.nodes import FileNode |
|
5 | from kallithea.lib.vcs.nodes import FileNode | |
6 | from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError |
|
6 | from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError | |
@@ -18,34 +18,30 b' class RepositoryBaseTest(_BackendTestMix' | |||||
18 | return super(RepositoryBaseTest, cls)._get_commits()[:1] |
|
18 | return super(RepositoryBaseTest, cls)._get_commits()[:1] | |
19 |
|
19 | |||
20 | def test_get_config_value(self): |
|
20 | def test_get_config_value(self): | |
21 |
|
|
21 | assert self.repo.get_config_value('universal', 'foo', TEST_USER_CONFIG_FILE) == 'bar' | |
22 | TEST_USER_CONFIG_FILE), 'bar') |
|
|||
23 |
|
22 | |||
24 | def test_get_config_value_defaults_to_None(self): |
|
23 | def test_get_config_value_defaults_to_None(self): | |
25 |
|
|
24 | assert self.repo.get_config_value('universal', 'nonexist', TEST_USER_CONFIG_FILE) == None | |
26 | TEST_USER_CONFIG_FILE), None) |
|
|||
27 |
|
25 | |||
28 | def test_get_user_name(self): |
|
26 | def test_get_user_name(self): | |
29 |
|
|
27 | assert self.repo.get_user_name(TEST_USER_CONFIG_FILE) == 'Foo Bar' | |
30 | 'Foo Bar') |
|
|||
31 |
|
28 | |||
32 | def test_get_user_email(self): |
|
29 | def test_get_user_email(self): | |
33 |
|
|
30 | assert self.repo.get_user_email(TEST_USER_CONFIG_FILE) == 'foo.bar@example.com' | |
34 | 'foo.bar@example.com') |
|
|||
35 |
|
31 | |||
36 | def test_repo_equality(self): |
|
32 | def test_repo_equality(self): | |
37 |
|
|
33 | assert self.repo == self.repo | |
38 |
|
34 | |||
39 | def test_repo_equality_broken_object(self): |
|
35 | def test_repo_equality_broken_object(self): | |
40 | import copy |
|
36 | import copy | |
41 | _repo = copy.copy(self.repo) |
|
37 | _repo = copy.copy(self.repo) | |
42 | delattr(_repo, 'path') |
|
38 | delattr(_repo, 'path') | |
43 |
|
|
39 | assert self.repo != _repo | |
44 |
|
40 | |||
45 | def test_repo_equality_other_object(self): |
|
41 | def test_repo_equality_other_object(self): | |
46 | class dummy(object): |
|
42 | class dummy(object): | |
47 | path = self.repo.path |
|
43 | path = self.repo.path | |
48 |
|
|
44 | assert self.repo != dummy() | |
49 |
|
45 | |||
50 |
|
46 | |||
51 | class RepositoryGetDiffTest(_BackendTestMixin): |
|
47 | class RepositoryGetDiffTest(_BackendTestMixin): | |
@@ -86,16 +82,16 b' class RepositoryGetDiffTest(_BackendTest' | |||||
86 | return commits |
|
82 | return commits | |
87 |
|
83 | |||
88 | def test_raise_for_wrong(self): |
|
84 | def test_raise_for_wrong(self): | |
89 |
with |
|
85 | with pytest.raises(ChangesetDoesNotExistError): | |
90 | self.repo.get_diff('a' * 40, 'b' * 40) |
|
86 | self.repo.get_diff('a' * 40, 'b' * 40) | |
91 |
|
87 | |||
92 |
|
88 | |||
93 |
class GitRepositoryGetDiff |
|
89 | class TestGitRepositoryGetDiff(RepositoryGetDiffTest): | |
94 | backend_alias = 'git' |
|
90 | backend_alias = 'git' | |
95 |
|
91 | |||
96 | def test_initial_commit_diff(self): |
|
92 | def test_initial_commit_diff(self): | |
97 | initial_rev = self.repo.revisions[0] |
|
93 | initial_rev = self.repo.revisions[0] | |
98 |
|
|
94 | assert self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev) == '''diff --git a/foobar b/foobar | |
99 | new file mode 100644 |
|
95 | new file mode 100644 | |
100 | index 0000000000000000000000000000000000000000..f6ea0495187600e7b2288c8ac19c5886383a4632 |
|
96 | index 0000000000000000000000000000000000000000..f6ea0495187600e7b2288c8ac19c5886383a4632 | |
101 | --- /dev/null |
|
97 | --- /dev/null | |
@@ -111,11 +107,11 b' index 0000000000000000000000000000000000' | |||||
111 | @@ -0,0 +1 @@ |
|
107 | @@ -0,0 +1 @@ | |
112 | +foobar2 |
|
108 | +foobar2 | |
113 | \ No newline at end of file |
|
109 | \ No newline at end of file | |
114 |
''' |
|
110 | ''' | |
115 |
|
111 | |||
116 | def test_second_changeset_diff(self): |
|
112 | def test_second_changeset_diff(self): | |
117 | revs = self.repo.revisions |
|
113 | revs = self.repo.revisions | |
118 |
|
|
114 | assert self.repo.get_diff(revs[0], revs[1]) == '''diff --git a/foobar b/foobar | |
119 | index f6ea0495187600e7b2288c8ac19c5886383a4632..389865bb681b358c9b102d79abd8d5f941e96551 100644 |
|
115 | index f6ea0495187600e7b2288c8ac19c5886383a4632..389865bb681b358c9b102d79abd8d5f941e96551 100644 | |
120 | --- a/foobar |
|
116 | --- a/foobar | |
121 | +++ b/foobar |
|
117 | +++ b/foobar | |
@@ -132,11 +128,11 b' index 0000000000000000000000000000000000' | |||||
132 | @@ -0,0 +1 @@ |
|
128 | @@ -0,0 +1 @@ | |
133 | +foobar3 |
|
129 | +foobar3 | |
134 | \ No newline at end of file |
|
130 | \ No newline at end of file | |
135 |
''' |
|
131 | ''' | |
136 |
|
132 | |||
137 | def test_third_changeset_diff(self): |
|
133 | def test_third_changeset_diff(self): | |
138 | revs = self.repo.revisions |
|
134 | revs = self.repo.revisions | |
139 |
|
|
135 | assert self.repo.get_diff(revs[1], revs[2]) == '''diff --git a/foobar b/foobar | |
140 | deleted file mode 100644 |
|
136 | deleted file mode 100644 | |
141 | index 389865bb681b358c9b102d79abd8d5f941e96551..0000000000000000000000000000000000000000 |
|
137 | index 389865bb681b358c9b102d79abd8d5f941e96551..0000000000000000000000000000000000000000 | |
142 | --- a/foobar |
|
138 | --- a/foobar | |
@@ -154,15 +150,15 b' index c11c37d41d33fb47741cff93fa5f9d798c' | |||||
154 | +FOOBAR |
|
150 | +FOOBAR | |
155 | +FOOBAR |
|
151 | +FOOBAR | |
156 | +FOOBAR |
|
152 | +FOOBAR | |
157 |
''' |
|
153 | ''' | |
158 |
|
154 | |||
159 |
|
155 | |||
160 |
class HgRepositoryGetDiff |
|
156 | class TestHgRepositoryGetDiff(RepositoryGetDiffTest): | |
161 | backend_alias = 'hg' |
|
157 | backend_alias = 'hg' | |
162 |
|
158 | |||
163 | def test_initial_commit_diff(self): |
|
159 | def test_initial_commit_diff(self): | |
164 | initial_rev = self.repo.revisions[0] |
|
160 | initial_rev = self.repo.revisions[0] | |
165 |
|
|
161 | assert self.repo.get_diff(self.repo.EMPTY_CHANGESET, initial_rev) == '''diff --git a/foobar b/foobar | |
166 | new file mode 100644 |
|
162 | new file mode 100644 | |
167 | --- /dev/null |
|
163 | --- /dev/null | |
168 | +++ b/foobar |
|
164 | +++ b/foobar | |
@@ -176,11 +172,11 b' new file mode 100644' | |||||
176 | @@ -0,0 +1,1 @@ |
|
172 | @@ -0,0 +1,1 @@ | |
177 | +foobar2 |
|
173 | +foobar2 | |
178 | \ No newline at end of file |
|
174 | \ No newline at end of file | |
179 |
''' |
|
175 | ''' | |
180 |
|
176 | |||
181 | def test_second_changeset_diff(self): |
|
177 | def test_second_changeset_diff(self): | |
182 | revs = self.repo.revisions |
|
178 | revs = self.repo.revisions | |
183 |
|
|
179 | assert self.repo.get_diff(revs[0], revs[1]) == '''diff --git a/foobar b/foobar | |
184 | --- a/foobar |
|
180 | --- a/foobar | |
185 | +++ b/foobar |
|
181 | +++ b/foobar | |
186 | @@ -1,1 +1,1 @@ |
|
182 | @@ -1,1 +1,1 @@ | |
@@ -195,11 +191,11 b' new file mode 100644' | |||||
195 | @@ -0,0 +1,1 @@ |
|
191 | @@ -0,0 +1,1 @@ | |
196 | +foobar3 |
|
192 | +foobar3 | |
197 | \ No newline at end of file |
|
193 | \ No newline at end of file | |
198 |
''' |
|
194 | ''' | |
199 |
|
195 | |||
200 | def test_third_changeset_diff(self): |
|
196 | def test_third_changeset_diff(self): | |
201 | revs = self.repo.revisions |
|
197 | revs = self.repo.revisions | |
202 |
|
|
198 | assert self.repo.get_diff(revs[1], revs[2]) == '''diff --git a/foobar b/foobar | |
203 | deleted file mode 100644 |
|
199 | deleted file mode 100644 | |
204 | --- a/foobar |
|
200 | --- a/foobar | |
205 | +++ /dev/null |
|
201 | +++ /dev/null | |
@@ -215,7 +211,7 b' diff --git a/foobar3 b/foobar3' | |||||
215 | +FOOBAR |
|
211 | +FOOBAR | |
216 | +FOOBAR |
|
212 | +FOOBAR | |
217 | +FOOBAR |
|
213 | +FOOBAR | |
218 |
''' |
|
214 | ''' | |
219 |
|
215 | |||
220 |
|
216 | |||
221 | # For each backend create test case class |
|
217 | # For each backend create test case class | |
@@ -223,6 +219,5 b' for alias in SCM_TESTS:' | |||||
223 | attrs = { |
|
219 | attrs = { | |
224 | 'backend_alias': alias, |
|
220 | 'backend_alias': alias, | |
225 | } |
|
221 | } | |
226 | cls_name = alias.capitalize() + RepositoryBaseTest.__name__ |
|
222 | cls_name = 'Test' + alias.capitalize() + RepositoryBaseTest.__name__ | |
227 | bases = (RepositoryBaseTest, unittest.TestCase) |
|
223 | globals()[cls_name] = type(cls_name, (RepositoryBaseTest,), attrs) | |
228 | globals()[cls_name] = type(cls_name, bases, attrs) |
|
@@ -1,4 +1,4 b'' | |||||
1 | from kallithea.lib.vcs.utils.compat import unittest |
|
1 | import pytest | |
2 |
|
2 | |||
3 | from kallithea.lib.vcs.exceptions import TagAlreadyExistError |
|
3 | from kallithea.lib.vcs.exceptions import TagAlreadyExistError | |
4 | from kallithea.lib.vcs.exceptions import TagDoesNotExistError |
|
4 | from kallithea.lib.vcs.exceptions import TagDoesNotExistError | |
@@ -14,20 +14,20 b' class TagsTestCaseMixin(_BackendTestMixi' | |||||
14 | tagsize = len(self.repo.tags) |
|
14 | tagsize = len(self.repo.tags) | |
15 | tag = self.repo.tag('last-commit', 'joe', tip.raw_id) |
|
15 | tag = self.repo.tag('last-commit', 'joe', tip.raw_id) | |
16 |
|
16 | |||
17 |
|
|
17 | assert len(self.repo.tags) == tagsize + 1 | |
18 | for top, dirs, files in tip.walk(): |
|
18 | for top, dirs, files in tip.walk(): | |
19 |
|
|
19 | assert top == tag.get_node(top.path) | |
20 |
|
20 | |||
21 | def test_tag_already_exist(self): |
|
21 | def test_tag_already_exist(self): | |
22 | tip = self.repo.get_changeset() |
|
22 | tip = self.repo.get_changeset() | |
23 | self.repo.tag('last-commit', 'joe', tip.raw_id) |
|
23 | self.repo.tag('last-commit', 'joe', tip.raw_id) | |
24 |
|
24 | |||
25 |
|
|
25 | with pytest.raises(TagAlreadyExistError): | |
26 |
self.repo.tag |
|
26 | self.repo.tag('last-commit', 'joe', tip.raw_id) | |
27 |
|
27 | |||
28 | chset = self.repo.get_changeset(0) |
|
28 | chset = self.repo.get_changeset(0) | |
29 |
|
|
29 | with pytest.raises(TagAlreadyExistError): | |
30 |
self.repo.tag |
|
30 | self.repo.tag('last-commit', 'jane', chset.raw_id) | |
31 |
|
31 | |||
32 | def test_remove_tag(self): |
|
32 | def test_remove_tag(self): | |
33 | tip = self.repo.get_changeset() |
|
33 | tip = self.repo.get_changeset() | |
@@ -35,15 +35,15 b' class TagsTestCaseMixin(_BackendTestMixi' | |||||
35 | tagsize = len(self.repo.tags) |
|
35 | tagsize = len(self.repo.tags) | |
36 |
|
36 | |||
37 | self.repo.remove_tag('last-commit', user='evil joe') |
|
37 | self.repo.remove_tag('last-commit', user='evil joe') | |
38 |
|
|
38 | assert len(self.repo.tags) == tagsize - 1 | |
39 |
|
39 | |||
40 | def test_remove_tag_which_does_not_exist(self): |
|
40 | def test_remove_tag_which_does_not_exist(self): | |
41 |
|
|
41 | with pytest.raises(TagDoesNotExistError): | |
42 |
self.repo.remove_tag |
|
42 | self.repo.remove_tag('last-commit', user='evil joe') | |
43 |
|
43 | |||
44 | def test_name_with_slash(self): |
|
44 | def test_name_with_slash(self): | |
45 | self.repo.tag('19/10/11', 'joe') |
|
45 | self.repo.tag('19/10/11', 'joe') | |
46 |
|
|
46 | assert '19/10/11' in self.repo.tags | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | # For each backend create test case class |
|
49 | # For each backend create test case class | |
@@ -51,6 +51,5 b' for alias in SCM_TESTS:' | |||||
51 | attrs = { |
|
51 | attrs = { | |
52 | 'backend_alias': alias, |
|
52 | 'backend_alias': alias, | |
53 | } |
|
53 | } | |
54 |
cls_name = ''.join(('%s tags |
|
54 | cls_name = ''.join(('test %s tags' % alias).title().split()) | |
55 | bases = (TagsTestCaseMixin, unittest.TestCase) |
|
55 | globals()[cls_name] = type(cls_name, (TagsTestCaseMixin,), attrs) | |
56 | globals()[cls_name] = type(cls_name, bases, attrs) |
|
@@ -6,7 +6,7 b' import time' | |||||
6 | import shutil |
|
6 | import shutil | |
7 | import datetime |
|
7 | import datetime | |
8 |
|
8 | |||
9 | from kallithea.lib.vcs.utils.compat import unittest |
|
9 | import pytest | |
10 |
|
10 | |||
11 | from kallithea.lib.vcs.utils.paths import get_dirs_for_path |
|
11 | from kallithea.lib.vcs.utils.paths import get_dirs_for_path | |
12 | from kallithea.lib.vcs.utils.helpers import get_dict_for_attrs |
|
12 | from kallithea.lib.vcs.utils.helpers import get_dict_for_attrs | |
@@ -22,7 +22,7 b' from kallithea.lib.vcs.exceptions import' | |||||
22 | from kallithea.tests.vcs.conf import TEST_HG_REPO, TEST_GIT_REPO, TESTS_TMP_PATH |
|
22 | from kallithea.tests.vcs.conf import TEST_HG_REPO, TEST_GIT_REPO, TESTS_TMP_PATH | |
23 |
|
23 | |||
24 |
|
24 | |||
25 | class PathsTest(unittest.TestCase): |
|
25 | class TestPaths(object): | |
26 |
|
26 | |||
27 | def _test_get_dirs_for_path(self, path, expected): |
|
27 | def _test_get_dirs_for_path(self, path, expected): | |
28 | """ |
|
28 | """ | |
@@ -30,9 +30,8 b' class PathsTest(unittest.TestCase):' | |||||
30 | """ |
|
30 | """ | |
31 | expected = sorted(expected) |
|
31 | expected = sorted(expected) | |
32 | result = sorted(get_dirs_for_path(path)) |
|
32 | result = sorted(get_dirs_for_path(path)) | |
33 |
|
|
33 | assert result == expected, \ | |
34 |
|
|
34 | "%s != %s which was expected result for path %s" % (result, expected, path) | |
35 | % (result, expected, path)) |
|
|||
36 |
|
35 | |||
37 | def test_get_dirs_for_path(self): |
|
36 | def test_get_dirs_for_path(self): | |
38 | path = 'foo/bar/baz/file' |
|
37 | path = 'foo/bar/baz/file' | |
@@ -45,8 +44,8 b' class PathsTest(unittest.TestCase):' | |||||
45 | self._test_get_dirs_for_path(path, expected) |
|
44 | self._test_get_dirs_for_path(path, expected) | |
46 |
|
45 | |||
47 | def test_get_scm(self): |
|
46 | def test_get_scm(self): | |
48 |
|
|
47 | assert ('hg', TEST_HG_REPO) == get_scm(TEST_HG_REPO) | |
49 |
|
|
48 | assert ('git', TEST_GIT_REPO) == get_scm(TEST_GIT_REPO) | |
50 |
|
49 | |||
51 | def test_get_two_scms_for_path(self): |
|
50 | def test_get_two_scms_for_path(self): | |
52 | multialias_repo_path = os.path.join(TESTS_TMP_PATH, 'hg-git-repo-2') |
|
51 | multialias_repo_path = os.path.join(TESTS_TMP_PATH, 'hg-git-repo-2') | |
@@ -55,135 +54,130 b' class PathsTest(unittest.TestCase):' | |||||
55 |
|
54 | |||
56 | os.mkdir(multialias_repo_path) |
|
55 | os.mkdir(multialias_repo_path) | |
57 |
|
56 | |||
58 | self.assertRaises(VCSError, get_scm, multialias_repo_path) |
|
57 | with pytest.raises(VCSError): | |
|
58 | get_scm(multialias_repo_path) | |||
59 |
|
59 | |||
60 | def test_get_scm_error_path(self): |
|
60 | def test_get_scm_error_path(self): | |
61 | self.assertRaises(VCSError, get_scm, 'err') |
|
61 | with pytest.raises(VCSError): | |
|
62 | get_scm('err') | |||
62 |
|
63 | |||
63 | def test_get_scms_for_path(self): |
|
64 | def test_get_scms_for_path(self): | |
64 | new = os.path.join(TESTS_TMP_PATH, 'vcs-scms-for-path-%s' % time.time()) |
|
65 | new = os.path.join(TESTS_TMP_PATH, 'vcs-scms-for-path-%s' % time.time()) | |
65 | os.mkdir(new) |
|
66 | os.mkdir(new) | |
66 |
|
|
67 | assert get_scms_for_path(new) == [] | |
67 |
|
68 | |||
68 | os.mkdir(os.path.join(new, '.tux')) |
|
69 | os.mkdir(os.path.join(new, '.tux')) | |
69 |
|
|
70 | assert get_scms_for_path(new) == [] | |
70 |
|
71 | |||
71 | os.mkdir(os.path.join(new, '.git')) |
|
72 | os.mkdir(os.path.join(new, '.git')) | |
72 |
|
|
73 | assert set(get_scms_for_path(new)) == set(['git']) | |
73 |
|
74 | |||
74 | os.mkdir(os.path.join(new, '.hg')) |
|
75 | os.mkdir(os.path.join(new, '.hg')) | |
75 |
|
|
76 | assert set(get_scms_for_path(new)) == set(['git', 'hg']) | |
76 |
|
77 | |||
77 |
|
78 | |||
78 |
class TestParseChangesets( |
|
79 | class TestParseChangesets(object): | |
79 |
|
80 | |||
80 | def test_main_is_returned_correctly(self): |
|
81 | def test_main_is_returned_correctly(self): | |
81 |
|
|
82 | assert parse_changesets('123456') == { | |
82 | 'start': None, |
|
83 | 'start': None, | |
83 | 'main': '123456', |
|
84 | 'main': '123456', | |
84 | 'end': None, |
|
85 | 'end': None, | |
85 |
} |
|
86 | } | |
86 |
|
87 | |||
87 | def test_start_is_returned_correctly(self): |
|
88 | def test_start_is_returned_correctly(self): | |
88 |
|
|
89 | assert parse_changesets('aaabbb..') == { | |
89 | 'start': 'aaabbb', |
|
90 | 'start': 'aaabbb', | |
90 | 'main': None, |
|
91 | 'main': None, | |
91 | 'end': None, |
|
92 | 'end': None, | |
92 |
} |
|
93 | } | |
93 |
|
94 | |||
94 | def test_end_is_returned_correctly(self): |
|
95 | def test_end_is_returned_correctly(self): | |
95 |
|
|
96 | assert parse_changesets('..cccddd') == { | |
96 | 'start': None, |
|
97 | 'start': None, | |
97 | 'main': None, |
|
98 | 'main': None, | |
98 | 'end': 'cccddd', |
|
99 | 'end': 'cccddd', | |
99 |
} |
|
100 | } | |
100 |
|
101 | |||
101 | def test_that_two_or_three_dots_are_allowed(self): |
|
102 | def test_that_two_or_three_dots_are_allowed(self): | |
102 | text1 = 'a..b' |
|
103 | text1 = 'a..b' | |
103 | text2 = 'a...b' |
|
104 | text2 = 'a...b' | |
104 |
|
|
105 | assert parse_changesets(text1) == parse_changesets(text2) | |
105 |
|
106 | |||
106 | def test_that_input_is_stripped_first(self): |
|
107 | def test_that_input_is_stripped_first(self): | |
107 | text1 = 'a..bb' |
|
108 | text1 = 'a..bb' | |
108 | text2 = ' a..bb\t\n\t ' |
|
109 | text2 = ' a..bb\t\n\t ' | |
109 |
|
|
110 | assert parse_changesets(text1) == parse_changesets(text2) | |
110 |
|
111 | |||
111 | def test_that_exception_is_raised(self): |
|
112 | def test_that_exception_is_raised(self): | |
112 | text = '123456.789012' # single dot is not recognized |
|
113 | text = '123456.789012' # single dot is not recognized | |
113 |
with |
|
114 | with pytest.raises(ValueError): | |
114 | parse_changesets(text) |
|
115 | parse_changesets(text) | |
115 |
|
116 | |||
116 | def test_non_alphanumeric_raises_exception(self): |
|
117 | def test_non_alphanumeric_raises_exception(self): | |
117 |
with |
|
118 | with pytest.raises(ValueError): | |
118 | parse_changesets('aaa@bbb') |
|
119 | parse_changesets('aaa@bbb') | |
119 |
|
120 | |||
120 |
|
121 | |||
121 |
class TestParseDatetime( |
|
122 | class TestParseDatetime(object): | |
122 |
|
123 | |||
123 | def test_datetime_text(self): |
|
124 | def test_datetime_text(self): | |
124 |
|
|
125 | assert parse_datetime('2010-04-07 21:29:41') == datetime.datetime(2010, 4, 7, 21, 29, 41) | |
125 | datetime.datetime(2010, 4, 7, 21, 29, 41)) |
|
|||
126 |
|
126 | |||
127 | def test_no_seconds(self): |
|
127 | def test_no_seconds(self): | |
128 |
|
|
128 | assert parse_datetime('2010-04-07 21:29') == datetime.datetime(2010, 4, 7, 21, 29) | |
129 | datetime.datetime(2010, 4, 7, 21, 29)) |
|
|||
130 |
|
129 | |||
131 | def test_date_only(self): |
|
130 | def test_date_only(self): | |
132 |
|
|
131 | assert parse_datetime('2010-04-07') == datetime.datetime(2010, 4, 7) | |
133 | datetime.datetime(2010, 4, 7)) |
|
|||
134 |
|
132 | |||
135 | def test_another_format(self): |
|
133 | def test_another_format(self): | |
136 |
|
|
134 | assert parse_datetime('04/07/10 21:29:41') == datetime.datetime(2010, 4, 7, 21, 29, 41) | |
137 | datetime.datetime(2010, 4, 7, 21, 29, 41)) |
|
|||
138 |
|
135 | |||
139 | def test_now(self): |
|
136 | def test_now(self): | |
140 |
|
|
137 | assert parse_datetime('now') - datetime.datetime.now() < datetime.timedelta(seconds=1) | |
141 | datetime.timedelta(seconds=1)) |
|
|||
142 |
|
138 | |||
143 | def test_today(self): |
|
139 | def test_today(self): | |
144 | today = datetime.date.today() |
|
140 | today = datetime.date.today() | |
145 | self.assertEqual(parse_datetime('today'), |
|
141 | assert parse_datetime('today') == datetime.datetime(*today.timetuple()[:3]) | |
146 | datetime.datetime(*today.timetuple()[:3])) |
|
|||
147 |
|
142 | |||
148 | def test_yesterday(self): |
|
143 | def test_yesterday(self): | |
149 | yesterday = datetime.date.today() - datetime.timedelta(days=1) |
|
144 | yesterday = datetime.date.today() - datetime.timedelta(days=1) | |
150 | self.assertEqual(parse_datetime('yesterday'), |
|
145 | assert parse_datetime('yesterday') == datetime.datetime(*yesterday.timetuple()[:3]) | |
151 | datetime.datetime(*yesterday.timetuple()[:3])) |
|
|||
152 |
|
146 | |||
153 | def test_tomorrow(self): |
|
147 | def test_tomorrow(self): | |
154 | tomorrow = datetime.date.today() + datetime.timedelta(days=1) |
|
148 | tomorrow = datetime.date.today() + datetime.timedelta(days=1) | |
155 | args = tomorrow.timetuple()[:3] + (23, 59, 59) |
|
149 | args = tomorrow.timetuple()[:3] + (23, 59, 59) | |
156 |
|
|
150 | assert parse_datetime('tomorrow') == datetime.datetime(*args) | |
157 |
|
151 | |||
158 | def test_days(self): |
|
152 | def test_days(self): | |
159 | timestamp = datetime.datetime.today() - datetime.timedelta(days=3) |
|
153 | timestamp = datetime.datetime.today() - datetime.timedelta(days=3) | |
160 | args = timestamp.timetuple()[:3] + (0, 0, 0, 0) |
|
154 | args = timestamp.timetuple()[:3] + (0, 0, 0, 0) | |
161 | expected = datetime.datetime(*args) |
|
155 | expected = datetime.datetime(*args) | |
162 |
|
|
156 | assert parse_datetime('3d') == expected | |
163 |
|
|
157 | assert parse_datetime('3 d') == expected | |
164 |
|
|
158 | assert parse_datetime('3 day') == expected | |
165 |
|
|
159 | assert parse_datetime('3 days') == expected | |
166 |
|
160 | |||
167 | def test_weeks(self): |
|
161 | def test_weeks(self): | |
168 | timestamp = datetime.datetime.today() - datetime.timedelta(days=3 * 7) |
|
162 | timestamp = datetime.datetime.today() - datetime.timedelta(days=3 * 7) | |
169 | args = timestamp.timetuple()[:3] + (0, 0, 0, 0) |
|
163 | args = timestamp.timetuple()[:3] + (0, 0, 0, 0) | |
170 | expected = datetime.datetime(*args) |
|
164 | expected = datetime.datetime(*args) | |
171 |
|
|
165 | assert parse_datetime('3w') == expected | |
172 |
|
|
166 | assert parse_datetime('3 w') == expected | |
173 |
|
|
167 | assert parse_datetime('3 week') == expected | |
174 |
|
|
168 | assert parse_datetime('3 weeks') == expected | |
175 |
|
169 | |||
176 | def test_mixed(self): |
|
170 | def test_mixed(self): | |
177 | timestamp = datetime.datetime.today() - datetime.timedelta(days=2 * 7 + 3) |
|
171 | timestamp = datetime.datetime.today() - datetime.timedelta(days=2 * 7 + 3) | |
178 | args = timestamp.timetuple()[:3] + (0, 0, 0, 0) |
|
172 | args = timestamp.timetuple()[:3] + (0, 0, 0, 0) | |
179 | expected = datetime.datetime(*args) |
|
173 | expected = datetime.datetime(*args) | |
180 |
|
|
174 | assert parse_datetime('2w3d') == expected | |
181 |
|
|
175 | assert parse_datetime('2w 3d') == expected | |
182 |
|
|
176 | assert parse_datetime('2w 3 days') == expected | |
183 |
|
|
177 | assert parse_datetime('2 weeks 3 days') == expected | |
184 |
|
178 | |||
185 |
|
179 | |||
186 |
class TestAuthorExtractors( |
|
180 | class TestAuthorExtractors(object): | |
187 | TEST_AUTHORS = [("Username Last'o'Name <username@example.com>", |
|
181 | TEST_AUTHORS = [("Username Last'o'Name <username@example.com>", | |
188 | ("Username Last'o'Name", "username@example.com")), |
|
182 | ("Username Last'o'Name", "username@example.com")), | |
189 | ("Username Last'o'Name Spaces < username@example.com >", |
|
183 | ("Username Last'o'Name Spaces < username@example.com >", | |
@@ -210,14 +204,14 b' class TestAuthorExtractors(unittest.Test' | |||||
210 |
|
204 | |||
211 | def test_author_email(self): |
|
205 | def test_author_email(self): | |
212 | for test_str, result in self.TEST_AUTHORS: |
|
206 | for test_str, result in self.TEST_AUTHORS: | |
213 |
|
|
207 | assert result[1] == author_email(test_str) | |
214 |
|
208 | |||
215 | def test_author_name(self): |
|
209 | def test_author_name(self): | |
216 | for test_str, result in self.TEST_AUTHORS: |
|
210 | for test_str, result in self.TEST_AUTHORS: | |
217 |
|
|
211 | assert result[0] == author_name(test_str) | |
218 |
|
212 | |||
219 |
|
213 | |||
220 |
class TestGetDictForAttrs( |
|
214 | class TestGetDictForAttrs(object): | |
221 |
|
215 | |||
222 | def test_returned_dict_has_expected_attrs(self): |
|
216 | def test_returned_dict_has_expected_attrs(self): | |
223 | obj = mock.Mock() |
|
217 | obj = mock.Mock() | |
@@ -228,23 +222,22 b' class TestGetDictForAttrs(unittest.TestC' | |||||
228 | obj.date = datetime.datetime(2010, 12, 31) |
|
222 | obj.date = datetime.datetime(2010, 12, 31) | |
229 | obj.count = 1001 |
|
223 | obj.count = 1001 | |
230 |
|
224 | |||
231 |
|
|
225 | assert get_dict_for_attrs(obj, ['CONST', 'foo', 'attrs', 'date', 'count']) == { | |
232 | 'date', 'count']), { |
|
|||
233 | 'CONST': True, |
|
226 | 'CONST': True, | |
234 | 'foo': 'aaa', |
|
227 | 'foo': 'aaa', | |
235 | 'attrs': {'foo': 'bar'}, |
|
228 | 'attrs': {'foo': 'bar'}, | |
236 | 'date': datetime.datetime(2010, 12, 31), |
|
229 | 'date': datetime.datetime(2010, 12, 31), | |
237 | 'count': 1001, |
|
230 | 'count': 1001, | |
238 |
} |
|
231 | } | |
239 |
|
232 | |||
240 |
|
233 | |||
241 |
class TestGetTotalSeconds( |
|
234 | class TestGetTotalSeconds(object): | |
242 |
|
235 | |||
243 | def assertTotalSecondsEqual(self, timedelta, expected_seconds): |
|
236 | def assertTotalSecondsEqual(self, timedelta, expected_seconds): | |
244 | result = get_total_seconds(timedelta) |
|
237 | result = get_total_seconds(timedelta) | |
245 |
|
|
238 | assert result == expected_seconds, \ | |
246 | "We computed %s seconds for %s but expected %s" |
|
239 | "We computed %s seconds for %s but expected %s" \ | |
247 |
% (result, timedelta, expected_seconds) |
|
240 | % (result, timedelta, expected_seconds) | |
248 |
|
241 | |||
249 | def test_get_total_seconds_returns_proper_value(self): |
|
242 | def test_get_total_seconds_returns_proper_value(self): | |
250 | self.assertTotalSecondsEqual(datetime.timedelta(seconds=1001), 1001) |
|
243 | self.assertTotalSecondsEqual(datetime.timedelta(seconds=1001), 1001) | |
@@ -253,21 +246,21 b' class TestGetTotalSeconds(unittest.TestC' | |||||
253 | self.assertTotalSecondsEqual(datetime.timedelta(seconds=50.65), 50.65) |
|
246 | self.assertTotalSecondsEqual(datetime.timedelta(seconds=50.65), 50.65) | |
254 |
|
247 | |||
255 |
|
248 | |||
256 |
class TestGetUserHome( |
|
249 | class TestGetUserHome(object): | |
257 |
|
250 | |||
258 | @mock.patch.object(os, 'environ', {}) |
|
251 | @mock.patch.object(os, 'environ', {}) | |
259 | def test_defaults_to_none(self): |
|
252 | def test_defaults_to_none(self): | |
260 |
|
|
253 | assert get_user_home() == '' | |
261 |
|
254 | |||
262 | @mock.patch.object(os, 'environ', {'HOME': '/home/foobar'}) |
|
255 | @mock.patch.object(os, 'environ', {'HOME': '/home/foobar'}) | |
263 | def test_unix_like(self): |
|
256 | def test_unix_like(self): | |
264 |
|
|
257 | assert get_user_home() == '/home/foobar' | |
265 |
|
258 | |||
266 | @mock.patch.object(os, 'environ', {'USERPROFILE': '/Users/foobar'}) |
|
259 | @mock.patch.object(os, 'environ', {'USERPROFILE': '/Users/foobar'}) | |
267 | def test_windows_like(self): |
|
260 | def test_windows_like(self): | |
268 |
|
|
261 | assert get_user_home() == '/Users/foobar' | |
269 |
|
262 | |||
270 | @mock.patch.object(os, 'environ', {'HOME': '/home/foobar', |
|
263 | @mock.patch.object(os, 'environ', {'HOME': '/home/foobar', | |
271 | 'USERPROFILE': '/Users/foobar'}) |
|
264 | 'USERPROFILE': '/Users/foobar'}) | |
272 | def test_prefers_home_over_userprofile(self): |
|
265 | def test_prefers_home_over_userprofile(self): | |
273 |
|
|
266 | assert get_user_home() == '/home/foobar' |
@@ -1,20 +1,19 b'' | |||||
1 | from kallithea.lib.vcs.utils.filesize import filesizeformat |
|
1 | from kallithea.lib.vcs.utils.filesize import filesizeformat | |
2 | from kallithea.lib.vcs.utils.compat import unittest |
|
|||
3 |
|
2 | |||
4 |
|
3 | |||
5 |
class TestFilesizeformat( |
|
4 | class TestFilesizeformat(object): | |
6 |
|
5 | |||
7 | def test_bytes(self): |
|
6 | def test_bytes(self): | |
8 |
|
|
7 | assert filesizeformat(10) == '10 B' | |
9 |
|
8 | |||
10 | def test_kilobytes(self): |
|
9 | def test_kilobytes(self): | |
11 |
|
|
10 | assert filesizeformat(1024 * 2) == '2 KB' | |
12 |
|
11 | |||
13 | def test_megabytes(self): |
|
12 | def test_megabytes(self): | |
14 |
|
|
13 | assert filesizeformat(1024 * 1024 * 2.3) == '2.3 MB' | |
15 |
|
14 | |||
16 | def test_gigabytes(self): |
|
15 | def test_gigabytes(self): | |
17 |
|
|
16 | assert filesizeformat(1024 * 1024 * 1024 * 12.92) == '12.92 GB' | |
18 |
|
17 | |||
19 | def test_that_function_respects_sep_parameter(self): |
|
18 | def test_that_function_respects_sep_parameter(self): | |
20 |
|
|
19 | assert filesizeformat(1, '') == '1B' |
@@ -1,7 +1,7 b'' | |||||
1 | import os |
|
1 | import os | |
2 | import shutil |
|
2 | import shutil | |
3 |
|
3 | |||
4 | from kallithea.lib.vcs.utils.compat import unittest |
|
4 | import pytest | |
5 |
|
5 | |||
6 | from kallithea.lib.utils2 import safe_str |
|
6 | from kallithea.lib.utils2 import safe_str | |
7 | from kallithea.lib.vcs import VCSError, get_repo, get_backend |
|
7 | from kallithea.lib.vcs import VCSError, get_repo, get_backend | |
@@ -10,32 +10,33 b' from kallithea.lib.vcs.backends.hg impor' | |||||
10 | from kallithea.tests.vcs.conf import TEST_HG_REPO, TEST_GIT_REPO, TESTS_TMP_PATH |
|
10 | from kallithea.tests.vcs.conf import TEST_HG_REPO, TEST_GIT_REPO, TESTS_TMP_PATH | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | class VCSTest(unittest.TestCase): |
|
13 | class TestVCS(object): | |
14 | """ |
|
14 | """ | |
15 | Tests for main module's methods. |
|
15 | Tests for main module's methods. | |
16 | """ |
|
16 | """ | |
17 |
|
17 | |||
18 | def test_get_backend(self): |
|
18 | def test_get_backend(self): | |
19 | hg = get_backend('hg') |
|
19 | hg = get_backend('hg') | |
20 |
|
|
20 | assert hg == MercurialRepository | |
21 |
|
21 | |||
22 | def test_alias_detect_hg(self): |
|
22 | def test_alias_detect_hg(self): | |
23 | alias = 'hg' |
|
23 | alias = 'hg' | |
24 | path = TEST_HG_REPO |
|
24 | path = TEST_HG_REPO | |
25 | backend = get_backend(alias) |
|
25 | backend = get_backend(alias) | |
26 | repo = backend(safe_str(path)) |
|
26 | repo = backend(safe_str(path)) | |
27 |
|
|
27 | assert 'hg' == repo.alias | |
28 |
|
28 | |||
29 | def test_alias_detect_git(self): |
|
29 | def test_alias_detect_git(self): | |
30 | alias = 'git' |
|
30 | alias = 'git' | |
31 | path = TEST_GIT_REPO |
|
31 | path = TEST_GIT_REPO | |
32 | backend = get_backend(alias) |
|
32 | backend = get_backend(alias) | |
33 | repo = backend(safe_str(path)) |
|
33 | repo = backend(safe_str(path)) | |
34 |
|
|
34 | assert 'git' == repo.alias | |
35 |
|
35 | |||
36 | def test_wrong_alias(self): |
|
36 | def test_wrong_alias(self): | |
37 | alias = 'wrong_alias' |
|
37 | alias = 'wrong_alias' | |
38 | self.assertRaises(VCSError, get_backend, alias) |
|
38 | with pytest.raises(VCSError): | |
|
39 | get_backend(alias) | |||
39 |
|
40 | |||
40 | def test_get_repo(self): |
|
41 | def test_get_repo(self): | |
41 | alias = 'hg' |
|
42 | alias = 'hg' | |
@@ -43,8 +44,8 b' class VCSTest(unittest.TestCase):' | |||||
43 | backend = get_backend(alias) |
|
44 | backend = get_backend(alias) | |
44 | repo = backend(safe_str(path)) |
|
45 | repo = backend(safe_str(path)) | |
45 |
|
46 | |||
46 |
|
|
47 | assert repo.__class__ == get_repo(safe_str(path), alias).__class__ | |
47 |
|
|
48 | assert repo.path == get_repo(safe_str(path), alias).path | |
48 |
|
49 | |||
49 | def test_get_repo_autoalias_hg(self): |
|
50 | def test_get_repo_autoalias_hg(self): | |
50 | alias = 'hg' |
|
51 | alias = 'hg' | |
@@ -52,8 +53,8 b' class VCSTest(unittest.TestCase):' | |||||
52 | backend = get_backend(alias) |
|
53 | backend = get_backend(alias) | |
53 | repo = backend(safe_str(path)) |
|
54 | repo = backend(safe_str(path)) | |
54 |
|
55 | |||
55 |
|
|
56 | assert repo.__class__ == get_repo(safe_str(path)).__class__ | |
56 |
|
|
57 | assert repo.path == get_repo(safe_str(path)).path | |
57 |
|
58 | |||
58 | def test_get_repo_autoalias_git(self): |
|
59 | def test_get_repo_autoalias_git(self): | |
59 | alias = 'git' |
|
60 | alias = 'git' | |
@@ -61,8 +62,8 b' class VCSTest(unittest.TestCase):' | |||||
61 | backend = get_backend(alias) |
|
62 | backend = get_backend(alias) | |
62 | repo = backend(safe_str(path)) |
|
63 | repo = backend(safe_str(path)) | |
63 |
|
64 | |||
64 |
|
|
65 | assert repo.__class__ == get_repo(safe_str(path)).__class__ | |
65 |
|
|
66 | assert repo.path == get_repo(safe_str(path)).path | |
66 |
|
67 | |||
67 | def test_get_repo_err(self): |
|
68 | def test_get_repo_err(self): | |
68 | blank_repo_path = os.path.join(TESTS_TMP_PATH, 'blank-error-repo') |
|
69 | blank_repo_path = os.path.join(TESTS_TMP_PATH, 'blank-error-repo') | |
@@ -70,8 +71,10 b' class VCSTest(unittest.TestCase):' | |||||
70 | shutil.rmtree(blank_repo_path) |
|
71 | shutil.rmtree(blank_repo_path) | |
71 |
|
72 | |||
72 | os.mkdir(blank_repo_path) |
|
73 | os.mkdir(blank_repo_path) | |
73 | self.assertRaises(VCSError, get_repo, blank_repo_path) |
|
74 | with pytest.raises(VCSError): | |
74 | self.assertRaises(VCSError, get_repo, blank_repo_path + 'non_existing') |
|
75 | get_repo(blank_repo_path) | |
|
76 | with pytest.raises(VCSError): | |||
|
77 | get_repo(blank_repo_path + 'non_existing') | |||
75 |
|
78 | |||
76 | def test_get_repo_multialias(self): |
|
79 | def test_get_repo_multialias(self): | |
77 | multialias_repo_path = os.path.join(TESTS_TMP_PATH, 'hg-git-repo') |
|
80 | multialias_repo_path = os.path.join(TESTS_TMP_PATH, 'hg-git-repo') | |
@@ -82,4 +85,5 b' class VCSTest(unittest.TestCase):' | |||||
82 |
|
85 | |||
83 | os.mkdir(os.path.join(multialias_repo_path, '.git')) |
|
86 | os.mkdir(os.path.join(multialias_repo_path, '.git')) | |
84 | os.mkdir(os.path.join(multialias_repo_path, '.hg')) |
|
87 | os.mkdir(os.path.join(multialias_repo_path, '.hg')) | |
85 | self.assertRaises(VCSError, get_repo, multialias_repo_path) |
|
88 | with pytest.raises(VCSError): | |
|
89 | get_repo(multialias_repo_path) |
General Comments 0
You need to be logged in to leave comments.
Login now