[MERGE] don't report malformed bundles as NotABundle
John Arbash Meinel
john at arbash-meinel.com
Wed Jun 21 17:10:18 BST 2006
Aaron Bentley wrote:
> Hi all,
>
> This bundle fixes a regression in the bundle handling introduced by my
> recent refactoring. The regression meant that NotABundle was raised for
> bundles with malformed headers, instead of MalformedBundle.
>
> This fixes the bug, and specifically ensures that bundles with crlf line
> endings do not cause NotABundle to be raised.
>
> Aaron
...
=== modified file bzrlib/bundle/serializer/__init__.py //
last-changed:abentley
... @panoramicfeedback.com-20060621150240-f0e4981af656ddec
--- bzrlib/bundle/serializer/__init__.py
+++ bzrlib/bundle/serializer/__init__.py
@@ -52,6 +52,8 @@
if m:
version = m.group('version')
break
+ elif line.startswith(BUNDLE_HEADER):
+ raise errors.MalformedHeader()
m = CHANGESET_OLD_HEADER_RE.match(line)
if m:
version = m.group('version')
...
I don't think 'assertNotRaises' is really what we want.
I think we want a fixed exception to be raised (MalformedBundle). As far
as the "doesn't raise anything" case, that is already handled by *not*
catching the exception at all.
+ def assertNotRaises(self, exception, callable, *args):
+ """A call may not raise the given exception.
+
+ It may raise a different exception, or no exception.
+ """
+ try:
+ callable(*args)
+ except exception:
+ self.fail("%s was raised." % exception.__name__)
+ except:
+ pass
+
def _startLogFile(self):
"""Send bzr and test log messages to a temporary file.
...
+ def test_malformed(self):
+ self.assertRaises(BadBundle, read_bundle,
+ StringIO('# Bazaar revision bundle v'))
+
+ def test_crlf_bundle(self):
+ self.assertNotRaises(NotABundle, read_bundle,
+ StringIO('# Bazaar revision bundle v0.7\r\n'))
+
Here I think we want to 'assertRaises(BadBundle, ...)'
and then we wouldn't need this test.
+class TestAssertions(TestCase):
+
+ def test_assert_not_raises(self):
+ class OtherException(Exception):
+ pass
+
+ class ThisException(Exception):
+ pass
+
+ def raiser(arg):
+ if arg == "nothing":
+ return
+ if arg == "other":
+ raise OtherException()
+ if arg == "this":
+ raise ThisException()
+
+ self.assertNotRaises(ThisException, raiser, 'nothing')
+ self.assertNotRaises(ThisException, raiser, 'other')
+ self.assertRaises(AssertionError,
+ self.assertNotRaises, ThisException, raiser, 'this')
+
+
class MetaTestLog(TestCase):
def test_logging(self):
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060621/8670b297/attachment.pgp
More information about the bazaar
mailing list