Rev 3829: (mbp) fix up branchbuilder doctests in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Nov 11 03:35:27 GMT 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3829
revision-id: pqm at pqm.ubuntu.com-20081111033523-xbz2o8weoyl4d0l7
parent: pqm at pqm.ubuntu.com-20081111023942-ir0du8iel76giykh
parent: mbp at sourcefrog.net-20081111023157-ylori8pmnbsef6hm
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-11-11 03:35:23 +0000
message:
(mbp) fix up branchbuilder doctests
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branchbuilder.py branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
------------------------------------------------------------
revno: 3825.3.2
revision-id: mbp at sourcefrog.net-20081111023157-ylori8pmnbsef6hm
parent: mbp at sourcefrog.net-20081111011928-g79d2s0eqx8zrwnh
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: branchbuilder
timestamp: Tue 2008-11-11 12:31:57 +1000
message:
Correct example of branchbuilder and change to a doctest, and refactor
modified:
bzrlib/branchbuilder.py branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
------------------------------------------------------------
revno: 3825.3.1
revision-id: mbp at sourcefrog.net-20081111011928-g79d2s0eqx8zrwnh
parent: pqm at pqm.ubuntu.com-20081107225426-gezbao014attrca8
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: branchbuilder
timestamp: Tue 2008-11-11 11:19:28 +1000
message:
selftest errors if modules said to have doctests don't have them
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
=== modified file 'NEWS'
--- a/NEWS 2008-11-11 02:39:42 +0000
+++ b/NEWS 2008-11-11 03:35:23 +0000
@@ -30,11 +30,15 @@
DOCUMENTATION:
API CHANGES:
+
* Transport implementations must provide copy_tree_to_transport. A default
implementation is provided for Transport subclasses.
TESTING:
+ * ``bzr selftest`` now fails if no doctests are found in a module
+ that's expected to have them. (Martin Pool)
+
INTERNALS:
=== modified file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py 2008-07-29 16:34:09 +0000
+++ b/bzrlib/branchbuilder.py 2008-11-11 02:31:57 +0000
@@ -16,11 +16,16 @@
"""Utility for create branches with particular contents."""
-from bzrlib import bzrdir, errors, memorytree
+from bzrlib import (
+ bzrdir,
+ commit,
+ errors,
+ memorytree,
+ )
class BranchBuilder(object):
- """A BranchBuilder aids creating Branches with particular shapes.
+ r"""A BranchBuilder aids creating Branches with particular shapes.
The expected way to use BranchBuilder is to construct a
BranchBuilder on the transport you want your branch on, and then call
@@ -30,14 +35,19 @@
real data.
For instance:
- builder = BranchBuilder(self.get_transport().clone('relpath'))
- builder.start_series()
- builder.build_snapshot('rev-id', [],
- [('add', ('filename', 'f-id', 'file', 'content\n'))])
- builder.build_snapshot('rev2-id', ['rev-id'],
- [('modify', ('f-id', 'new-content\n'))])
- builder.finish_series()
- branch = builder.get_branch()
+
+ >>> from bzrlib.transport.memory import MemoryTransport
+ >>> builder = BranchBuilder(MemoryTransport("memory:///"))
+ >>> builder.start_series()
+ >>> builder.build_snapshot('rev-id', None, [
+ ... ('add', ('', 'root-id', 'directory', '')),
+ ... ('add', ('filename', 'f-id', 'file', 'content\n'))])
+ 'rev-id'
+ >>> builder.build_snapshot('rev2-id', ['rev-id'],
+ ... [('modify', ('f-id', 'new-content\n'))])
+ 'rev2-id'
+ >>> builder.finish_series()
+ >>> branch = builder.get_branch()
:ivar _tree: This is a private member which is not meant to be modified by
users of this class. While a 'series' is in progress, it should hold a
@@ -71,10 +81,18 @@
tree.lock_write()
try:
tree.add('')
- return tree.commit('commit %d' % (self._branch.revno() + 1))
+ return self._do_commit(tree)
finally:
tree.unlock()
+ def _do_commit(self, tree, message=None, **kwargs):
+ reporter = commit.NullCommitReporter()
+ if message is None:
+ message = u'commit %d' % (self._branch.revno() + 1,)
+ return tree.commit(message,
+ reporter=reporter,
+ **kwargs)
+
def _move_branch_pointer(self, new_revision_id):
"""Point self._branch to a different revision id."""
self._branch.lock_write()
@@ -192,10 +210,7 @@
tree.add(to_add_files, to_add_file_ids, to_add_kinds)
for file_id, content in new_contents.iteritems():
tree.put_file_bytes_non_atomic(file_id, content)
-
- if message is None:
- message = u'commit %d' % (self._branch.revno() + 1,)
- return tree.commit(message, rev_id=revision_id)
+ return self._do_commit(tree, message=message, rev_id=revision_id)
finally:
tree.unlock()
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-11-03 19:01:14 +0000
+++ b/bzrlib/tests/__init__.py 2008-11-11 02:31:57 +0000
@@ -2953,14 +2953,13 @@
modules_to_doctest = [
'bzrlib',
- 'bzrlib.errors',
+ 'bzrlib.branchbuilder',
'bzrlib.export',
'bzrlib.inventory',
'bzrlib.iterablefile',
'bzrlib.lockdir',
'bzrlib.merge3',
'bzrlib.option',
- 'bzrlib.store',
'bzrlib.symbol_versioning',
'bzrlib.tests',
'bzrlib.timestamp',
@@ -2976,6 +2975,8 @@
except ValueError, e:
print '**failed to get doctest for: %s\n%s' % (mod, e)
raise
+ if len(doc_suite._tests) == 0:
+ raise errors.BzrError("no doctests found in %s" % (mod,))
suite.addTest(doc_suite)
default_encoding = sys.getdefaultencoding()
More information about the bazaar-commits
mailing list