Rev 1300: Add new easy to use commit editor for tests. in http://people.samba.org/bzr/jelmer/bzr-svn/0.4
Jelmer Vernooij
jelmer at samba.org
Mon Jun 23 01:27:36 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-svn/0.4
------------------------------------------------------------
revno: 1300
revision-id: jelmer at samba.org-20080623002734-oxgti3m9yova9j7a
parent: jelmer at samba.org-20080622235714-27r60juzjgbkz0ov
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Mon 2008-06-23 02:27:34 +0200
message:
Add new easy to use commit editor for tests.
modified:
tests/__init__.py __init__.py-20060508151940-e9f4d914801a2535
tests/test_logwalker.py test_logwalker.py-20060622141944-pkocc3rj8g62ukbi-1
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-06-22 22:44:40 +0000
+++ b/tests/__init__.py 2008-06-23 00:27:34 +0000
@@ -33,6 +33,65 @@
from bzrlib.plugins.svn.client import Client
from bzrlib.plugins.svn.ra import Auth, RemoteAccess, txdelta_send_stream
+class TestFileEditor(object):
+ def __init__(self, file):
+ self.file = file
+
+ def change_prop(self, name, value):
+ self.file.change_prop(name, value)
+
+ def modify(self, contents=None):
+ if contents is None:
+ contents = osutils.rand_chars(100)
+ txdelta = self.apply_textdelta()
+ txdelta_send_stream(StringIO(contents), txdelta)
+
+ def close(self):
+ self.file.close()
+
+
+class TestDirEditor(object):
+ def __init__(self, dir, baseurl, revnum):
+ self.dir = dir
+ self.baseurl = baseurl
+ self.revnum = revnum
+
+ def close(self):
+ self.dir.close()
+
+ def change_prop(self, name, value):
+ self.dir.change_prop(name, value)
+
+ def open_dir(self, path):
+ return TestDirEditor(self.dir.open_directory(path, -1), self.baseurl, self.revnum)
+
+ def open_file(self, path):
+ return TestFileEditor(self.dir.open_file(path, -1))
+
+ def add_dir(self, path, copyfrom_path=None, copyfrom_rev=-1):
+ if copyfrom_path is not None:
+ copyfrom_path = urlutils.join(self.baseurl, copyfrom_path)
+ if copyfrom_path is not None and copyfrom_rev == -1:
+ copyfrom_rev = self.revnum
+ return TestDirEditor(self.dir.add_directory(path, copyfrom_path, copyfrom_rev), self.baseurl, self.revnum)
+
+ def add_file(self, path, copyfrom_path=None, copyfrom_rev=-1):
+ return TestFileEditor(self.dir.add_file(path, copyfrom_path, copyfrom_rev))
+
+ def delete(self, path):
+ self.dir.delete_path(path)
+
+
+class TestCommitEditor(TestDirEditor):
+ def __init__(self, editor, baseurl, revnum):
+ self.editor = editor
+ TestDirEditor.__init__(self, self.editor.open_root(), baseurl, revnum)
+
+ def close(self):
+ TestDirEditor.close(self)
+ self.editor.close()
+
+
class TestCaseWithSubversionRepository(TestCaseInTempDir):
"""A test case that provides the ability to build Subversion
repositories."""
@@ -245,6 +304,11 @@
"""
return repos.Repository(relpath).fs()
+ def get_commit_editor(self, url, message="Test commit"):
+ ra = RemoteAccess(url.encode("utf-8"))
+ revnum = ra.get_latest_revnum()
+ return TestCommitEditor(ra.get_commit_editor({"svn:log": message}), ra.url, revnum)
+
def commit_editor(self, url, message="Test commit"):
ra = RemoteAccess(url.encode('utf8'))
class CommitEditor(object):
=== modified file 'tests/test_logwalker.py'
--- a/tests/test_logwalker.py 2008-06-22 23:44:07 +0000
+++ b/tests/test_logwalker.py 2008-06-23 00:27:34 +0000
@@ -39,9 +39,9 @@
def test_get_branch_log(self):
repos_url = self.make_repository("a")
- cb = self.commit_editor(repos_url)
- cb.add_file("foo")
- cb.done()
+ cb = self.get_commit_editor(repos_url)
+ cb.add_file("foo").close()
+ cb.close()
walker = self.get_log_walker(transport=SvnRaTransport(repos_url))
@@ -49,17 +49,17 @@
def test_get_branch_follow_branch(self):
repos_url = self.make_repository("a")
- cb = self.commit_editor(repos_url)
- cb.add_dir("trunk")
- cb.done()
+ cb = self.get_commit_editor(repos_url)
+ cb.add_dir("trunk").close()
+ cb.close()
- cb = self.commit_editor(repos_url)
- cb.add_dir("branches")
- cb.done()
+ cb = self.get_commit_editor(repos_url)
+ cb.add_dir("branches").close()
+ cb.close()
- cb = self.commit_editor(repos_url)
- cb.add_dir("branches/foo", "trunk")
- cb.done()
+ cb = self.get_commit_editor(repos_url)
+ cb.add_dir("branches/foo", "trunk").close()
+ cb.close()
walker = self.get_log_walker(transport=SvnRaTransport(repos_url))
@@ -67,18 +67,19 @@
def test_get_branch_follow_branch_changing_parent(self):
repos_url = self.make_repository("a")
- cb = self.commit_editor(repos_url)
- cb.add_dir("trunk")
- cb.add_file("trunk/foo")
- cb.done()
-
- cb = self.commit_editor(repos_url)
- cb.add_dir("branches")
- cb.done()
-
- cb = self.commit_editor(repos_url)
- cb.add_dir("branches/abranch", "trunk")
- cb.done()
+ cb = self.get_commit_editor(repos_url)
+ d = cb.add_dir("trunk")
+ d.add_file("trunk/foo").close()
+ d.close()
+ cb.close()
+
+ cb = self.get_commit_editor(repos_url)
+ cb.add_dir("branches").close()
+ cb.close()
+
+ cb = self.get_commit_editor(repos_url)
+ cb.add_dir("branches/abranch", "trunk").close()
+ cb.close()
walker = self.get_log_walker(transport=SvnRaTransport(repos_url))
More information about the bazaar-commits
mailing list