Mercurial > kallithea
annotate rhodecode/tests/models/test_diff_parsers.py @ 3733:af049a957506 beta
fixed default permissions population during upgrades
- it often happen that introducing new permission
caused default permission to reset it's state to installation
default.
new version makes sure that only missing permissions are
created while leaving old defaults
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 10 Apr 2013 02:55:21 +0200 |
parents | fb1709520112 |
children | ce4b7023a492 |
rev | line source |
---|---|
3035
fb1709520112
fix tests for python2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
3022
diff
changeset
|
1 from __future__ import with_statement |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 import os |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 import unittest |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 from rhodecode.tests import * |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 from rhodecode.lib.diffs import DiffProcessor, NEW_FILENODE, DEL_FILENODE, \ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 dn = os.path.dirname |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 FIXTURES = os.path.join(dn(dn(os.path.abspath(__file__))), 'fixtures') |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 DIFF_FIXTURES = { |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 'hg_diff_add_single_binary_file.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 (u'US Warszawa.jpg', 'A', ['b', NEW_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 'hg_diff_mod_single_binary_file.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 (u'US Warszawa.jpg', 'M', ['b', MOD_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 'hg_diff_del_single_binary_file.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 (u'US Warszawa.jpg', 'D', ['b', DEL_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 'hg_diff_binary_and_normal.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 (u'img/baseline-10px.png', 'A', ['b', NEW_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 (u'js/jquery/hashgrid.js', 'A', [340, 0]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 (u'index.html', 'M', [3, 2]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 (u'less/docs.less', 'M', [34, 0]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 (u'less/scaffolding.less', 'M', [1, 3]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 (u'readme.markdown', 'M', [1, 10]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 (u'img/baseline-20px.png', 'D', ['b', DEL_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 (u'js/global.js', 'D', [0, 75]) |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 'hg_diff_chmod.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 (u'file', 'M', ['b', CHMOD_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 'hg_diff_rename_file.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 (u'file_renamed', 'M', ['b', RENAMED_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 'git_diff_chmod.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 (u'work-horus.xls', 'M', ['b', CHMOD_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 'git_diff_rename_file.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 (u'file.xls', 'M', ['b', RENAMED_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 'git_diff_mod_single_binary_file.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 ('US Warszawa.jpg', 'M', ['b', MOD_FILENODE]) |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 'git_diff_binary_and_normal.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 (u'img/baseline-10px.png', 'A', ['b', NEW_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 (u'js/jquery/hashgrid.js', 'A', [340, 0]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 (u'index.html', 'M', [3, 2]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 (u'less/docs.less', 'M', [34, 0]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 (u'less/scaffolding.less', 'M', [1, 3]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 (u'readme.markdown', 'M', [1, 10]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 (u'img/baseline-20px.png', 'D', ['b', DEL_FILENODE]), |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 (u'js/global.js', 'D', [0, 75]) |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 ], |
3022
0ed42ca7ff9e
Fixed issue with inproper handling of diff parsing that could lead to infinit loops.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
57 'diff_with_diff_data.diff': [ |
0ed42ca7ff9e
Fixed issue with inproper handling of diff parsing that could lead to infinit loops.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
58 (u'vcs/backends/base.py', 'M', [18, 2]), |
0ed42ca7ff9e
Fixed issue with inproper handling of diff parsing that could lead to infinit loops.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
59 (u'vcs/backends/git/repository.py', 'M', [46, 15]), |
0ed42ca7ff9e
Fixed issue with inproper handling of diff parsing that could lead to infinit loops.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
60 (u'vcs/backends/hg.py', 'M', [22, 3]), |
0ed42ca7ff9e
Fixed issue with inproper handling of diff parsing that could lead to infinit loops.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
61 (u'vcs/tests/test_git.py', 'M', [5, 5]), |
0ed42ca7ff9e
Fixed issue with inproper handling of diff parsing that could lead to infinit loops.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
62 (u'vcs/tests/test_repository.py', 'M', [174, 2]) |
0ed42ca7ff9e
Fixed issue with inproper handling of diff parsing that could lead to infinit loops.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
63 ], |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 # 'large_diff.diff': [ |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 # |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 # ], |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 } |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 def _diff_checker(fixture): |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 with open(os.path.join(FIXTURES, fixture)) as f: |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 diff = f.read() |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 diff_proc = DiffProcessor(diff) |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 diff_proc_d = diff_proc.prepare() |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 data = [(x['filename'], x['operation'], x['stats']) for x in diff_proc_d] |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 expected_data = DIFF_FIXTURES[fixture] |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 assert expected_data == data |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 def test_parse_diff(): |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 for fixture in DIFF_FIXTURES: |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 yield _diff_checker, fixture |