1
# Copyright (C) 2008 Canonical Ltd
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.
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.
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
17
"""Test the Import parsing"""
21
from bzrlib import tests
23
from bzrlib.plugins.fastimport import (
29
class TestLineBasedParser(tests.TestCase):
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())
37
self.assertEqual('bar', p.next_line())
38
self.assertEqual('baz', p.next_line())
39
self.assertEqual(None, p.next_line())
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
49
self.assertEqual('baz', p.read_bytes(3))
51
self.assertRaises(errors.MissingBytes, p.read_bytes, 10)
53
def test_read_until(self):
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
62
self.assertEqual('def', p.read_until('ghi'))
63
# Test missing terminator
64
self.assertRaises(errors.MissingTerminator, p.read_until('>>>'))
68
_sample_import_text = """
80
committer bugs <bugs@bunny.org> now
92
class TestImportParser(tests.TestCase):
94
def test_iter_commands(self):
95
s = StringIO.StringIO(_sample_import_text)
96
p = parser.ImportParser(s)
97
for cmd in p.iter_commands():
99
if cmd.name == 'commit':
100
for fc in cmd.file_iter():
103
#self.assertEqual('progress', cmd1.name)