bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.65.4
by James Westby
Make the rename handling more robust. |
1 |
# Copyright (C) 2008 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
import time |
|
18 |
||
19 |
from bzrlib import ( |
|
20 |
branch, |
|
21 |
tests, |
|
22 |
)
|
|
23 |
||
24 |
from bzrlib.plugins.fastimport import ( |
|
25 |
commands, |
|
26 |
errors, |
|
27 |
)
|
|
28 |
||
29 |
from bzrlib.plugins.fastimport.processors import ( |
|
30 |
generic_processor, |
|
31 |
)
|
|
32 |
||
33 |
||
34 |
class TestRename(tests.TestCaseWithTransport): |
|
35 |
||
36 |
def get_handler(self): |
|
37 |
branch = self.make_branch('.') |
|
38 |
handler = generic_processor.GenericProcessor(branch.bzrdir) |
|
39 |
return (handler, branch) |
|
40 |
||
41 |
def get_command_iter(self, old_path, new_path): |
|
42 |
def command_list(): |
|
43 |
author = ['', 'bugs@a.com', time.time(), time.timezone] |
|
44 |
committer = ['', 'elmer@a.com', time.time(), time.timezone] |
|
45 |
def files_one(): |
|
46 |
yield commands.FileModifyCommand(old_path, 'file', False, |
|
47 |
None, "aaa") |
|
48 |
yield commands.CommitCommand('head', '1', author, |
|
|
0.64.71
by Ian Clatworthy
fix tests to use new CommitCommand constructor |
49 |
committer, "commit 1", None, [], files_one) |
|
0.65.4
by James Westby
Make the rename handling more robust. |
50 |
def files_two(): |
51 |
yield commands.FileRenameCommand(old_path, new_path) |
|
52 |
yield commands.CommitCommand('head', '2', author, |
|
|
0.64.71
by Ian Clatworthy
fix tests to use new CommitCommand constructor |
53 |
committer, "commit 2", ":1", [], files_two) |
|
0.65.4
by James Westby
Make the rename handling more robust. |
54 |
return command_list |
55 |
||
56 |
# FIXME: [] as a default is bad, as it is mutable, but I want
|
|
57 |
# to use None to mean "don't check this".
|
|
58 |
def check_changes(self, changes, expected_added=[], |
|
59 |
expected_removed=[], expected_modified=[], |
|
60 |
expected_renamed=[]): |
|
61 |
"""Check the changes in a TreeDelta |
|
62 |
||
63 |
This method checks that the TreeDelta contains the expected
|
|
64 |
modifications between the two trees that were used to generate
|
|
65 |
it. The required changes are passed in as a list, where
|
|
66 |
each entry contains the needed information about the change.
|
|
67 |
||
68 |
If you do not wish to assert anything about a particular
|
|
69 |
category then pass None instead.
|
|
70 |
||
71 |
changes: The TreeDelta to check.
|
|
72 |
expected_added: a list of (filename,) tuples that must have
|
|
73 |
been added in the delta.
|
|
74 |
expected_removed: a list of (filename,) tuples that must have
|
|
75 |
been removed in the delta.
|
|
76 |
expected_modified: a list of (filename,) tuples that must have
|
|
77 |
been modified in the delta.
|
|
78 |
expected_renamed: a list of (old_path, new_path) tuples that
|
|
79 |
must have been renamed in the delta.
|
|
80 |
"""
|
|
81 |
renamed = changes.renamed |
|
82 |
added = changes.added |
|
83 |
removed = changes.removed |
|
84 |
modified = changes.modified |
|
85 |
if expected_renamed is not None: |
|
86 |
self.assertEquals(len(renamed), len(expected_renamed), |
|
87 |
"%s is renamed" % str(renamed)) |
|
88 |
renamed_files = [(item[0], item[1]) for item in renamed] |
|
89 |
for expected_renamed_entry in expected_renamed: |
|
90 |
self.assertTrue(expected_renamed_entry in renamed_files, |
|
91 |
"%s is not renamed, %s are" % (str(expected_renamed_entry), |
|
92 |
renamed_files)) |
|
93 |
if expected_added is not None: |
|
94 |
self.assertEquals(len(added), len(expected_added), |
|
95 |
"%s is added" % str(added)) |
|
96 |
added_files = [(item[0],) for item in added] |
|
97 |
for expected_added_entry in expected_added: |
|
98 |
self.assertTrue(expected_added_entry in added_files, |
|
99 |
"%s is not added, %s are" % (str(expected_added_entry), |
|
100 |
added_files)) |
|
101 |
if expected_removed is not None: |
|
102 |
self.assertEquals(len(removed), len(expected_removed), |
|
103 |
"%s is removed" % str(removed)) |
|
104 |
removed_files = [(item[0],) for item in removed] |
|
105 |
for expected_removed_entry in expected_removed: |
|
106 |
self.assertTrue(expected_removed_entry in removed_files, |
|
107 |
"%s is not removed, %s are" % (str(expected_removed_entry), |
|
108 |
removed_files)) |
|
109 |
if expected_modified is not None: |
|
110 |
self.assertEquals(len(modified), len(expected_modified), |
|
111 |
"%s is modified" % str(modified)) |
|
112 |
modified_files = [(item[0],) for item in modified] |
|
113 |
for expected_modified_entry in expected_modified: |
|
114 |
self.assertTrue(expected_modified_entry in modified_files, |
|
115 |
"%s is not modified, %s are" % (str(expected_modified_entry), |
|
116 |
modified_files)) |
|
117 |
||
118 |
def test_rename_in_root(self): |
|
119 |
(handler, branch) = self.get_handler() |
|
120 |
old_path = 'a' |
|
121 |
new_path = 'b' |
|
122 |
command_list = self.get_command_iter(old_path, new_path) |
|
123 |
handler.process(command_list) |
|
124 |
repo = branch.repository |
|
125 |
revtree1 = repo.revision_tree(branch.revision_history()[0]) |
|
126 |
revtree2 = repo.revision_tree(branch.revision_history()[1]) |
|
127 |
changes = revtree2.changes_from(revtree1) |
|
128 |
self.check_changes(changes, expected_renamed=[(old_path, new_path)]) |
|
129 |
||
130 |
def test_rename_in_subdir(self): |
|
131 |
(handler, branch) = self.get_handler() |
|
132 |
old_path = 'a/a' |
|
133 |
new_path = 'a/b' |
|
134 |
command_list = self.get_command_iter(old_path, new_path) |
|
135 |
handler.process(command_list) |
|
136 |
repo = branch.repository |
|
137 |
revtree1 = repo.revision_tree(branch.revision_history()[0]) |
|
138 |
revtree2 = repo.revision_tree(branch.revision_history()[1]) |
|
139 |
changes = revtree2.changes_from(revtree1) |
|
140 |
self.check_changes(changes, expected_renamed=[(old_path, new_path)]) |
|
141 |
||
142 |
def test_move_to_new_dir(self): |
|
143 |
(handler, branch) = self.get_handler() |
|
144 |
old_path = 'a/a' |
|
145 |
new_path = 'b/a' |
|
146 |
command_list = self.get_command_iter(old_path, new_path) |
|
147 |
handler.process(command_list) |
|
148 |
repo = branch.repository |
|
149 |
revtree1 = repo.revision_tree(branch.revision_history()[0]) |
|
150 |
revtree2 = repo.revision_tree(branch.revision_history()[1]) |
|
151 |
changes = revtree2.changes_from(revtree1) |
|
152 |
self.check_changes(changes, expected_renamed=[(old_path, new_path)], |
|
153 |
expected_added=[('b',)]) |