##// END OF EJS Templates
tests: fixing test_diffprocessor_as_html_with_comments
lisaq -
r420:5caecaf7 default
parent child Browse files
Show More
@@ -1,732 +1,748 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import textwrap
22 22
23 23 import pytest
24 24
25 25 from rhodecode.lib.diffs import (
26 26 DiffProcessor, wrapped_diff,
27 27 NEW_FILENODE, DEL_FILENODE, MOD_FILENODE, RENAMED_FILENODE,
28 28 CHMOD_FILENODE, BIN_FILENODE, COPIED_FILENODE)
29 29 from rhodecode.tests.fixture import Fixture
30 30 from rhodecode.lib.vcs.backends.git.repository import GitDiff
31 31 from rhodecode.lib.vcs.backends.hg.repository import MercurialDiff
32 32 from rhodecode.lib.vcs.backends.svn.repository import SubversionDiff
33 33
34 34 fixture = Fixture()
35 35
36 36
37 37 def test_wrapped_diff_limited_file_diff(vcsbackend_random):
38 38 vcsbackend = vcsbackend_random
39 39 repo = vcsbackend.create_repo()
40 40 vcsbackend.add_file(repo, 'a_file', content="line 1\nline 2\nline3\n")
41 41 commit = repo.get_commit()
42 42 file_node = commit.get_node('a_file')
43 43
44 44 # Only limit the file diff to trigger the code path
45 45 result = wrapped_diff(
46 46 None, file_node, diff_limit=10000, file_limit=1)
47 47 data = result[5]
48 48
49 49 # Verify that the limits were applied
50 50 assert data['exceeds_limit'] is True
51 51 assert data['is_limited_diff'] is True
52 52
53 53
54 54 def test_diffprocessor_as_html_with_comments():
55 55 raw_diff = textwrap.dedent('''
56 56 diff --git a/setup.py b/setup.py
57 57 index 5b36422..cfd698e 100755
58 58 --- a/setup.py
59 59 +++ b/setup.py
60 60 @@ -2,7 +2,7 @@
61 61 #!/usr/bin/python
62 62 # Setup file for X
63 63 # Copyright (C) No one
64 64 -
65 65 +x
66 66 try:
67 67 from setuptools import setup, Extension
68 68 except ImportError:
69 69 ''')
70 70 diff = GitDiff(raw_diff)
71 71 processor = DiffProcessor(diff)
72 72 processor.prepare()
73 73
74 74 # Note that the cell with the context in line 5 (in the html) has the
75 75 # no-comment class, which will prevent the add comment icon to be displayed.
76 76 expected_html = textwrap.dedent('''
77 77 <table class="code-difftable">
78 78 <tr class="line context">
79 79 <td class="add-comment-line"><span class="add-comment-content"></span></td>
80 80 <td class="lineno old">...</td>
81 81 <td class="lineno new">...</td>
82 82 <td class="code no-comment">
83 83 <pre>@@ -2,7 +2,7 @@
84 84 </pre>
85 85 </td>
86 86 </tr>
87 87 <tr class="line unmod">
88 88 <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td>
89 <td id="setuppy_o2" class="lineno old"><a href="#setuppy_o2">2</a></td>
90 <td id="setuppy_n2" class="lineno new"><a href="#setuppy_n2">2</a></td>
89 <td id="setuppy_o2" class="lineno old"><a href="#setuppy_o2" class="tooltip"
90 title="Click to select line">2</a></td>
91 <td id="setuppy_n2" class="lineno new"><a href="#setuppy_n2" class="tooltip"
92 title="Click to select line">2</a></td>
91 93 <td class="code">
92 94 <pre>#!/usr/bin/python
93 95 </pre>
94 96 </td>
95 97 </tr>
96 98 <tr class="line unmod">
97 99 <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td>
98 <td id="setuppy_o3" class="lineno old"><a href="#setuppy_o3">3</a></td>
99 <td id="setuppy_n3" class="lineno new"><a href="#setuppy_n3">3</a></td>
100 <td id="setuppy_o3" class="lineno old"><a href="#setuppy_o3" class="tooltip"
101 title="Click to select line">3</a></td>
102 <td id="setuppy_n3" class="lineno new"><a href="#setuppy_n3" class="tooltip"
103 title="Click to select line">3</a></td>
100 104 <td class="code">
101 105 <pre># Setup file for X
102 106 </pre>
103 107 </td>
104 108 </tr>
105 109 <tr class="line unmod">
106 110 <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td>
107 <td id="setuppy_o4" class="lineno old"><a href="#setuppy_o4">4</a></td>
108 <td id="setuppy_n4" class="lineno new"><a href="#setuppy_n4">4</a></td>
111 <td id="setuppy_o4" class="lineno old"><a href="#setuppy_o4" class="tooltip"
112 title="Click to select line">4</a></td>
113 <td id="setuppy_n4" class="lineno new"><a href="#setuppy_n4" class="tooltip"
114 title="Click to select line">4</a></td>
109 115 <td class="code">
110 116 <pre># Copyright (C) No one
111 117 </pre>
112 118 </td>
113 119 </tr>
114 120 <tr class="line del">
115 121 <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td>
116 <td id="setuppy_o5" class="lineno old"><a href="#setuppy_o5">5</a></td>
117 <td class="lineno new"><a href="#setuppy_n"></a></td>
122 <td id="setuppy_o5" class="lineno old"><a href="#setuppy_o5" class="tooltip"
123 title="Click to select line">5</a></td>
124 <td class="lineno new"><a href="#setuppy_n" class="tooltip"
125 title="Click to select line"></a></td>
118 126 <td class="code">
119 127 <pre>
120 128 </pre>
121 129 </td>
122 130 </tr>
123 131 <tr class="line add">
124 132 <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td>
125 <td class="lineno old"><a href="#setuppy_o"></a></td>
126 <td id="setuppy_n5" class="lineno new"><a href="#setuppy_n5">5</a></td>
133 <td class="lineno old"><a href="#setuppy_o" class="tooltip"
134 title="Click to select line"></a></td>
135 <td id="setuppy_n5" class="lineno new"><a href="#setuppy_n5" class="tooltip"
136 title="Click to select line">5</a></td>
127 137 <td class="code">
128 138 <pre><ins>x</ins>
129 139 </pre>
130 140 </td>
131 141 </tr>
132 142 <tr class="line unmod">
133 143 <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td>
134 <td id="setuppy_o6" class="lineno old"><a href="#setuppy_o6">6</a></td>
135 <td id="setuppy_n6" class="lineno new"><a href="#setuppy_n6">6</a></td>
144 <td id="setuppy_o6" class="lineno old"><a href="#setuppy_o6" class="tooltip"
145 title="Click to select line">6</a></td>
146 <td id="setuppy_n6" class="lineno new"><a href="#setuppy_n6" class="tooltip"
147 title="Click to select line">6</a></td>
136 148 <td class="code">
137 149 <pre>try:
138 150 </pre>
139 151 </td>
140 152 </tr>
141 153 <tr class="line unmod">
142 154 <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td>
143 <td id="setuppy_o7" class="lineno old"><a href="#setuppy_o7">7</a></td>
144 <td id="setuppy_n7" class="lineno new"><a href="#setuppy_n7">7</a></td>
155 <td id="setuppy_o7" class="lineno old"><a href="#setuppy_o7" class="tooltip"
156 title="Click to select line">7</a></td>
157 <td id="setuppy_n7" class="lineno new"><a href="#setuppy_n7" class="tooltip"
158 title="Click to select line">7</a></td>
145 159 <td class="code">
146 160 <pre> from setuptools import setup, Extension
147 161 </pre>
148 162 </td>
149 163 </tr>
150 164 <tr class="line unmod">
151 165 <td class="add-comment-line"><span class="add-comment-content"><a href="#"><span class="icon-comment-add"></span></a></span></td>
152 <td id="setuppy_o8" class="lineno old"><a href="#setuppy_o8">8</a></td>
153 <td id="setuppy_n8" class="lineno new"><a href="#setuppy_n8">8</a></td>
166 <td id="setuppy_o8" class="lineno old"><a href="#setuppy_o8" class="tooltip"
167 title="Click to select line">8</a></td>
168 <td id="setuppy_n8" class="lineno new"><a href="#setuppy_n8" class="tooltip"
169 title="Click to select line">8</a></td>
154 170 <td class="code">
155 171 <pre>except ImportError:
156 172 </pre>
157 173 </td>
158 174 </tr>
159 175 </table>
160 176 ''').strip()
161 177 html = processor.as_html(enable_comments=True).replace('\t', ' ')
162 178
163 179 assert html == expected_html
164 180
165 181
166 182 class TestMixedFilenameEncodings:
167 183
168 184 @pytest.fixture(scope="class")
169 185 def raw_diff(self):
170 186 return fixture.load_resource(
171 187 'hg_diff_mixed_filename_encodings.diff')
172 188
173 189 @pytest.fixture
174 190 def processor(self, raw_diff):
175 191 diff = MercurialDiff(raw_diff)
176 192 processor = DiffProcessor(diff)
177 193 return processor
178 194
179 195 def test_filenames_are_decoded_to_unicode(self, processor):
180 196 diff_data = processor.prepare()
181 197 filenames = [item['filename'] for item in diff_data]
182 198 assert filenames == [
183 199 u'spΓ€cial-utf8.txt', u'spοΏ½cial-cp1252.txt', u'spοΏ½cial-latin1.txt']
184 200
185 201 def test_raw_diff_is_decoded_to_unicode(self, processor):
186 202 diff_data = processor.prepare()
187 203 raw_diffs = [item['raw_diff'] for item in diff_data]
188 204 new_file_message = u'\nnew file mode 100644\n'
189 205 expected_raw_diffs = [
190 206 u' a/spΓ€cial-utf8.txt b/spΓ€cial-utf8.txt' + new_file_message,
191 207 u' a/spοΏ½cial-cp1252.txt b/spοΏ½cial-cp1252.txt' + new_file_message,
192 208 u' a/spοΏ½cial-latin1.txt b/spοΏ½cial-latin1.txt' + new_file_message]
193 209 assert raw_diffs == expected_raw_diffs
194 210
195 211 def test_as_raw_preserves_the_encoding(self, processor, raw_diff):
196 212 assert processor.as_raw() == raw_diff
197 213
198 214
199 215 # TODO: mikhail: format the following data structure properly
200 216 DIFF_FIXTURES = [
201 217 ('hg',
202 218 'hg_diff_add_single_binary_file.diff',
203 219 [('US Warszawa.jpg', 'A',
204 220 {'added': 0,
205 221 'deleted': 0,
206 222 'binary': True,
207 223 'ops': {NEW_FILENODE: 'new file 100755',
208 224 BIN_FILENODE: 'binary diff hidden'}}),
209 225 ]),
210 226 ('hg',
211 227 'hg_diff_mod_single_binary_file.diff',
212 228 [('US Warszawa.jpg', 'M',
213 229 {'added': 0,
214 230 'deleted': 0,
215 231 'binary': True,
216 232 'ops': {MOD_FILENODE: 'modified file',
217 233 BIN_FILENODE: 'binary diff hidden'}}),
218 234 ]),
219 235 ('hg',
220 236 'hg_diff_mod_single_file_and_rename_and_chmod.diff',
221 237 [('README', 'M',
222 238 {'added': 3,
223 239 'deleted': 0,
224 240 'binary': False,
225 241 'ops': {MOD_FILENODE: 'modified file',
226 242 RENAMED_FILENODE: 'file renamed from README.rst to README',
227 243 CHMOD_FILENODE: 'modified file chmod 100755 => 100644'}}),
228 244 ]),
229 245 ('hg',
230 246 'hg_diff_mod_file_and_rename.diff',
231 247 [('README.rst', 'M',
232 248 {'added': 3,
233 249 'deleted': 0,
234 250 'binary': False,
235 251 'ops': {MOD_FILENODE: 'modified file',
236 252 RENAMED_FILENODE: 'file renamed from README to README.rst'}}),
237 253 ]),
238 254 ('hg',
239 255 'hg_diff_del_single_binary_file.diff',
240 256 [('US Warszawa.jpg', 'D',
241 257 {'added': 0,
242 258 'deleted': 0,
243 259 'binary': True,
244 260 'ops': {DEL_FILENODE: 'deleted file',
245 261 BIN_FILENODE: 'binary diff hidden'}}),
246 262 ]),
247 263 ('hg',
248 264 'hg_diff_chmod_and_mod_single_binary_file.diff',
249 265 [('gravatar.png', 'M',
250 266 {'added': 0,
251 267 'deleted': 0,
252 268 'binary': True,
253 269 'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755',
254 270 BIN_FILENODE: 'binary diff hidden'}}),
255 271 ]),
256 272 ('hg',
257 273 'hg_diff_chmod.diff',
258 274 [('file', 'M',
259 275 {'added': 0,
260 276 'deleted': 0,
261 277 'binary': True,
262 278 'ops': {CHMOD_FILENODE: 'modified file chmod 100755 => 100644'}}),
263 279 ]),
264 280 ('hg',
265 281 'hg_diff_rename_file.diff',
266 282 [('file_renamed', 'M',
267 283 {'added': 0,
268 284 'deleted': 0,
269 285 'binary': True,
270 286 'ops': {RENAMED_FILENODE: 'file renamed from file to file_renamed'}}),
271 287 ]),
272 288 ('hg',
273 289 'hg_diff_rename_and_chmod_file.diff',
274 290 [('README', 'M',
275 291 {'added': 0,
276 292 'deleted': 0,
277 293 'binary': True,
278 294 'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755',
279 295 RENAMED_FILENODE: 'file renamed from README.rst to README'}}),
280 296 ]),
281 297 ('hg',
282 298 'hg_diff_binary_and_normal.diff',
283 299 [('img/baseline-10px.png', 'A',
284 300 {'added': 0,
285 301 'deleted': 0,
286 302 'binary': True,
287 303 'ops': {NEW_FILENODE: 'new file 100644',
288 304 BIN_FILENODE: 'binary diff hidden'}}),
289 305 ('js/jquery/hashgrid.js', 'A',
290 306 {'added': 340,
291 307 'deleted': 0,
292 308 'binary': False,
293 309 'ops': {NEW_FILENODE: 'new file 100755'}}),
294 310 ('index.html', 'M',
295 311 {'added': 3,
296 312 'deleted': 2,
297 313 'binary': False,
298 314 'ops': {MOD_FILENODE: 'modified file'}}),
299 315 ('less/docs.less', 'M',
300 316 {'added': 34,
301 317 'deleted': 0,
302 318 'binary': False,
303 319 'ops': {MOD_FILENODE: 'modified file'}}),
304 320 ('less/scaffolding.less', 'M',
305 321 {'added': 1,
306 322 'deleted': 3,
307 323 'binary': False,
308 324 'ops': {MOD_FILENODE: 'modified file'}}),
309 325 ('readme.markdown', 'M',
310 326 {'added': 1,
311 327 'deleted': 10,
312 328 'binary': False,
313 329 'ops': {MOD_FILENODE: 'modified file'}}),
314 330 ('img/baseline-20px.png', 'D',
315 331 {'added': 0,
316 332 'deleted': 0,
317 333 'binary': True,
318 334 'ops': {DEL_FILENODE: 'deleted file',
319 335 BIN_FILENODE: 'binary diff hidden'}}),
320 336 ('js/global.js', 'D',
321 337 {'added': 0,
322 338 'deleted': 75,
323 339 'binary': False,
324 340 'ops': {DEL_FILENODE: 'deleted file'}})
325 341 ]),
326 342 ('git',
327 343 'git_diff_chmod.diff',
328 344 [('work-horus.xls', 'M',
329 345 {'added': 0,
330 346 'deleted': 0,
331 347 'binary': True,
332 348 'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755'}})
333 349 ]),
334 350 ('git',
335 351 'git_diff_rename_file.diff',
336 352 [('file.xls', 'M',
337 353 {'added': 0,
338 354 'deleted': 0,
339 355 'binary': True,
340 356 'ops': {
341 357 RENAMED_FILENODE: 'file renamed from work-horus.xls to file.xls'}})
342 358 ]),
343 359 ('git',
344 360 'git_diff_mod_single_binary_file.diff',
345 361 [('US Warszawa.jpg', 'M',
346 362 {'added': 0,
347 363 'deleted': 0,
348 364 'binary': True,
349 365 'ops': {MOD_FILENODE: 'modified file',
350 366 BIN_FILENODE: 'binary diff hidden'}})
351 367 ]),
352 368 ('git',
353 369 'git_diff_binary_and_normal.diff',
354 370 [('img/baseline-10px.png', 'A',
355 371 {'added': 0,
356 372 'deleted': 0,
357 373 'binary': True,
358 374 'ops': {NEW_FILENODE: 'new file 100644',
359 375 BIN_FILENODE: 'binary diff hidden'}}),
360 376 ('js/jquery/hashgrid.js', 'A',
361 377 {'added': 340,
362 378 'deleted': 0,
363 379 'binary': False,
364 380 'ops': {NEW_FILENODE: 'new file 100755'}}),
365 381 ('index.html', 'M',
366 382 {'added': 3,
367 383 'deleted': 2,
368 384 'binary': False,
369 385 'ops': {MOD_FILENODE: 'modified file'}}),
370 386 ('less/docs.less', 'M',
371 387 {'added': 34,
372 388 'deleted': 0,
373 389 'binary': False,
374 390 'ops': {MOD_FILENODE: 'modified file'}}),
375 391 ('less/scaffolding.less', 'M',
376 392 {'added': 1,
377 393 'deleted': 3,
378 394 'binary': False,
379 395 'ops': {MOD_FILENODE: 'modified file'}}),
380 396 ('readme.markdown', 'M',
381 397 {'added': 1,
382 398 'deleted': 10,
383 399 'binary': False,
384 400 'ops': {MOD_FILENODE: 'modified file'}}),
385 401 ('img/baseline-20px.png', 'D',
386 402 {'added': 0,
387 403 'deleted': 0,
388 404 'binary': True,
389 405 'ops': {DEL_FILENODE: 'deleted file',
390 406 BIN_FILENODE: 'binary diff hidden'}}),
391 407 ('js/global.js', 'D',
392 408 {'added': 0,
393 409 'deleted': 75,
394 410 'binary': False,
395 411 'ops': {DEL_FILENODE: 'deleted file'}}),
396 412 ]),
397 413 ('hg',
398 414 'diff_with_diff_data.diff',
399 415 [('vcs/backends/base.py', 'M',
400 416 {'added': 18,
401 417 'deleted': 2,
402 418 'binary': False,
403 419 'ops': {MOD_FILENODE: 'modified file'}}),
404 420 ('vcs/backends/git/repository.py', 'M',
405 421 {'added': 46,
406 422 'deleted': 15,
407 423 'binary': False,
408 424 'ops': {MOD_FILENODE: 'modified file'}}),
409 425 ('vcs/backends/hg.py', 'M',
410 426 {'added': 22,
411 427 'deleted': 3,
412 428 'binary': False,
413 429 'ops': {MOD_FILENODE: 'modified file'}}),
414 430 ('vcs/tests/test_git.py', 'M',
415 431 {'added': 5,
416 432 'deleted': 5,
417 433 'binary': False,
418 434 'ops': {MOD_FILENODE: 'modified file'}}),
419 435 ('vcs/tests/test_repository.py', 'M',
420 436 {'added': 174,
421 437 'deleted': 2,
422 438 'binary': False,
423 439 'ops': {MOD_FILENODE: 'modified file'}}),
424 440 ]),
425 441 ('hg',
426 442 'hg_diff_copy_file.diff',
427 443 [('file2', 'M',
428 444 {'added': 0,
429 445 'deleted': 0,
430 446 'binary': True,
431 447 'ops': {COPIED_FILENODE: 'file copied from file1 to file2'}}),
432 448 ]),
433 449 ('hg',
434 450 'hg_diff_copy_and_modify_file.diff',
435 451 [('file3', 'M',
436 452 {'added': 1,
437 453 'deleted': 0,
438 454 'binary': False,
439 455 'ops': {COPIED_FILENODE: 'file copied from file2 to file3',
440 456 MOD_FILENODE: 'modified file'}}),
441 457 ]),
442 458 ('hg',
443 459 'hg_diff_copy_and_chmod_file.diff',
444 460 [('file4', 'M',
445 461 {'added': 0,
446 462 'deleted': 0,
447 463 'binary': True,
448 464 'ops': {COPIED_FILENODE: 'file copied from file3 to file4',
449 465 CHMOD_FILENODE: 'modified file chmod 100644 => 100755'}}),
450 466 ]),
451 467 ('hg',
452 468 'hg_diff_copy_chmod_and_edit_file.diff',
453 469 [('file5', 'M',
454 470 {'added': 2,
455 471 'deleted': 1,
456 472 'binary': False,
457 473 'ops': {COPIED_FILENODE: 'file copied from file4 to file5',
458 474 CHMOD_FILENODE: 'modified file chmod 100755 => 100644',
459 475 MOD_FILENODE: 'modified file'}})]),
460 476
461 477 # Diffs to validate rename and copy file with space in its name
462 478 ('git',
463 479 'git_diff_rename_file_with_spaces.diff',
464 480 [('file_with_ two spaces.txt', 'M',
465 481 {'added': 0,
466 482 'deleted': 0,
467 483 'binary': True,
468 484 'ops': {
469 485 RENAMED_FILENODE: (
470 486 'file renamed from file_with_ spaces.txt to file_with_ '
471 487 ' two spaces.txt')}
472 488 }), ]),
473 489 ('hg',
474 490 'hg_diff_rename_file_with_spaces.diff',
475 491 [('file_changed _.txt', 'M',
476 492 {'added': 0,
477 493 'deleted': 0,
478 494 'binary': True,
479 495 'ops': {
480 496 RENAMED_FILENODE: (
481 497 'file renamed from file_ with update.txt to file_changed'
482 498 ' _.txt')}
483 499 }), ]),
484 500 ('hg',
485 501 'hg_diff_copy_file_with_spaces.diff',
486 502 [('file_copied_ with spaces.txt', 'M',
487 503 {'added': 0,
488 504 'deleted': 0,
489 505 'binary': True,
490 506 'ops': {
491 507 COPIED_FILENODE: (
492 508 'file copied from file_changed_without_spaces.txt to'
493 509 ' file_copied_ with spaces.txt')}
494 510 }),
495 511 ]),
496 512
497 513 # special signs from git
498 514 ('git',
499 515 'git_diff_binary_special_files.diff',
500 516 [('css/_Icon\\r', 'A',
501 517 {'added': 0,
502 518 'deleted': 0,
503 519 'binary': True,
504 520 'ops': {NEW_FILENODE: 'new file 100644',
505 521 BIN_FILENODE: 'binary diff hidden'}
506 522 }),
507 523 ]),
508 524 ('git',
509 525 'git_diff_binary_special_files_2.diff',
510 526 [('css/Icon\\r', 'A',
511 527 {'added': 0,
512 528 'deleted': 0,
513 529 'binary': True,
514 530 'ops': {NEW_FILENODE: 'new file 100644', }
515 531 }),
516 532 ]),
517 533
518 534 # TODO: mikhail: do we still need this?
519 535 # (
520 536 # 'hg',
521 537 # 'large_diff.diff',
522 538 # [
523 539 # ('.hgignore', 'A', {
524 540 # 'deleted': 0, 'binary': False, 'added': 3, 'ops': {
525 541 # 1: 'new file 100644'}}),
526 542 # (
527 543 # 'MANIFEST.in', 'A',
528 544 # {'deleted': 0, 'binary': False, 'added': 3, 'ops': {
529 545 # 1: 'new file 100644'}}),
530 546 # (
531 547 # 'README.txt', 'A',
532 548 # {'deleted': 0, 'binary': False, 'added': 19, 'ops': {
533 549 # 1: 'new file 100644'}}),
534 550 # (
535 551 # 'development.ini', 'A', {
536 552 # 'deleted': 0, 'binary': False, 'added': 116, 'ops': {
537 553 # 1: 'new file 100644'}}),
538 554 # (
539 555 # 'docs/index.txt', 'A', {
540 556 # 'deleted': 0, 'binary': False, 'added': 19, 'ops': {
541 557 # 1: 'new file 100644'}}),
542 558 # (
543 559 # 'ez_setup.py', 'A', {
544 560 # 'deleted': 0, 'binary': False, 'added': 276, 'ops': {
545 561 # 1: 'new file 100644'}}),
546 562 # (
547 563 # 'hgapp.py', 'A', {
548 564 # 'deleted': 0, 'binary': False, 'added': 26, 'ops': {
549 565 # 1: 'new file 100644'}}),
550 566 # (
551 567 # 'hgwebdir.config', 'A', {
552 568 # 'deleted': 0, 'binary': False, 'added': 21, 'ops': {
553 569 # 1: 'new file 100644'}}),
554 570 # (
555 571 # 'pylons_app.egg-info/PKG-INFO', 'A', {
556 572 # 'deleted': 0, 'binary': False, 'added': 10, 'ops': {
557 573 # 1: 'new file 100644'}}),
558 574 # (
559 575 # 'pylons_app.egg-info/SOURCES.txt', 'A', {
560 576 # 'deleted': 0, 'binary': False, 'added': 33, 'ops': {
561 577 # 1: 'new file 100644'}}),
562 578 # (
563 579 # 'pylons_app.egg-info/dependency_links.txt', 'A', {
564 580 # 'deleted': 0, 'binary': False, 'added': 1, 'ops': {
565 581 # 1: 'new file 100644'}}),
566 582 # #TODO:
567 583 # ]
568 584 # ),
569 585 ]
570 586
571 587 DIFF_FIXTURES_WITH_CONTENT = [
572 588 (
573 589 'hg', 'hg_diff_single_file_change_newline.diff',
574 590 [
575 591 (
576 592 'file_b', # filename
577 593 'A', # change
578 594 { # stats
579 595 'added': 1,
580 596 'deleted': 0,
581 597 'binary': False,
582 598 'ops': {NEW_FILENODE: 'new file 100644', }
583 599 },
584 600 '@@ -0,0 +1 @@\n+test_content b\n' # diff
585 601 ),
586 602 ],
587 603 ),
588 604 (
589 605 'hg', 'hg_diff_double_file_change_newline.diff',
590 606 [
591 607 (
592 608 'file_b', # filename
593 609 'A', # change
594 610 { # stats
595 611 'added': 1,
596 612 'deleted': 0,
597 613 'binary': False,
598 614 'ops': {NEW_FILENODE: 'new file 100644', }
599 615 },
600 616 '@@ -0,0 +1 @@\n+test_content b\n' # diff
601 617 ),
602 618 (
603 619 'file_c', # filename
604 620 'A', # change
605 621 { # stats
606 622 'added': 1,
607 623 'deleted': 0,
608 624 'binary': False,
609 625 'ops': {NEW_FILENODE: 'new file 100644', }
610 626 },
611 627 '@@ -0,0 +1 @@\n+test_content c\n' # diff
612 628 ),
613 629 ],
614 630 ),
615 631 (
616 632 'hg', 'hg_diff_double_file_change_double_newline.diff',
617 633 [
618 634 (
619 635 'file_b', # filename
620 636 'A', # change
621 637 { # stats
622 638 'added': 1,
623 639 'deleted': 0,
624 640 'binary': False,
625 641 'ops': {NEW_FILENODE: 'new file 100644', }
626 642 },
627 643 '@@ -0,0 +1 @@\n+test_content b\n\n' # diff
628 644 ),
629 645 (
630 646 'file_c', # filename
631 647 'A', # change
632 648 { # stats
633 649 'added': 1,
634 650 'deleted': 0,
635 651 'binary': False,
636 652 'ops': {NEW_FILENODE: 'new file 100644', }
637 653 },
638 654 '@@ -0,0 +1 @@\n+test_content c\n' # diff
639 655 ),
640 656 ],
641 657 ),
642 658 (
643 659 'hg', 'hg_diff_four_file_change_newline.diff',
644 660 [
645 661 (
646 662 'file', # filename
647 663 'A', # change
648 664 { # stats
649 665 'added': 1,
650 666 'deleted': 0,
651 667 'binary': False,
652 668 'ops': {NEW_FILENODE: 'new file 100644', }
653 669 },
654 670 '@@ -0,0 +1,1 @@\n+file\n' # diff
655 671 ),
656 672 (
657 673 'file2', # filename
658 674 'A', # change
659 675 { # stats
660 676 'added': 1,
661 677 'deleted': 0,
662 678 'binary': False,
663 679 'ops': {NEW_FILENODE: 'new file 100644', }
664 680 },
665 681 '@@ -0,0 +1,1 @@\n+another line\n' # diff
666 682 ),
667 683 (
668 684 'file3', # filename
669 685 'A', # change
670 686 { # stats
671 687 'added': 1,
672 688 'deleted': 0,
673 689 'binary': False,
674 690 'ops': {NEW_FILENODE: 'new file 100644', }
675 691 },
676 692 '@@ -0,0 +1,1 @@\n+newline\n' # diff
677 693 ),
678 694 (
679 695 'file4', # filename
680 696 'A', # change
681 697 { # stats
682 698 'added': 1,
683 699 'deleted': 0,
684 700 'binary': False,
685 701 'ops': {NEW_FILENODE: 'new file 100644', }
686 702 },
687 703 '@@ -0,0 +1,1 @@\n+fil4\n\\ No newline at end of file' # diff
688 704 ),
689 705 ],
690 706 ),
691 707
692 708 ]
693 709
694 710
695 711 diff_class = {
696 712 'git': GitDiff,
697 713 'hg': MercurialDiff,
698 714 'svn': SubversionDiff,
699 715 }
700 716
701 717
702 718 @pytest.fixture(params=DIFF_FIXTURES)
703 719 def diff_fixture(request):
704 720 vcs, diff_fixture, expected = request.param
705 721 diff_txt = fixture.load_resource(diff_fixture)
706 722 diff = diff_class[vcs](diff_txt)
707 723 return diff, expected
708 724
709 725
710 726 def test_diff_lib(diff_fixture):
711 727 diff, expected_data = diff_fixture
712 728 diff_proc = DiffProcessor(diff)
713 729 diff_proc_d = diff_proc.prepare()
714 730 data = [(x['filename'], x['operation'], x['stats']) for x in diff_proc_d]
715 731 assert expected_data == data
716 732
717 733
718 734 @pytest.fixture(params=DIFF_FIXTURES_WITH_CONTENT)
719 735 def diff_fixture_w_content(request):
720 736 vcs, diff_fixture, expected = request.param
721 737 diff_txt = fixture.load_resource(diff_fixture)
722 738 diff = diff_class[vcs](diff_txt)
723 739 return diff, expected
724 740
725 741
726 742 def test_diff_lib_newlines(diff_fixture_w_content):
727 743 diff, expected_data = diff_fixture_w_content
728 744 diff_proc = DiffProcessor(diff)
729 745 diff_proc_d = diff_proc.prepare()
730 746 data = [(x['filename'], x['operation'], x['stats'], x['raw_diff'])
731 747 for x in diff_proc_d]
732 748 assert expected_data == data
General Comments 0
You need to be logged in to leave comments. Login now