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
|
|
74 |
aaaa
|
|
75 |
blob
|
|
76 |
data 5
|
|
77 |
bbbbb
|
|
78 |
# Commit formats
|
|
79 |
commit
|
|
|
0.65.2
by James Westby
The space between the author and email is optional in committer. |
80 |
mark :1
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
81 |
committer bugs <bugs@bunny.org> now
|
82 |
data 14
|
|
83 |
initial import
|
|
84 |
M 644 inline README
|
|
85 |
data 18
|
|
86 |
Welcome from bugs
|
|
|
0.65.2
by James Westby
The space between the author and email is optional in committer. |
87 |
commit
|
88 |
committer <bugs@bunny.org> now
|
|
89 |
data 13
|
|
90 |
second commit
|
|
91 |
from :1
|
|
92 |
M 644 inline README
|
|
93 |
data 24
|
|
94 |
Welcome from bugs, etc.
|
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
95 |
# Miscellaneous
|
96 |
checkpoint
|
|
97 |
progress completed
|
|
98 |
"""
|
|
99 |
||
100 |
||
101 |
class TestImportParser(tests.TestCase): |
|
102 |
||
103 |
def test_iter_commands(self): |
|
104 |
s = StringIO.StringIO(_sample_import_text) |
|
105 |
p = parser.ImportParser(s) |
|
|
0.64.10
by Ian Clatworthy
1st cut are dequoting paths |
106 |
result = [] |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
107 |
for cmd in p.iter_commands(): |
|
0.64.10
by Ian Clatworthy
1st cut are dequoting paths |
108 |
result.append(cmd) |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
109 |
if cmd.name == 'commit': |
110 |
for fc in cmd.file_iter(): |
|
|
0.64.10
by Ian Clatworthy
1st cut are dequoting paths |
111 |
result.append(fc) |
112 |
cmd1 = result[0] |
|
113 |
self.assertEqual('progress', cmd1.name) |
|
114 |
||
115 |
||
116 |
class TestStringParsing(tests.TestCase): |
|
117 |
||
118 |
def test_unquote(self): |
|
119 |
s = r'hello \"sweet\" wo\\r\tld' |
|
120 |
self.assertEquals(r'hello "sweet" wo\r' + "\tld", |
|
121 |
parser._unquote_c_string(s)) |