Rev 22: Initial work on a GitCommitBuilder to make the test suite run in no-glacial time. in http://bzr.arbash-meinel.com/plugins/git
John Arbash Meinel
john at arbash-meinel.com
Fri Nov 9 06:08:17 GMT 2007
At http://bzr.arbash-meinel.com/plugins/git
------------------------------------------------------------
revno: 22
revision-id:john at arbash-meinel.com-20071109060811-toeslo9r1gnn24rr
parent: john at arbash-meinel.com-20071109045315-76bp6gmezv29hule
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: git
timestamp: Fri 2007-11-09 01:08:11 -0500
message:
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
added:
tests/test_builder.py test_builder.py-20071109060756-yqmwmyqdr3pqeh3s-1
modified:
tests/__init__.py __init__.py-20070202180350-njrb42t7fnv35d1k-2
-------------- next part --------------
=== added file 'tests/test_builder.py'
--- a/tests/test_builder.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_builder.py 2007-11-09 06:08:11 +0000
@@ -0,0 +1,90 @@
+# Copyright (C) 2007 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 our ability to build up test repositories"""
+
+from cStringIO import StringIO
+
+from bzrlib.plugins.git import tests
+
+
+class TestCommitBuilder(tests.TestCase):
+
+ def test__create_blob(self):
+ stream = StringIO()
+ builder = tests.GitCommitBuilder(stream)
+ self.assertEqual(1, builder._create_blob('foo\nbar\n'))
+ self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
+ stream.getvalue())
+
+ def test_set_file(self):
+ stream = StringIO()
+ builder = tests.GitCommitBuilder(stream)
+ builder.set_file('foobar', 'foo\nbar\n', False)
+ self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
+ stream.getvalue())
+ self.assertEqual(['M 100644 :1 foobar\n'], builder.commit_info)
+
+ def test_set_file_unicode(self):
+ stream = StringIO()
+ builder = tests.GitCommitBuilder(stream)
+ builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
+ self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
+ stream.getvalue())
+ self.assertEqual(['M 100644 :1 f\xc2\xb5/bar\n'], builder.commit_info)
+
+ def test_set_file_executable(self):
+ stream = StringIO()
+ builder = tests.GitCommitBuilder(stream)
+ builder.set_file(u'f\xb5/bar', 'contents\nbar\n', True)
+ self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
+ stream.getvalue())
+ self.assertEqual(['M 100755 :1 f\xc2\xb5/bar\n'], builder.commit_info)
+
+ def test_set_link(self):
+ stream = StringIO()
+ builder = tests.GitCommitBuilder(stream)
+ builder.set_link(u'f\xb5/bar', 'link/contents')
+ self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n',
+ stream.getvalue())
+ self.assertEqual(['M 120000 :1 f\xc2\xb5/bar\n'], builder.commit_info)
+
+ def test_delete_entry(self):
+ stream = StringIO()
+ builder = tests.GitCommitBuilder(stream)
+ builder.delete_entry(u'path/to/f\xb5')
+ self.assertEqual(['D path/to/f\xc2\xb5\n'], builder.commit_info)
+
+ def test_add_and_commit(self):
+ stream = StringIO()
+ builder = tests.GitCommitBuilder(stream)
+
+ builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
+ self.assertEqual(2, builder.commit('refs/head/master',
+ 'Joe Foo <joe at foo.com>',
+ u'committing f\xb5/bar',
+ timestamp=1194586400,
+ timezone='+0100'))
+ self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n'
+ 'commit refs/head/master\n'
+ 'mark :2\n'
+ 'committer Joe Foo <joe at foo.com> 1194586400 +0100\n'
+ 'data 18\n'
+ 'committing f\xc2\xb5/bar'
+ '\n'
+ 'M 100644 :1 f\xc2\xb5/bar\n'
+ '\n',
+ stream.getvalue())
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2007-11-09 04:17:01 +0000
+++ b/tests/__init__.py 2007-11-09 06:08:11 +0000
@@ -17,6 +17,7 @@
"""The basic test suite for bzr-git."""
import subprocess
+import time
from bzrlib import (
tests,
@@ -57,12 +58,79 @@
return out
+class GitBranchBuilder(object):
+
+ def __init__(self, stream):
+ self.commit_info = []
+ self.stream = stream
+ self._counter = 0
+ self._branch = 'refs/head/master'
+
+ def set_branch(self, branch):
+ """Set the branch we are committing."""
+ self._branch = branch
+
+ def _create_blob(self, content):
+ self._counter += 1
+ self.stream.write('blob\n')
+ self.stream.write('mark :%d\n' % (self._counter,))
+ self.stream.write('data %d\n' % (len(content),))
+ self.stream.write(content)
+ self.stream.write('\n')
+ return self._counter
+
+ def set_file(self, path, content, executable):
+ """Create or update content at a given path."""
+ mark = self._create_blob(content)
+ if executable:
+ mode = '100755'
+ else:
+ mode = '100644'
+ self.commit_info.append('M %s :%d %s\n'
+ % (mode, mark, path.encode('utf-8')))
+
+ def set_link(self, path, link_target):
+ """Create or update a link at a given path."""
+ mark = self._create_blob(link_target)
+ self.commit_info.append('M 120000 :%d %s\n'
+ % (mark, path.encode('utf-8')))
+
+ def delete_entry(self, path):
+ """This will delete files or symlinks at the given location."""
+ self.commit_info.append('D %s\n' % (path.encode('utf-8'),))
+
+ def commit(self, committer, message, timestamp=None,
+ timezone='+0000', author=None):
+ self._counter += 1
+ mark = self._counter
+ self.stream.write('commit %s\n' % (branch,))
+ self.stream.write('mark :%d\n' % (mark,))
+ self.stream.write('committer %s %s %s\n'
+ % (committer, timestamp, timezone))
+ message = message.encode('UTF-8')
+ self.stream.write('data %d\n' % (len(message),))
+ self.stream.write(message)
+ self.stream.write('\n')
+ self.stream.writelines(self.commit_info)
+ self.stream.write('\n')
+ self.commit_info = []
+ return mark
+
+
+class GitBranchBuilder(object):
+ """This uses git-fast-import to build up something directly."""
+
+ def __init__(self, git_dir):
+ self.git_dir = git_dir
+
+
def test_suite():
loader = tests.TestLoader()
suite = tests.TestSuite()
testmod_names = [
+ 'test_builder',
'test_git_branch',
'test_git_dir',
'test_git_repository',
More information about the bazaar-commits
mailing list