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