bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
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 |
"""Test the Import parsing"""
|
|
18 |
||
19 |
import StringIO |
|
20 |
||
21 |
from bzrlib import tests |
|
22 |
||
23 |
from bzrlib.plugins.fastimport import ( |
|
24 |
errors, |
|
25 |
parser, |
|
26 |
)
|
|
27 |
||
28 |
||
29 |
class TestLineBasedParser(tests.TestCase): |
|
30 |
||
31 |
def test_push_line(self): |
|
32 |
s = StringIO.StringIO("foo\nbar\nbaz\n") |
|
33 |
p = parser.LineBasedParser(s) |
|
34 |
self.assertEqual('foo', p.next_line()) |
|
35 |
self.assertEqual('bar', p.next_line()) |
|
36 |
p.push_line('bar') |
|
37 |
self.assertEqual('bar', p.next_line()) |
|
38 |
self.assertEqual('baz', p.next_line()) |
|
39 |
self.assertEqual(None, p.next_line()) |
|
40 |
||
41 |
def test_read_bytes(self): |
|
42 |
s = StringIO.StringIO("foo\nbar\nbaz\n") |
|
43 |
p = parser.LineBasedParser(s) |
|
44 |
self.assertEqual('fo', p.read_bytes(2)) |
|
45 |
self.assertEqual('o\nb', p.read_bytes(3)) |
|
46 |
self.assertEqual('ar', p.next_line()) |
|
47 |
# Test that the line buffer is ignored
|
|
48 |
p.push_line('bar') |
|
49 |
self.assertEqual('baz', p.read_bytes(3)) |
|
50 |
# Test missing bytes
|
|
51 |
self.assertRaises(errors.MissingBytes, p.read_bytes, 10) |
|
52 |
||
53 |
def test_read_until(self): |
|
54 |
# TODO
|
|
55 |
return
|
|
56 |
s = StringIO.StringIO("foo\nbar\nbaz\nabc\ndef\nghi\n") |
|
57 |
p = parser.LineBasedParser(s) |
|
58 |
self.assertEqual('foo\nbar', p.read_until('baz')) |
|
59 |
self.assertEqual('abc', p.next_line()) |
|
60 |
# Test that the line buffer is ignored
|
|
61 |
p.push_line('abc') |
|
62 |
self.assertEqual('def', p.read_until('ghi')) |
|
63 |
# Test missing terminator
|
|
64 |
self.assertRaises(errors.MissingTerminator, p.read_until('>>>')) |
|
65 |
||
66 |
||
67 |
# Sample text
|
|
68 |
_sample_import_text = """ |
|
69 |
progress completed
|
|
70 |
# Test blob formats
|
|
71 |
blob
|
|
72 |
mark :1
|
|
73 |
data 4
|
|
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
74 |
aaaablob
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
75 |
data 5
|
76 |
bbbbb
|
|
77 |
# Commit formats
|
|
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
78 |
commit refs/heads/master
|
79 |
mark :2
|
|
80 |
committer bugs bunny <bugs@bunny.org> now
|
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
81 |
data 14
|
82 |
initial import
|
|
83 |
M 644 inline README
|
|
84 |
data 18
|
|
85 |
Welcome from bugs
|
|
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
86 |
commit refs/heads/master
|
|
0.65.2
by James Westby
The space between the author and email is optional in committer. |
87 |
committer <bugs@bunny.org> now
|
88 |
data 13
|
|
89 |
second commit
|
|
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
90 |
from :2
|
|
0.65.2
by James Westby
The space between the author and email is optional in committer. |
91 |
M 644 inline README
|
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
92 |
data 23
|
|
0.65.2
by James Westby
The space between the author and email is optional in committer. |
93 |
Welcome from bugs, etc.
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
94 |
# Miscellaneous
|
95 |
checkpoint
|
|
96 |
progress completed
|
|
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
97 |
# Test a commit without sub-commands (bug #351717)
|
98 |
commit refs/heads/master
|
|
99 |
mark :3
|
|
100 |
author <bugs@bunny.org> now
|
|
101 |
committer <bugs@bunny.org> now
|
|
102 |
data 20
|
|
103 |
first commit, empty
|
|
|
0.88.1
by Samuel Bronson
Add a test for bug #400960. |
104 |
# Test a commit with a heredoc-style (delimited_data) messsage (bug #400960)
|
105 |
commit refs/heads/master
|
|
106 |
mark :4
|
|
107 |
author <bugs@bunny.org> now
|
|
108 |
committer <bugs@bunny.org> now
|
|
109 |
data <<EOF
|
|
110 |
Commit with heredoc-style message
|
|
111 |
EOF
|
|
|
0.64.229
by Ian Clatworthy
Handle git submodules in the stream by warning about + ignoring them |
112 |
# Test a "submodule"/tree-reference
|
113 |
commit refs/heads/master
|
|
114 |
mark :5
|
|
115 |
author <bugs@bunny.org> now
|
|
116 |
committer <bugs@bunny.org> now
|
|
117 |
data 15
|
|
118 |
submodule test
|
|
119 |
M 160000 rev-id tree-id
|
|
|
0.102.8
by Ian Clatworthy
feature parsing |
120 |
# Test features
|
121 |
feature whatever
|
|
122 |
feature foo=bar
|
|
|
0.102.9
by Ian Clatworthy
parsing of multiple authors and commit properties |
123 |
# Test commit with properties
|
124 |
commit refs/heads/master
|
|
125 |
mark :6
|
|
126 |
committer <bugs@bunny.org> now
|
|
127 |
data 18
|
|
128 |
test of properties
|
|
129 |
property p1
|
|
130 |
property p2 5 hohum
|
|
131 |
property p3 16 alpha
|
|
132 |
beta
|
|
133 |
gamma
|
|
|
0.64.255
by Ian Clatworthy
Fix parsing error when a property is found after a multi-line one |
134 |
property p4 8 whatever
|
|
0.102.9
by Ian Clatworthy
parsing of multiple authors and commit properties |
135 |
# Test a commit with multiple authors
|
136 |
commit refs/heads/master
|
|
137 |
mark :7
|
|
138 |
author Fluffy <fluffy@bunny.org> now
|
|
139 |
author Daffy <daffy@duck.org> now
|
|
140 |
author Donald <donald@duck.org> now
|
|
141 |
committer <bugs@bunny.org> now
|
|
142 |
data 17
|
|
143 |
multi-author test
|
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
144 |
"""
|
145 |
||
146 |
||
147 |
class TestImportParser(tests.TestCase): |
|
148 |
||
149 |
def test_iter_commands(self): |
|
150 |
s = StringIO.StringIO(_sample_import_text) |
|
151 |
p = parser.ImportParser(s) |
|
|
0.64.10
by Ian Clatworthy
1st cut are dequoting paths |
152 |
result = [] |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
153 |
for cmd in p.iter_commands(): |
|
0.64.10
by Ian Clatworthy
1st cut are dequoting paths |
154 |
result.append(cmd) |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
155 |
if cmd.name == 'commit': |
156 |
for fc in cmd.file_iter(): |
|
|
0.64.10
by Ian Clatworthy
1st cut are dequoting paths |
157 |
result.append(fc) |
|
0.102.9
by Ian Clatworthy
parsing of multiple authors and commit properties |
158 |
self.assertEqual(len(result), 17) |
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
159 |
cmd1 = result.pop(0) |
|
0.64.10
by Ian Clatworthy
1st cut are dequoting paths |
160 |
self.assertEqual('progress', cmd1.name) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
161 |
self.assertEqual('completed', cmd1.message) |
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
162 |
cmd2 = result.pop(0) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
163 |
self.assertEqual('blob', cmd2.name) |
164 |
self.assertEqual('1', cmd2.mark) |
|
165 |
self.assertEqual(':1', cmd2.id) |
|
166 |
self.assertEqual('aaaa', cmd2.data) |
|
167 |
self.assertEqual(4, cmd2.lineno) |
|
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
168 |
cmd3 = result.pop(0) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
169 |
self.assertEqual('blob', cmd3.name) |
170 |
self.assertEqual('@7', cmd3.id) |
|
171 |
self.assertEqual(None, cmd3.mark) |
|
172 |
self.assertEqual('bbbbb', cmd3.data) |
|
173 |
self.assertEqual(7, cmd3.lineno) |
|
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
174 |
cmd4 = result.pop(0) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
175 |
self.assertEqual('commit', cmd4.name) |
176 |
self.assertEqual('2', cmd4.mark) |
|
177 |
self.assertEqual(':2', cmd4.id) |
|
178 |
self.assertEqual('initial import', cmd4.message) |
|
179 |
self.assertEqual('bugs bunny', cmd4.committer[0]) |
|
180 |
self.assertEqual('bugs@bunny.org', cmd4.committer[1]) |
|
181 |
# FIXME: check timestamp and timezone as well
|
|
182 |
self.assertEqual(None, cmd4.author) |
|
183 |
self.assertEqual(11, cmd4.lineno) |
|
184 |
self.assertEqual('refs/heads/master', cmd4.ref) |
|
|
0.64.71
by Ian Clatworthy
fix tests to use new CommitCommand constructor |
185 |
self.assertEqual(None, cmd4.from_) |
186 |
self.assertEqual([], cmd4.merges) |
|
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
187 |
file_cmd1 = result.pop(0) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
188 |
self.assertEqual('filemodify', file_cmd1.name) |
189 |
self.assertEqual('README', file_cmd1.path) |
|
190 |
self.assertEqual('file', file_cmd1.kind) |
|
191 |
self.assertEqual(False, file_cmd1.is_executable) |
|
192 |
self.assertEqual('Welcome from bugs\n', file_cmd1.data) |
|
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
193 |
cmd5 = result.pop(0) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
194 |
self.assertEqual('commit', cmd5.name) |
195 |
self.assertEqual(None, cmd5.mark) |
|
196 |
self.assertEqual('@19', cmd5.id) |
|
197 |
self.assertEqual('second commit', cmd5.message) |
|
198 |
self.assertEqual('', cmd5.committer[0]) |
|
199 |
self.assertEqual('bugs@bunny.org', cmd5.committer[1]) |
|
200 |
# FIXME: check timestamp and timezone as well
|
|
201 |
self.assertEqual(None, cmd5.author) |
|
202 |
self.assertEqual(19, cmd5.lineno) |
|
203 |
self.assertEqual('refs/heads/master', cmd5.ref) |
|
|
0.64.71
by Ian Clatworthy
fix tests to use new CommitCommand constructor |
204 |
self.assertEqual(':2', cmd5.from_) |
205 |
self.assertEqual([], cmd5.merges) |
|
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
206 |
file_cmd2 = result.pop(0) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
207 |
self.assertEqual('filemodify', file_cmd2.name) |
208 |
self.assertEqual('README', file_cmd2.path) |
|
209 |
self.assertEqual('file', file_cmd2.kind) |
|
210 |
self.assertEqual(False, file_cmd2.is_executable) |
|
211 |
self.assertEqual('Welcome from bugs, etc.', file_cmd2.data) |
|
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
212 |
cmd6 = result.pop(0) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
213 |
self.assertEqual(cmd6.name, 'checkpoint') |
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
214 |
cmd7 = result.pop(0) |
|
0.65.5
by James Westby
Make the parser handle multiple words in the committer name. |
215 |
self.assertEqual('progress', cmd7.name) |
216 |
self.assertEqual('completed', cmd7.message) |
|
|
0.64.172
by Ian Clatworthy
handle commit commands with no from clause and no sub-commands |
217 |
cmd = result.pop(0) |
218 |
self.assertEqual('commit', cmd.name) |
|
219 |
self.assertEqual('3', cmd.mark) |
|
220 |
self.assertEqual(None, cmd.from_) |
|
|
0.88.1
by Samuel Bronson
Add a test for bug #400960. |
221 |
cmd = result.pop(0) |
222 |
self.assertEqual('commit', cmd.name) |
|
223 |
self.assertEqual('4', cmd.mark) |
|
224 |
self.assertEqual('Commit with heredoc-style message\n', cmd.message) |
|
|
0.64.229
by Ian Clatworthy
Handle git submodules in the stream by warning about + ignoring them |
225 |
cmd = result.pop(0) |
226 |
self.assertEqual('commit', cmd.name) |
|
227 |
self.assertEqual('5', cmd.mark) |
|
228 |
self.assertEqual('submodule test\n', cmd.message) |
|
229 |
file_cmd1 = result.pop(0) |
|
230 |
self.assertEqual('filemodify', file_cmd1.name) |
|
231 |
self.assertEqual('tree-id', file_cmd1.path) |
|
232 |
self.assertEqual('tree-reference', file_cmd1.kind) |
|
233 |
self.assertEqual(False, file_cmd1.is_executable) |
|
234 |
self.assertEqual("rev-id", file_cmd1.dataref) |
|
|
0.102.8
by Ian Clatworthy
feature parsing |
235 |
cmd = result.pop(0) |
236 |
self.assertEqual('feature', cmd.name) |
|
237 |
self.assertEqual('whatever', cmd.feature_name) |
|
238 |
self.assertEqual(None, cmd.value) |
|
239 |
cmd = result.pop(0) |
|
240 |
self.assertEqual('feature', cmd.name) |
|
241 |
self.assertEqual('foo', cmd.feature_name) |
|
242 |
self.assertEqual('bar', cmd.value) |
|
|
0.102.9
by Ian Clatworthy
parsing of multiple authors and commit properties |
243 |
cmd = result.pop(0) |
244 |
self.assertEqual('commit', cmd.name) |
|
245 |
self.assertEqual('6', cmd.mark) |
|
246 |
self.assertEqual('test of properties', cmd.message) |
|
247 |
self.assertEqual({ |
|
|
0.102.10
by Ian Clatworthy
Store multiple authors and revision properties when defined |
248 |
'p1': None, |
249 |
'p2': u'hohum', |
|
250 |
'p3': u'alpha\nbeta\ngamma', |
|
|
0.64.255
by Ian Clatworthy
Fix parsing error when a property is found after a multi-line one |
251 |
'p4': u'whatever', |
|
0.102.9
by Ian Clatworthy
parsing of multiple authors and commit properties |
252 |
}, cmd.properties) |
253 |
cmd = result.pop(0) |
|
254 |
self.assertEqual('commit', cmd.name) |
|
255 |
self.assertEqual('7', cmd.mark) |
|
256 |
self.assertEqual('multi-author test', cmd.message) |
|
257 |
self.assertEqual('', cmd.committer[0]) |
|
258 |
self.assertEqual('bugs@bunny.org', cmd.committer[1]) |
|
259 |
self.assertEqual('Fluffy', cmd.author[0]) |
|
260 |
self.assertEqual('fluffy@bunny.org', cmd.author[1]) |
|
261 |
self.assertEqual('Daffy', cmd.more_authors[0][0]) |
|
262 |
self.assertEqual('daffy@duck.org', cmd.more_authors[0][1]) |
|
263 |
self.assertEqual('Donald', cmd.more_authors[1][0]) |
|
264 |
self.assertEqual('donald@duck.org', cmd.more_authors[1][1]) |
|
|
0.64.10
by Ian Clatworthy
1st cut are dequoting paths |
265 |
|
266 |
||
267 |
class TestStringParsing(tests.TestCase): |
|
268 |
||
269 |
def test_unquote(self): |
|
270 |
s = r'hello \"sweet\" wo\\r\tld' |
|
271 |
self.assertEquals(r'hello "sweet" wo\r' + "\tld", |
|
272 |
parser._unquote_c_string(s)) |
|
|
0.64.175
by Ian Clatworthy
fix parsing when a rename old-path has spaces in it |
273 |
|
274 |
||
275 |
class TestPathPairParsing(tests.TestCase): |
|
276 |
||
277 |
def test_path_pair_simple(self): |
|
278 |
p = parser.ImportParser("") |
|
279 |
self.assertEqual(['foo', 'bar'], p._path_pair("foo bar")) |
|
280 |
||
281 |
def test_path_pair_spaces_in_first(self): |
|
282 |
p = parser.ImportParser("") |
|
283 |
self.assertEqual(['foo bar', 'baz'], |
|
284 |
p._path_pair('"foo bar" baz')) |