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
|
# Copyright (C) 2008 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Test the Import parsing"""
import StringIO
from bzrlib import tests
from bzrlib.plugins.fastimport import (
errors,
parser,
)
class TestLineBasedParser(tests.TestCase):
def test_push_line(self):
s = StringIO.StringIO("foo\nbar\nbaz\n")
p = parser.LineBasedParser(s)
self.assertEqual('foo', p.next_line())
self.assertEqual('bar', p.next_line())
p.push_line('bar')
self.assertEqual('bar', p.next_line())
self.assertEqual('baz', p.next_line())
self.assertEqual(None, p.next_line())
def test_read_bytes(self):
s = StringIO.StringIO("foo\nbar\nbaz\n")
p = parser.LineBasedParser(s)
self.assertEqual('fo', p.read_bytes(2))
self.assertEqual('o\nb', p.read_bytes(3))
self.assertEqual('ar', p.next_line())
# Test that the line buffer is ignored
p.push_line('bar')
self.assertEqual('baz', p.read_bytes(3))
# Test missing bytes
self.assertRaises(errors.MissingBytes, p.read_bytes, 10)
def test_read_until(self):
# TODO
return
s = StringIO.StringIO("foo\nbar\nbaz\nabc\ndef\nghi\n")
p = parser.LineBasedParser(s)
self.assertEqual('foo\nbar', p.read_until('baz'))
self.assertEqual('abc', p.next_line())
# Test that the line buffer is ignored
p.push_line('abc')
self.assertEqual('def', p.read_until('ghi'))
# Test missing terminator
self.assertRaises(errors.MissingTerminator, p.read_until('>>>'))
# Sample text
_sample_import_text = """
progress completed
# Test blob formats
blob
mark :1
data 4
aaaa
blob
data 5
bbbbb
# Commit formats
commit
committer bugs <bugs@bunny.org> now
data 14
initial import
M 644 inline README
data 18
Welcome from bugs
# Miscellaneous
checkpoint
progress completed
"""
class TestImportParser(tests.TestCase):
def test_iter_commands(self):
s = StringIO.StringIO(_sample_import_text)
p = parser.ImportParser(s)
for cmd in p.iter_commands():
print cmd
if cmd.name == 'commit':
for fc in cmd.file_iter():
print " %s" % (fc,)
#cmd1 = cmds[0]
#self.assertEqual('progress', cmd1.name)
|