diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2010-09-03 23:09:05 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2010-09-03 23:09:05 +0200 |
commit | 844a4f35d6ab0dc1542c40b03cef19a87b9dda08 (patch) | |
tree | 8f13f492b839d5fa3fd9689c3ce674b9c5770c62 /tests | |
parent | bb709e9dabb929d07d9f5424da262bdfd99d8b2d (diff) | |
download | bzr-fastimport-844a4f35d6ab0dc1542c40b03cef19a87b9dda08.tar.gz |
Move pure-fastimport code into its own directory, in preparation of splitting it into a separate package.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 20 | ||||
-rw-r--r-- | tests/test_commands.py | 341 | ||||
-rw-r--r-- | tests/test_errors.py | 78 | ||||
-rw-r--r-- | tests/test_filter_processor.py | 16 | ||||
-rw-r--r-- | tests/test_generic_processor.py | 3 | ||||
-rw-r--r-- | tests/test_head_tracking.py | 2 | ||||
-rw-r--r-- | tests/test_parser.py | 2 |
7 files changed, 22 insertions, 440 deletions
diff --git a/tests/__init__.py b/tests/__init__.py index cda5705..549cf3e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -21,16 +21,16 @@ from bzrlib.tests.TestUtil import TestLoader, TestSuite def test_suite(): - module_names = [__name__ + '.' + x for x in [ - 'test_branch_mapper', - 'test_commands', - 'test_errors', - 'test_filter_processor', - 'test_generic_processor', - 'test_head_tracking', - 'test_helpers', - 'test_parser', - 'test_revision_store', + module_names = ['bzrlib.plugins.fastimport.' + x for x in [ + 'fastimport.tests.test_commands', + 'fastimport.tests.test_errors', + 'tests.test_branch_mapper', + 'tests.test_filter_processor', + 'tests.test_generic_processor', + 'tests.test_head_tracking', + 'tests.test_helpers', + 'tests.test_parser', + 'tests.test_revision_store', ]] loader = TestLoader() return loader.loadTestsFromModuleNames(module_names) diff --git a/tests/test_commands.py b/tests/test_commands.py deleted file mode 100644 index 3e185b0..0000000 --- a/tests/test_commands.py +++ /dev/null @@ -1,341 +0,0 @@ -# Copyright (C) 2009 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 how Commands are displayed""" - -from bzrlib import tests - -from bzrlib.plugins.fastimport import ( - commands, - ) - - -class TestBlobDisplay(tests.TestCase): - - def test_blob(self): - c = commands.BlobCommand("1", "hello world") - self.assertEqual("blob\nmark :1\ndata 11\nhello world", repr(c)) - - def test_blob_no_mark(self): - c = commands.BlobCommand(None, "hello world") - self.assertEqual("blob\ndata 11\nhello world", repr(c)) - - -class TestCheckpointDisplay(tests.TestCase): - - def test_checkpoint(self): - c = commands.CheckpointCommand() - self.assertEqual("checkpoint", repr(c)) - - -class TestCommitDisplay(tests.TestCase): - - def test_commit(self): - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, - "release v1.0", ":aaa", None, None) - self.assertEqualDiff( - "commit refs/heads/master\n" - "mark :bbb\n" - "committer Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0\n" - "from :aaa", - repr(c)) - - def test_commit_unicode_committer(self): - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - name = u'\u013d\xf3r\xe9m \xcdp\u0161\xfam' - name_utf8 = name.encode('utf8') - committer = (name, 'test@example.com', 1234567890, -6 * 3600) - c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, - "release v1.0", ":aaa", None, None) - self.assertEqualDiff( - "commit refs/heads/master\n" - "mark :bbb\n" - "committer %s <test@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0\n" - "from :aaa" % (name_utf8,), - repr(c)) - - def test_commit_no_mark(self): - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - c = commands.CommitCommand("refs/heads/master", None, None, committer, - "release v1.0", ":aaa", None, None) - self.assertEqualDiff( - "commit refs/heads/master\n" - "committer Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0\n" - "from :aaa", - repr(c)) - - def test_commit_no_from(self): - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, - "release v1.0", None, None, None) - self.assertEqualDiff( - "commit refs/heads/master\n" - "mark :bbb\n" - "committer Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0", - repr(c)) - - def test_commit_with_author(self): - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600) - committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - c = commands.CommitCommand("refs/heads/master", "bbb", author, - committer, "release v1.0", ":aaa", None, None) - self.assertEqualDiff( - "commit refs/heads/master\n" - "mark :bbb\n" - "author Sue Wong <sue@example.com> 1234565432 -0600\n" - "committer Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0\n" - "from :aaa", - repr(c)) - - def test_commit_with_merges(self): - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - c = commands.CommitCommand("refs/heads/master", "ddd", None, committer, - "release v1.0", ":aaa", [':bbb', ':ccc'], None) - self.assertEqualDiff( - "commit refs/heads/master\n" - "mark :ddd\n" - "committer Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0\n" - "from :aaa\n" - "merge :bbb\n" - "merge :ccc", - repr(c)) - - def test_commit_with_filecommands(self): - file_cmds = iter([ - commands.FileDeleteCommand('readme.txt'), - commands.FileModifyCommand('NEWS', 'file', False, None, - 'blah blah blah'), - ]) - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, - "release v1.0", ":aaa", None, file_cmds) - self.assertEqualDiff( - "commit refs/heads/master\n" - "mark :bbb\n" - "committer Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0\n" - "from :aaa\n" - "D readme.txt\n" - "M 644 inline NEWS\n" - "data 14\n" - "blah blah blah", - repr(c)) - - def test_commit_with_more_authors(self): - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600) - committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - more_authors = [ - ('Al Smith', 'al@example.com', 1234565432, -6 * 3600), - ('Bill Jones', 'bill@example.com', 1234565432, -6 * 3600), - ] - c = commands.CommitCommand("refs/heads/master", "bbb", author, - committer, "release v1.0", ":aaa", None, None, - more_authors=more_authors) - self.assertEqualDiff( - "commit refs/heads/master\n" - "mark :bbb\n" - "author Sue Wong <sue@example.com> 1234565432 -0600\n" - "author Al Smith <al@example.com> 1234565432 -0600\n" - "author Bill Jones <bill@example.com> 1234565432 -0600\n" - "committer Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0\n" - "from :aaa", - repr(c)) - - def test_commit_with_properties(self): - # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - properties = { - u'greeting': u'hello', - u'planet': u'world', - } - c = commands.CommitCommand("refs/heads/master", "bbb", None, - committer, "release v1.0", ":aaa", None, None, - properties=properties) - self.assertEqualDiff( - "commit refs/heads/master\n" - "mark :bbb\n" - "committer Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 12\n" - "release v1.0\n" - "from :aaa\n" - "property greeting 5 hello\n" - "property planet 5 world", - repr(c)) - - -class TestFeatureDisplay(tests.TestCase): - - def test_feature(self): - c = commands.FeatureCommand("dwim") - self.assertEqual("feature dwim", repr(c)) - - def test_feature_with_value(self): - c = commands.FeatureCommand("dwim", "please") - self.assertEqual("feature dwim=please", repr(c)) - - -class TestProgressDisplay(tests.TestCase): - - def test_progress(self): - c = commands.ProgressCommand("doing foo") - self.assertEqual("progress doing foo", repr(c)) - - -class TestResetDisplay(tests.TestCase): - - def test_reset(self): - c = commands.ResetCommand("refs/tags/v1.0", ":xxx") - self.assertEqual("reset refs/tags/v1.0\nfrom :xxx\n", repr(c)) - - def test_reset_no_from(self): - c = commands.ResetCommand("refs/remotes/origin/master", None) - self.assertEqual("reset refs/remotes/origin/master", repr(c)) - - -class TestTagDisplay(tests.TestCase): - - def test_tag(self): - # tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc) - tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - c = commands.TagCommand("refs/tags/v1.0", ":xxx", tagger, "create v1.0") - self.assertEqual( - "tag refs/tags/v1.0\n" - "from :xxx\n" - "tagger Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 11\n" - "create v1.0", - repr(c)) - - def test_tag_no_from(self): - tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) - c = commands.TagCommand("refs/tags/v1.0", None, tagger, "create v1.0") - self.assertEqualDiff( - "tag refs/tags/v1.0\n" - "tagger Joe Wong <joe@example.com> 1234567890 -0600\n" - "data 11\n" - "create v1.0", - repr(c)) - - -class TestFileModifyDisplay(tests.TestCase): - - def test_filemodify_file(self): - c = commands.FileModifyCommand("foo/bar", "file", False, ":23", None) - self.assertEqual("M 644 :23 foo/bar", repr(c)) - - def test_filemodify_file_executable(self): - c = commands.FileModifyCommand("foo/bar", "file", True, ":23", None) - self.assertEqual("M 755 :23 foo/bar", repr(c)) - - def test_filemodify_file_internal(self): - c = commands.FileModifyCommand("foo/bar", "file", False, None, - "hello world") - self.assertEqual("M 644 inline foo/bar\ndata 11\nhello world", repr(c)) - - def test_filemodify_symlink(self): - c = commands.FileModifyCommand("foo/bar", "symlink", False, None, "baz") - self.assertEqual("M 120000 inline foo/bar\ndata 3\nbaz", repr(c)) - - def test_filemodify_treeref(self): - c = commands.FileModifyCommand("tree-info", "tree-reference", False, - "revision-id-info", None) - self.assertEqual("M 160000 revision-id-info tree-info", repr(c)) - - -class TestFileDeleteDisplay(tests.TestCase): - - def test_filedelete(self): - c = commands.FileDeleteCommand("foo/bar") - self.assertEqual("D foo/bar", repr(c)) - - -class TestFileCopyDisplay(tests.TestCase): - - def test_filecopy(self): - c = commands.FileCopyCommand("foo/bar", "foo/baz") - self.assertEqual("C foo/bar foo/baz", repr(c)) - - def test_filecopy_quoted(self): - # Check the first path is quoted if it contains spaces - c = commands.FileCopyCommand("foo/b a r", "foo/b a z") - self.assertEqual('C "foo/b a r" foo/b a z', repr(c)) - - -class TestFileRenameDisplay(tests.TestCase): - - def test_filerename(self): - c = commands.FileRenameCommand("foo/bar", "foo/baz") - self.assertEqual("R foo/bar foo/baz", repr(c)) - - def test_filerename_quoted(self): - # Check the first path is quoted if it contains spaces - c = commands.FileRenameCommand("foo/b a r", "foo/b a z") - self.assertEqual('R "foo/b a r" foo/b a z', repr(c)) - - -class TestFileDeleteAllDisplay(tests.TestCase): - - def test_filedeleteall(self): - c = commands.FileDeleteAllCommand() - self.assertEqual("deleteall", repr(c)) - - -class TestPathChecking(tests.TestCase): - - def test_filemodify_path_checking(self): - self.assertRaises(ValueError, commands.FileModifyCommand, "", - "file", False, None, "text") - self.assertRaises(ValueError, commands.FileModifyCommand, None, - "file", False, None, "text") - - def test_filedelete_path_checking(self): - self.assertRaises(ValueError, commands.FileDeleteCommand, "") - self.assertRaises(ValueError, commands.FileDeleteCommand, None) - - def test_filerename_path_checking(self): - self.assertRaises(ValueError, commands.FileRenameCommand, "", "foo") - self.assertRaises(ValueError, commands.FileRenameCommand, None, "foo") - self.assertRaises(ValueError, commands.FileRenameCommand, "foo", "") - self.assertRaises(ValueError, commands.FileRenameCommand, "foo", None) - - def test_filecopy_path_checking(self): - self.assertRaises(ValueError, commands.FileCopyCommand, "", "foo") - self.assertRaises(ValueError, commands.FileCopyCommand, None, "foo") - self.assertRaises(ValueError, commands.FileCopyCommand, "foo", "") - self.assertRaises(ValueError, commands.FileCopyCommand, "foo", None) diff --git a/tests/test_errors.py b/tests/test_errors.py deleted file mode 100644 index 8f483a8..0000000 --- a/tests/test_errors.py +++ /dev/null @@ -1,78 +0,0 @@ -# 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 errors""" - -from bzrlib import tests - -from bzrlib.plugins.fastimport import ( - errors, - ) - - -class TestErrors(tests.TestCase): - - def test_MissingBytes(self): - e = errors.MissingBytes(99, 10, 8) - self.assertEqual("line 99: Unexpected EOF - expected 10 bytes, found 8", - str(e)) - - def test_MissingTerminator(self): - e = errors.MissingTerminator(99, '---') - self.assertEqual("line 99: Unexpected EOF - expected '---' terminator", - str(e)) - - def test_InvalidCommand(self): - e = errors.InvalidCommand(99, 'foo') - self.assertEqual("line 99: Invalid command 'foo'", - str(e)) - - def test_MissingSection(self): - e = errors.MissingSection(99, 'foo', 'bar') - self.assertEqual("line 99: Command foo is missing section bar", - str(e)) - - def test_BadFormat(self): - e = errors.BadFormat(99, 'foo', 'bar', 'xyz') - self.assertEqual("line 99: Bad format for section bar in " - "command foo: found 'xyz'", - str(e)) - - def test_InvalidTimezone(self): - e = errors.InvalidTimezone(99, 'aa:bb') - self.assertEqual('aa:bb', e.timezone) - self.assertEqual('', e.reason) - self.assertEqual("line 99: Timezone 'aa:bb' could not be converted.", - str(e)) - e = errors.InvalidTimezone(99, 'aa:bb', 'Non-numeric hours') - self.assertEqual('aa:bb', e.timezone) - self.assertEqual(' Non-numeric hours', e.reason) - self.assertEqual("line 99: Timezone 'aa:bb' could not be converted." - " Non-numeric hours", - str(e)) - - def test_UnknownDateFormat(self): - e = errors.UnknownDateFormat('aaa') - self.assertEqual("Unknown date format 'aaa'", str(e)) - - def test_MissingHandler(self): - e = errors.MissingHandler('foo') - self.assertEqual("Missing handler for command foo", str(e)) - - def test_UnknownFeature(self): - e = errors.UnknownFeature('aaa') - self.assertEqual("Unknown feature 'aaa' - try a later importer or " - "an earlier data format", str(e)) diff --git a/tests/test_filter_processor.py b/tests/test_filter_processor.py index ff8a09f..da5fdf2 100644 --- a/tests/test_filter_processor.py +++ b/tests/test_filter_processor.py @@ -18,13 +18,14 @@ from cStringIO import StringIO -from bzrlib import tests +from testtools import TestCase -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( parser, ) -from bzrlib.plugins.fastimport.processors.filter_processor import ( - FilterProcessor, + +from bzrlib.plugins.fastimport.processors import ( + filter_processor, ) @@ -103,17 +104,18 @@ M 644 :4 doc/index.txt """ -class TestCaseWithFiltering(tests.TestCase): +class TestCaseWithFiltering(TestCase): def assertFiltering(self, input, params, expected): outf = StringIO() - proc = FilterProcessor(None, params=params) + proc = filter_processor.FilterProcessor( + None, params=params) proc.outf = outf s = StringIO(input) p = parser.ImportParser(s) proc.process(p.iter_commands) out = outf.getvalue() - self.assertEqualDiff(expected, out) + self.assertEquals(expected, out) class TestNoFiltering(TestCaseWithFiltering): diff --git a/tests/test_generic_processor.py b/tests/test_generic_processor.py index 778a4aa..d479d09 100644 --- a/tests/test_generic_processor.py +++ b/tests/test_generic_processor.py @@ -21,9 +21,8 @@ from bzrlib import ( tests, ) -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( commands, - errors, ) from bzrlib.plugins.fastimport.processors import ( diff --git a/tests/test_head_tracking.py b/tests/test_head_tracking.py index 63712e0..e88e366 100644 --- a/tests/test_head_tracking.py +++ b/tests/test_head_tracking.py @@ -20,7 +20,7 @@ from cStringIO import StringIO from bzrlib import tests -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( commands, parser, ) diff --git a/tests/test_parser.py b/tests/test_parser.py index 4e1a1cd..18475e6 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -20,7 +20,7 @@ import StringIO from bzrlib import tests -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( errors, parser, ) |