Rev 2740: (robertc) Add records_written attribute to ContainerWriter's. (Robert Collins). in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Aug 22 02:33:00 BST 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2740
revision-id: pqm at pqm.ubuntu.com-20070822013256-6w9yisc450hwqf2b
parent: pqm at pqm.ubuntu.com-20070821175054-6pcl32ipl9eopnqw
parent: robertc at robertcollins.net-20070821231835-usf67px0chh80iag
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-08-22 02:32:56 +0100
message:
(robertc) Add records_written attribute to ContainerWriter's. (Robert Collins).
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/pack.py container.py-20070607160755-tr8zc26q18rn0jnb-1
bzrlib/tests/test_pack.py test_container.py-20070607160755-tr8zc26q18rn0jnb-2
------------------------------------------------------------
revno: 2698.1.2
merged: robertc at robertcollins.net-20070821231835-usf67px0chh80iag
parent: robertc at robertcollins.net-20070815011257-kxmspgdwk2l36h0x
parent: pqm at pqm.ubuntu.com-20070821175054-6pcl32ipl9eopnqw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: integration
timestamp: Wed 2007-08-22 09:18:35 +1000
message:
Merge bzr.dev to resolve conflicts.
------------------------------------------------------------
revno: 2698.1.1
merged: robertc at robertcollins.net-20070815011257-kxmspgdwk2l36h0x
parent: pqm at pqm.ubuntu.com-20070814221506-6rw0b0oolfdeqrdw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pack
timestamp: Wed 2007-08-15 11:12:57 +1000
message:
Add records_written attribute to ContainerWriter's. (Robert Collins).
=== modified file 'NEWS'
--- a/NEWS 2007-08-21 03:40:50 +0000
+++ b/NEWS 2007-08-21 23:18:35 +0000
@@ -61,6 +61,9 @@
stack to the log, which can be useful for gathering debug details.
(Robert Collins)
+ * ``bzrlib.pack.ContainerWriter`` now tracks how many records have been
+ added via a public attribute records_written. (Robert Collins)
+
bzr 0.90 2007-08-??
===================
=== modified file 'bzrlib/pack.py'
--- a/bzrlib/pack.py 2007-08-08 02:57:22 +0000
+++ b/bzrlib/pack.py 2007-08-15 01:12:57 +0000
@@ -59,7 +59,12 @@
class ContainerWriter(object):
- """A class for writing containers."""
+ """A class for writing containers.
+
+ :attribute records_written: The number of user records added to the
+ container. This does not count the prelude or suffix of the container
+ introduced by the begin() and end() methods.
+ """
def __init__(self, write_func):
"""Constructor.
@@ -69,6 +74,7 @@
"""
self._write_func = write_func
self.current_offset = 0
+ self.records_written = 0
def begin(self):
"""Begin writing a container."""
@@ -112,6 +118,7 @@
self.write_func("\n")
# Finally, the contents.
self.write_func(bytes)
+ self.records_written += 1
# return a memo of where we wrote data to allow random access.
return current_offset, self.current_offset - current_offset
=== modified file 'bzrlib/tests/test_pack.py'
--- a/bzrlib/tests/test_pack.py 2007-08-08 02:57:22 +0000
+++ b/bzrlib/tests/test_pack.py 2007-08-15 01:12:57 +0000
@@ -40,6 +40,13 @@
self.assertEqual('Bazaar pack format 1 (introduced in 0.18)\n',
output.getvalue())
+ def test_zero_records_written_after_begin(self):
+ """After begin is written, 0 records have been written."""
+ output = StringIO()
+ writer = pack.ContainerWriter(output.write)
+ writer.begin()
+ self.assertEqual(0, writer.records_written)
+
def test_end(self):
"""The end() method writes an End Marker record."""
output = StringIO()
@@ -49,6 +56,23 @@
self.assertEqual('Bazaar pack format 1 (introduced in 0.18)\nE',
output.getvalue())
+ def test_empty_end_does_not_add_a_record_to_records_written(self):
+ """The end() method does not count towards the records written."""
+ output = StringIO()
+ writer = pack.ContainerWriter(output.write)
+ writer.begin()
+ writer.end()
+ self.assertEqual(0, writer.records_written)
+
+ def test_non_empty_end_does_not_add_a_record_to_records_written(self):
+ """The end() method does not count towards the records written."""
+ output = StringIO()
+ writer = pack.ContainerWriter(output.write)
+ writer.begin()
+ writer.add_bytes_record('foo', names=[])
+ writer.end()
+ self.assertEqual(1, writer.records_written)
+
def test_add_bytes_record_no_name(self):
"""Add a bytes record with no name."""
output = StringIO()
@@ -131,6 +155,16 @@
errors.InvalidRecordError,
writer.add_bytes_record, 'abc', names=[('bad name', )])
+ def test_add_bytes_records_add_to_records_written(self):
+ """Adding a Bytes record increments the records_written counter."""
+ output = StringIO()
+ writer = pack.ContainerWriter(output.write)
+ writer.begin()
+ writer.add_bytes_record('foo', names=[])
+ self.assertEqual(1, writer.records_written)
+ writer.add_bytes_record('foo', names=[])
+ self.assertEqual(2, writer.records_written)
+
class TestContainerReader(tests.TestCase):
More information about the bazaar-commits
mailing list