Files
@ e527cc2ce8dc
Branch filter:
Location: kallithea/kallithea/tests/models/test_diff_parsers.py
e527cc2ce8dc
10.8 KiB
text/x-python
cleanup: get rid of most "import *"
Apply script generated with the following hack:
(
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(.*)' may be undefined, or defined from star imports.*/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.* undefined name '(.*)'$/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\\\\<XXXX\\\\.,\3.,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\2\\\\.\3 .*,\2 import \3,g' \1/gp" | sort -u
) | grep -v kallithea/bin/kallithea_cli_ishell.py > fix2.sh
Apply script generated with the following hack:
(
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(.*)' may be undefined, or defined from star imports.*/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.* undefined name '(.*)'$/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\\\\<XXXX\\\\.,\3.,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\2\\\\.\3 .*,\2 import \3,g' \1/gp" | sort -u
) | grep -v kallithea/bin/kallithea_cli_ishell.py > fix2.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | from kallithea.lib.diffs import BIN_FILENODE, CHMOD_FILENODE, COPIED_FILENODE, DEL_FILENODE, MOD_FILENODE, NEW_FILENODE, RENAMED_FILENODE, DiffProcessor
from kallithea.tests import base
from kallithea.tests.fixture import Fixture
fixture = Fixture()
DIFF_FIXTURES = {
'hg_diff_add_single_binary_file.diff': [
('US Warszawa.jpg', 'added',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {NEW_FILENODE: 'new file 100755',
BIN_FILENODE: 'binary diff not shown'}}),
],
'hg_diff_mod_single_binary_file.diff': [
('US Warszawa.jpg', 'modified',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {MOD_FILENODE: 'modified file',
BIN_FILENODE: 'binary diff not shown'}}),
],
'hg_diff_mod_single_file_and_rename_and_chmod.diff': [
('README', 'renamed',
{'added': 3,
'deleted': 0,
'binary': False,
'ops': {RENAMED_FILENODE: 'file renamed from README.rst to README',
CHMOD_FILENODE: 'modified file chmod 100755 => 100644'}}),
],
'hg_diff_mod_file_and_rename.diff': [
('README.rst', 'renamed',
{'added': 3,
'deleted': 0,
'binary': False,
'ops': {RENAMED_FILENODE: 'file renamed from README to README.rst'}}),
],
'hg_diff_del_single_binary_file.diff': [
('US Warszawa.jpg', 'removed',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {DEL_FILENODE: 'deleted file',
BIN_FILENODE: 'binary diff not shown'}}),
],
'hg_diff_chmod_and_mod_single_binary_file.diff': [
('gravatar.png', 'modified',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755',
BIN_FILENODE: 'binary diff not shown'}}),
],
'hg_diff_chmod.diff': [
('file', 'modified',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {CHMOD_FILENODE: 'modified file chmod 100755 => 100644'}}),
],
'hg_diff_rename_file.diff': [
('file_renamed', 'renamed',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {RENAMED_FILENODE: 'file renamed from file to file_renamed'}}),
],
'hg_diff_rename_and_chmod_file.diff': [
('README', 'renamed',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755',
RENAMED_FILENODE: 'file renamed from README.rst to README'}}),
],
'hg_diff_binary_and_normal.diff': [
('img/baseline-10px.png', 'added',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {NEW_FILENODE: 'new file 100644',
BIN_FILENODE: 'binary diff not shown'}}),
('img/baseline-20px.png', 'removed',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {DEL_FILENODE: 'deleted file',
BIN_FILENODE: 'binary diff not shown'}}),
('index.html', 'modified',
{'added': 3,
'deleted': 2,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('js/global.js', 'removed',
{'added': 0,
'deleted': 75,
'binary': False,
'ops': {DEL_FILENODE: 'deleted file'}}),
('js/jquery/hashgrid.js', 'added',
{'added': 340,
'deleted': 0,
'binary': False,
'ops': {NEW_FILENODE: 'new file 100755'}}),
('less/docs.less', 'modified',
{'added': 34,
'deleted': 0,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('less/scaffolding.less', 'modified',
{'added': 1,
'deleted': 3,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('readme.markdown', 'modified',
{'added': 1,
'deleted': 10,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
],
'git_diff_chmod.diff': [
('work-horus.xls', 'modified',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {CHMOD_FILENODE: 'modified file chmod 100644 => 100755'}})
],
'git_diff_rename_file.diff': [
('file.xls', 'renamed',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {RENAMED_FILENODE: 'file renamed from work-horus.xls to file.xls'}}),
('files/var/www/favicon.ico/DEFAULT',
'renamed',
{'added': 0,
'binary': True,
'deleted': 0,
'ops': {4: 'file renamed from files/var/www/favicon.ico to files/var/www/favicon.ico/DEFAULT',
6: 'modified file chmod 100644 => 100755'}})
],
'git_diff_mod_single_binary_file.diff': [
('US Warszawa.jpg', 'modified',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {MOD_FILENODE: 'modified file',
BIN_FILENODE: 'binary diff not shown'}})
],
'git_diff_binary_and_normal.diff': [
('img/baseline-10px.png', 'added',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {NEW_FILENODE: 'new file 100644',
BIN_FILENODE: 'binary diff not shown'}}),
('img/baseline-20px.png', 'removed',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {DEL_FILENODE: 'deleted file',
BIN_FILENODE: 'binary diff not shown'}}),
('index.html', 'modified',
{'added': 3,
'deleted': 2,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('js/global.js', 'removed',
{'added': 0,
'deleted': 75,
'binary': False,
'ops': {DEL_FILENODE: 'deleted file'}}),
('js/jquery/hashgrid.js', 'added',
{'added': 340,
'deleted': 0,
'binary': False,
'ops': {NEW_FILENODE: 'new file 100755'}}),
('less/docs.less', 'modified',
{'added': 34,
'deleted': 0,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('less/scaffolding.less', 'modified',
{'added': 1,
'deleted': 3,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('readme.markdown', 'modified',
{'added': 1,
'deleted': 10,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
],
'diff_with_diff_data.diff': [
('vcs/backends/base.py', 'modified',
{'added': 18,
'deleted': 2,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('vcs/backends/git/repository.py', 'modified',
{'added': 46,
'deleted': 15,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('vcs/backends/hg.py', 'modified',
{'added': 22,
'deleted': 3,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('vcs/tests/test_git.py', 'modified',
{'added': 5,
'deleted': 5,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
('vcs/tests/test_repository.py', 'modified',
{'added': 174,
'deleted': 2,
'binary': False,
'ops': {MOD_FILENODE: 'modified file'}}),
],
'git_diff_modify_binary_file.diff': [
('file.name', 'modified',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {MOD_FILENODE: 'modified file',
BIN_FILENODE: 'binary diff not shown'}})
],
'hg_diff_copy_file.diff': [
('file2', 'modified',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {COPIED_FILENODE: 'file copied from file1 to file2'}}),
],
'hg_diff_copy_and_modify_file.diff': [
('file3', 'modified',
{'added': 1,
'deleted': 0,
'binary': False,
'ops': {COPIED_FILENODE: 'file copied from file2 to file3',
MOD_FILENODE: 'modified file'}}),
],
'hg_diff_copy_and_chmod_file.diff': [
('file4', 'modified',
{'added': 0,
'deleted': 0,
'binary': True,
'ops': {COPIED_FILENODE: 'file copied from file3 to file4',
CHMOD_FILENODE: 'modified file chmod 100644 => 100755'}}),
],
'hg_diff_copy_chmod_and_edit_file.diff': [
('file5', 'modified',
{'added': 2,
'deleted': 1,
'binary': False,
'ops': {COPIED_FILENODE: 'file copied from file4 to file5',
CHMOD_FILENODE: 'modified file chmod 100755 => 100644',
MOD_FILENODE: 'modified file'}}),
],
'hg_diff_rename_space_cr.diff': [
('oh yes', 'renamed',
{'added': 3,
'deleted': 2,
'binary': False,
'ops': {RENAMED_FILENODE: 'file renamed from oh no to oh yes'}}),
],
}
class TestDiffLib(base.TestController):
@base.parametrize('diff_fixture', DIFF_FIXTURES)
def test_diff(self, diff_fixture):
raw_diff = fixture.load_resource(diff_fixture, strip=False)
vcs = 'hg'
if diff_fixture.startswith('git_'):
vcs = 'git'
diff_processor = DiffProcessor(raw_diff, vcs=vcs)
data = [(x['filename'], x['operation'], x['stats']) for x in diff_processor.parsed]
expected_data = DIFF_FIXTURES[diff_fixture]
assert expected_data == data
def test_diff_markup(self):
raw_diff = fixture.load_resource('markuptest.diff', strip=False)
diff_processor = DiffProcessor(raw_diff)
chunks = diff_processor.parsed[0]['chunks']
assert not chunks[0]
#from pprint import pprint; pprint(chunks[1])
l = ['\n']
for d in chunks[1]:
d['line'] = d['line'].encode() # not needed for py3
l.append('%(action)-7s %(new_lineno)3s %(old_lineno)3s %(line)r\n' % d)
s = ''.join(l)
assert s == r'''
context ... ... '@@ -51,6 +51,13 @@\n'
unmod 51 51 '<u>\t</u>begin();\n'
unmod 52 52 '<u>\t</u>\n'
add 53 '<u>\t</u>int foo;<u class="cr"></u>\n'
add 54 '<u>\t</u>int bar; <u class="cr"></u>\n'
add 55 '<u>\t</u>int baz;<u>\t</u><u class="cr"></u>\n'
add 56 '<u>\t</u>int space; <i></i>'
add 57 '<u>\t</u>int tab;<u>\t</u>\n'
add 58 '<u>\t</u>\n'
unmod 59 53 ' <i></i>'
del 54 '<u>\t</u>#define MAX_STEPS (48)\n'
add 60 '<u>\t</u><u class="cr"></u>\n'
add 61 '<u>\t</u>#define MAX_STEPS (64)<u class="cr"></u>\n'
unmod 62 55 '\n'
del 56 '<u>\t</u>#define MIN_STEPS (<del>48</del>)\n'
add 63 '<u>\t</u>#define MIN_STEPS (<ins>42</ins>)\n'
'''
|