|
@@
-1,257
+1,282
b''
|
|
1
|
1
|
from __future__ import with_statement
|
|
2
|
2
|
import os
|
|
3
|
3
|
from rhodecode.tests import *
|
|
4
|
4
|
from rhodecode.lib.diffs import DiffProcessor, NEW_FILENODE, DEL_FILENODE, \
|
|
5
|
5
|
MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE, COPIED_FILENODE
|
|
6
|
6
|
|
|
7
|
7
|
dn = os.path.dirname
|
|
8
|
8
|
FIXTURES = os.path.join(dn(dn(os.path.abspath(__file__))), 'fixtures')
|
|
9
|
9
|
|
|
10
|
10
|
DIFF_FIXTURES = {
|
|
11
|
11
|
'hg_diff_add_single_binary_file.diff': [
|
|
12
|
12
|
('US Warszawa.jpg', 'A',
|
|
13
|
13
|
{'added': 0,
|
|
14
|
14
|
'deleted': 0,
|
|
15
|
15
|
'binary': True,
|
|
16
|
16
|
'ops': {NEW_FILENODE: 'new file 100755',
|
|
17
|
17
|
BIN_FILENODE: 'binary diff not shown'}}),
|
|
18
|
18
|
],
|
|
19
|
19
|
'hg_diff_mod_single_binary_file.diff': [
|
|
20
|
20
|
('US Warszawa.jpg', 'M',
|
|
21
|
21
|
{'added': 0,
|
|
22
|
22
|
'deleted': 0,
|
|
23
|
23
|
'binary': True,
|
|
24
|
24
|
'ops': {MOD_FILENODE: 'modified file',
|
|
25
|
25
|
BIN_FILENODE: 'binary diff not shown'}}),
|
|
26
|
26
|
],
|
|
27
|
27
|
|
|
28
|
28
|
'hg_diff_mod_single_file_and_rename_and_chmod.diff': [
|
|
29
|
29
|
('README', 'M',
|
|
30
|
30
|
{'added': 3,
|
|
31
|
31
|
'deleted': 0,
|
|
32
|
32
|
'binary': False,
|
|
33
|
33
|
'ops': {MOD_FILENODE: 'modified file',
|
|
34
|
34
|
RENAMED_FILENODE: 'file renamed from README.rst to README',
|
|
35
|
35
|
CHMOD_FILENODE: 'modified file chmod 100755 => 100644'}}),
|
|
36
|
36
|
],
|
|
37
|
37
|
'hg_diff_mod_file_and_rename.diff': [
|
|
38
|
38
|
('README.rst', 'M',
|
|
39
|
39
|
{'added': 3,
|
|
40
|
40
|
'deleted': 0,
|
|
41
|
41
|
'binary': False,
|
|
42
|
42
|
'ops': {MOD_FILENODE: 'modified file',
|
|
43
|
43
|
RENAMED_FILENODE: 'file renamed from README to README.rst'}}),
|
|
44
|
44
|
],
|
|
45
|
45
|
'hg_diff_del_single_binary_file.diff': [
|
|
46
|
46
|
('US Warszawa.jpg', 'D',
|
|
47
|
47
|
{'added': 0,
|
|
48
|
48
|
'deleted': 0,
|
|
49
|
49
|
'binary': True,
|
|
50
|
50
|
'ops': {DEL_FILENODE: 'deleted file',
|
|
51
|
51
|
BIN_FILENODE: 'binary diff not shown'}}),
|
|
52
|
52
|
],
|
|
53
|
53
|
'hg_diff_chmod_and_mod_single_binary_file.diff': [
|
|
54
|
54
|
('gravatar.png', 'M',
|
|
55
|
55
|
{'added': 0,
|
|
56
|
56
|
'deleted': 0,
|
|
57
|
57
|
'binary': True,
|
|
58
|
58
|
'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755',
|
|
59
|
59
|
BIN_FILENODE: 'binary diff not shown'}}),
|
|
60
|
60
|
],
|
|
61
|
61
|
'hg_diff_chmod.diff': [
|
|
62
|
62
|
('file', 'M',
|
|
63
|
63
|
{'added': 0,
|
|
64
|
64
|
'deleted': 0,
|
|
65
|
65
|
'binary': True,
|
|
66
|
66
|
'ops': {CHMOD_FILENODE: 'modified file chmod 100755 => 100644'}}),
|
|
67
|
67
|
],
|
|
68
|
68
|
'hg_diff_rename_file.diff': [
|
|
69
|
69
|
('file_renamed', 'M',
|
|
70
|
70
|
{'added': 0,
|
|
71
|
71
|
'deleted': 0,
|
|
72
|
72
|
'binary': True,
|
|
73
|
73
|
'ops': {RENAMED_FILENODE: 'file renamed from file to file_renamed'}}),
|
|
74
|
74
|
],
|
|
75
|
75
|
'hg_diff_rename_and_chmod_file.diff': [
|
|
76
|
76
|
('README', 'M',
|
|
77
|
77
|
{'added': 0,
|
|
78
|
78
|
'deleted': 0,
|
|
79
|
79
|
'binary': True,
|
|
80
|
80
|
'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755',
|
|
81
|
81
|
RENAMED_FILENODE: 'file renamed from README.rst to README'}}),
|
|
82
|
82
|
],
|
|
83
|
83
|
'hg_diff_binary_and_normal.diff': [
|
|
84
|
84
|
('img/baseline-10px.png', 'A',
|
|
85
|
85
|
{'added': 0,
|
|
86
|
86
|
'deleted': 0,
|
|
87
|
87
|
'binary': True,
|
|
88
|
88
|
'ops': {NEW_FILENODE: 'new file 100644',
|
|
89
|
89
|
BIN_FILENODE: 'binary diff not shown'}}),
|
|
90
|
90
|
('js/jquery/hashgrid.js', 'A',
|
|
91
|
91
|
{'added': 340,
|
|
92
|
92
|
'deleted': 0,
|
|
93
|
93
|
'binary': False,
|
|
94
|
94
|
'ops': {NEW_FILENODE: 'new file 100755'}}),
|
|
95
|
95
|
('index.html', 'M',
|
|
96
|
96
|
{'added': 3,
|
|
97
|
97
|
'deleted': 2,
|
|
98
|
98
|
'binary': False,
|
|
99
|
99
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
100
|
100
|
('less/docs.less', 'M',
|
|
101
|
101
|
{'added': 34,
|
|
102
|
102
|
'deleted': 0,
|
|
103
|
103
|
'binary': False,
|
|
104
|
104
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
105
|
105
|
('less/scaffolding.less', 'M',
|
|
106
|
106
|
{'added': 1,
|
|
107
|
107
|
'deleted': 3,
|
|
108
|
108
|
'binary': False,
|
|
109
|
109
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
110
|
110
|
('readme.markdown', 'M',
|
|
111
|
111
|
{'added': 1,
|
|
112
|
112
|
'deleted': 10,
|
|
113
|
113
|
'binary': False,
|
|
114
|
114
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
115
|
115
|
('img/baseline-20px.png', 'D',
|
|
116
|
116
|
{'added': 0,
|
|
117
|
117
|
'deleted': 0,
|
|
118
|
118
|
'binary': True,
|
|
119
|
119
|
'ops': {DEL_FILENODE: 'deleted file',
|
|
120
|
120
|
BIN_FILENODE: 'binary diff not shown'}}),
|
|
121
|
121
|
('js/global.js', 'D',
|
|
122
|
122
|
{'added': 0,
|
|
123
|
123
|
'deleted': 75,
|
|
124
|
124
|
'binary': False,
|
|
125
|
125
|
'ops': {DEL_FILENODE: 'deleted file'}})
|
|
126
|
126
|
],
|
|
127
|
127
|
'git_diff_chmod.diff': [
|
|
128
|
128
|
('work-horus.xls', 'M',
|
|
129
|
129
|
{'added': 0,
|
|
130
|
130
|
'deleted': 0,
|
|
131
|
131
|
'binary': True,
|
|
132
|
132
|
'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755'}})
|
|
133
|
133
|
],
|
|
134
|
134
|
'git_diff_rename_file.diff': [
|
|
135
|
135
|
('file.xls', 'M',
|
|
136
|
136
|
{'added': 0,
|
|
137
|
137
|
'deleted': 0,
|
|
138
|
138
|
'binary': True,
|
|
139
|
139
|
'ops': {RENAMED_FILENODE: 'file renamed from work-horus.xls to file.xls'}})
|
|
140
|
140
|
],
|
|
141
|
141
|
'git_diff_mod_single_binary_file.diff': [
|
|
142
|
142
|
('US Warszawa.jpg', 'M',
|
|
143
|
143
|
{'added': 0,
|
|
144
|
144
|
'deleted': 0,
|
|
145
|
145
|
'binary': True,
|
|
146
|
146
|
'ops': {MOD_FILENODE: 'modified file',
|
|
147
|
147
|
BIN_FILENODE: 'binary diff not shown'}})
|
|
148
|
148
|
],
|
|
149
|
149
|
'git_diff_binary_and_normal.diff': [
|
|
150
|
150
|
('img/baseline-10px.png', 'A',
|
|
151
|
151
|
{'added': 0,
|
|
152
|
152
|
'deleted': 0,
|
|
153
|
153
|
'binary': True,
|
|
154
|
154
|
'ops': {NEW_FILENODE: 'new file 100644',
|
|
155
|
155
|
BIN_FILENODE: 'binary diff not shown'}}),
|
|
156
|
156
|
('js/jquery/hashgrid.js', 'A',
|
|
157
|
157
|
{'added': 340,
|
|
158
|
158
|
'deleted': 0,
|
|
159
|
159
|
'binary': False,
|
|
160
|
160
|
'ops': {NEW_FILENODE: 'new file 100755'}}),
|
|
161
|
161
|
('index.html', 'M',
|
|
162
|
162
|
{'added': 3,
|
|
163
|
163
|
'deleted': 2,
|
|
164
|
164
|
'binary': False,
|
|
165
|
165
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
166
|
166
|
('less/docs.less', 'M',
|
|
167
|
167
|
{'added': 34,
|
|
168
|
168
|
'deleted': 0,
|
|
169
|
169
|
'binary': False,
|
|
170
|
170
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
171
|
171
|
('less/scaffolding.less', 'M',
|
|
172
|
172
|
{'added': 1,
|
|
173
|
173
|
'deleted': 3,
|
|
174
|
174
|
'binary': False,
|
|
175
|
175
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
176
|
176
|
('readme.markdown', 'M',
|
|
177
|
177
|
{'added': 1,
|
|
178
|
178
|
'deleted': 10,
|
|
179
|
179
|
'binary': False,
|
|
180
|
180
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
181
|
181
|
('img/baseline-20px.png', 'D',
|
|
182
|
182
|
{'added': 0,
|
|
183
|
183
|
'deleted': 0,
|
|
184
|
184
|
'binary': True,
|
|
185
|
185
|
'ops': {DEL_FILENODE: 'deleted file',
|
|
186
|
186
|
BIN_FILENODE: 'binary diff not shown'}}),
|
|
187
|
187
|
('js/global.js', 'D',
|
|
188
|
188
|
{'added': 0,
|
|
189
|
189
|
'deleted': 75,
|
|
190
|
190
|
'binary': False,
|
|
191
|
191
|
'ops': {DEL_FILENODE: 'deleted file'}}),
|
|
192
|
192
|
],
|
|
193
|
193
|
'diff_with_diff_data.diff': [
|
|
194
|
194
|
('vcs/backends/base.py', 'M',
|
|
195
|
195
|
{'added': 18,
|
|
196
|
196
|
'deleted': 2,
|
|
197
|
197
|
'binary': False,
|
|
198
|
198
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
199
|
199
|
('vcs/backends/git/repository.py', 'M',
|
|
200
|
200
|
{'added': 46,
|
|
201
|
201
|
'deleted': 15,
|
|
202
|
202
|
'binary': False,
|
|
203
|
203
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
204
|
204
|
('vcs/backends/hg.py', 'M',
|
|
205
|
205
|
{'added': 22,
|
|
206
|
206
|
'deleted': 3,
|
|
207
|
207
|
'binary': False,
|
|
208
|
208
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
209
|
209
|
('vcs/tests/test_git.py', 'M',
|
|
210
|
210
|
{'added': 5,
|
|
211
|
211
|
'deleted': 5,
|
|
212
|
212
|
'binary': False,
|
|
213
|
213
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
214
|
214
|
('vcs/tests/test_repository.py', 'M',
|
|
215
|
215
|
{'added': 174,
|
|
216
|
216
|
'deleted': 2,
|
|
217
|
217
|
'binary': False,
|
|
218
|
218
|
'ops': {MOD_FILENODE: 'modified file'}}),
|
|
219
|
219
|
],
|
|
220
|
220
|
'hg_diff_copy_file.diff': [
|
|
221
|
221
|
('file2', 'M',
|
|
222
|
222
|
{'added': 0,
|
|
223
|
223
|
'deleted': 0,
|
|
224
|
224
|
'binary': True,
|
|
225
|
225
|
'ops': {COPIED_FILENODE: 'file copied from file1 to file2'}}),
|
|
|
226
|
],
|
|
|
227
|
'hg_diff_copy_and_modify_file.diff': [
|
|
|
228
|
('file3', 'M',
|
|
|
229
|
{'added': 1,
|
|
|
230
|
'deleted': 0,
|
|
|
231
|
'binary': False,
|
|
|
232
|
'ops': {COPIED_FILENODE: 'file copied from file2 to file3',
|
|
|
233
|
MOD_FILENODE: 'modified file'}}),
|
|
|
234
|
],
|
|
|
235
|
'hg_diff_copy_and_chmod_file.diff': [
|
|
|
236
|
('file4', 'M',
|
|
|
237
|
{'added': 0,
|
|
|
238
|
'deleted': 0,
|
|
|
239
|
'binary': True,
|
|
|
240
|
'ops': {COPIED_FILENODE: 'file copied from file3 to file4',
|
|
|
241
|
CHMOD_FILENODE: 'modified file chmod 100644 => 100755'}}),
|
|
|
242
|
],
|
|
|
243
|
'hg_diff_copy_chmod_and_edit_file.diff': [
|
|
|
244
|
('file5', 'M',
|
|
|
245
|
{'added': 2,
|
|
|
246
|
'deleted': 1,
|
|
|
247
|
'binary': False,
|
|
|
248
|
'ops': {COPIED_FILENODE: 'file copied from file4 to file5',
|
|
|
249
|
CHMOD_FILENODE: 'modified file chmod 100755 => 100644',
|
|
|
250
|
MOD_FILENODE: 'modified file'}}),
|
|
226
|
251
|
]
|
|
227
|
252
|
# 'large_diff.diff': [
|
|
228
|
253
|
# ('.hgignore', 'A', {'deleted': 0, 'binary': False, 'added': 3, 'ops': {1: 'new file 100644'}}),
|
|
229
|
254
|
# ('MANIFEST.in', 'A', {'deleted': 0, 'binary': False, 'added': 3, 'ops': {1: 'new file 100644'}}),
|
|
230
|
255
|
# ('README.txt', 'A', {'deleted': 0, 'binary': False, 'added': 19, 'ops': {1: 'new file 100644'}}),
|
|
231
|
256
|
# ('development.ini', 'A', {'deleted': 0, 'binary': False, 'added': 116, 'ops': {1: 'new file 100644'}}),
|
|
232
|
257
|
# ('docs/index.txt', 'A', {'deleted': 0, 'binary': False, 'added': 19, 'ops': {1: 'new file 100644'}}),
|
|
233
|
258
|
# ('ez_setup.py', 'A', {'deleted': 0, 'binary': False, 'added': 276, 'ops': {1: 'new file 100644'}}),
|
|
234
|
259
|
# ('hgapp.py', 'A', {'deleted': 0, 'binary': False, 'added': 26, 'ops': {1: 'new file 100644'}}),
|
|
235
|
260
|
# ('hgwebdir.config', 'A', {'deleted': 0, 'binary': False, 'added': 21, 'ops': {1: 'new file 100644'}}),
|
|
236
|
261
|
# ('pylons_app.egg-info/PKG-INFO', 'A', {'deleted': 0, 'binary': False, 'added': 10, 'ops': {1: 'new file 100644'}}),
|
|
237
|
262
|
# ('pylons_app.egg-info/SOURCES.txt', 'A', {'deleted': 0, 'binary': False, 'added': 33, 'ops': {1: 'new file 100644'}}),
|
|
238
|
263
|
# ('pylons_app.egg-info/dependency_links.txt', 'A', {'deleted': 0, 'binary': False, 'added': 1, 'ops': {1: 'new file 100644'}}),
|
|
239
|
264
|
# #TODO:
|
|
240
|
265
|
# ],
|
|
241
|
266
|
|
|
242
|
267
|
}
|
|
243
|
268
|
|
|
244
|
269
|
|
|
245
|
270
|
class DiffLibTest(BaseTestCase):
|
|
246
|
271
|
|
|
247
|
272
|
@parameterized.expand([(x,) for x in DIFF_FIXTURES])
|
|
248
|
273
|
def test_diff(self, diff_fixture):
|
|
249
|
274
|
|
|
250
|
275
|
with open(os.path.join(FIXTURES, diff_fixture)) as f:
|
|
251
|
276
|
diff = f.read()
|
|
252
|
277
|
|
|
253
|
278
|
diff_proc = DiffProcessor(diff)
|
|
254
|
279
|
diff_proc_d = diff_proc.prepare()
|
|
255
|
280
|
data = [(x['filename'], x['operation'], x['stats']) for x in diff_proc_d]
|
|
256
|
281
|
expected_data = DIFF_FIXTURES[diff_fixture]
|
|
257
|
282
|
self.assertListEqual(expected_data, data)
|