Rev 2556: Better messages from assertContainsRe in http://sourcefrog.net/bzr/dlock

Martin Pool mbp at sourcefrog.net
Wed Jun 27 07:33:32 BST 2007


At http://sourcefrog.net/bzr/dlock

------------------------------------------------------------
revno: 2556
revision-id: mbp at sourcefrog.net-20070627063331-42nj4x28k15zmqan
parent: pqm at pqm.ubuntu.com-20070627023032-h316n5k05g1nqqem
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: dlock
timestamp: Wed 2007-06-27 16:33:31 +1000
message:
  Better messages from assertContainsRe
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-06-27 01:43:03 +0000
+++ b/bzrlib/tests/__init__.py	2007-06-27 06:33:31 +0000
@@ -839,8 +839,14 @@
     def assertContainsRe(self, haystack, needle_re):
         """Assert that a contains something matching a regular expression."""
         if not re.search(needle_re, haystack):
-            raise AssertionError('pattern "%r" not found in "%r"'
-                    % (needle_re, haystack))
+            if '\n' in haystack or len(haystack) > 60:
+                # a long string, format it in a more readable way
+                raise AssertionError(
+                        'pattern "%s" not found in\n"""\\\n%s"""\n'
+                        % (needle_re, haystack))
+            else:
+                raise AssertionError('pattern "%s" not found in "%s"'
+                        % (needle_re, haystack))
 
     def assertNotContainsRe(self, haystack, needle_re):
         """Assert that a does not match a regular expression"""




More information about the bazaar-commits mailing list