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