summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2011-11-13 17:18:10 +0100
committerJelmer Vernooij <jelmer@samba.org>2011-11-13 18:06:06 +0100
commita4c2ba66cb420d35789e55f604599a84c8d570a7 (patch)
tree1843e93aa11e30bb36b7d24c967f7238d0c4a2f0 /lib
parent9250177ae71e37fe1a132fe198cac4f3512bc4c7 (diff)
downloadsamba-a4c2ba66cb420d35789e55f604599a84c8d570a7.tar.gz
samba-a4c2ba66cb420d35789e55f604599a84c8d570a7.tar.bz2
samba-a4c2ba66cb420d35789e55f604599a84c8d570a7.zip
testtools: Import new upstream snapshot.
Diffstat (limited to 'lib')
-rw-r--r--lib/testtools/NEWS5
-rw-r--r--lib/testtools/testtools/matchers.py2
-rw-r--r--lib/testtools/testtools/testresult/real.py10
-rw-r--r--lib/testtools/testtools/tests/test_matchers.py10
-rw-r--r--lib/testtools/testtools/tests/test_testcase.py4
-rw-r--r--lib/testtools/testtools/tests/test_testresult.py7
6 files changed, 30 insertions, 8 deletions
diff --git a/lib/testtools/NEWS b/lib/testtools/NEWS
index 5896b84c38..c56bdf7470 100644
--- a/lib/testtools/NEWS
+++ b/lib/testtools/NEWS
@@ -6,6 +6,11 @@ Changes and improvements to testtools_, grouped by release.
NEXT
~~~~
+Changes
+-------
+
+* Failed equality assertions now line up. (Jonathan Lange, #879339)
+
0.9.12
~~~~~~
diff --git a/lib/testtools/testtools/matchers.py b/lib/testtools/testtools/matchers.py
index 693a20befa..4725265f98 100644
--- a/lib/testtools/testtools/matchers.py
+++ b/lib/testtools/testtools/matchers.py
@@ -378,7 +378,7 @@ class _BinaryMismatch(Mismatch):
left = repr(self.expected)
right = repr(self.other)
if len(left) + len(right) > 70:
- return "%s:\nreference = %s\nactual = %s\n" % (
+ return "%s:\nreference = %s\nactual = %s\n" % (
self._mismatch_string, self._format(self.expected),
self._format(self.other))
else:
diff --git a/lib/testtools/testtools/testresult/real.py b/lib/testtools/testtools/testresult/real.py
index eb548dfa2c..aec6edb032 100644
--- a/lib/testtools/testtools/testresult/real.py
+++ b/lib/testtools/testtools/testresult/real.py
@@ -222,6 +222,10 @@ class MultiTestResult(TestResult):
TestResult.__init__(self)
self._results = list(map(ExtendedToOriginalDecorator, results))
+ def __repr__(self):
+ return '<%s (%s)>' % (
+ self.__class__.__name__, ', '.join(map(repr, self._results)))
+
def _dispatch(self, message, *args, **kwargs):
return tuple(
getattr(result, message)(*args, **kwargs)
@@ -354,6 +358,9 @@ class ThreadsafeForwardingResult(TestResult):
self.result = ExtendedToOriginalDecorator(target)
self.semaphore = semaphore
+ def __repr__(self):
+ return '<%s %r>' % (self.__class__.__name__, self.result)
+
def _add_result_with_semaphore(self, method, test, *args, **kwargs):
self.semaphore.acquire()
try:
@@ -433,6 +440,9 @@ class ExtendedToOriginalDecorator(object):
def __init__(self, decorated):
self.decorated = decorated
+ def __repr__(self):
+ return '<%s %r>' % (self.__class__.__name__, self.decorated)
+
def __getattr__(self, name):
return getattr(self.decorated, name)
diff --git a/lib/testtools/testtools/tests/test_matchers.py b/lib/testtools/testtools/tests/test_matchers.py
index ebdd4a9510..f327a34b05 100644
--- a/lib/testtools/testtools/tests/test_matchers.py
+++ b/lib/testtools/testtools/tests/test_matchers.py
@@ -155,7 +155,7 @@ class Test_BinaryMismatch(TestCase):
one_line_b = self._long_b.replace(_b("\n"), _b(" "))
mismatch = _BinaryMismatch(one_line_b, "!~", self._long_b)
self.assertEqual(mismatch.describe(),
- "%s:\nreference = %s\nactual = %s\n" % ("!~",
+ "%s:\nreference = %s\nactual = %s\n" % ("!~",
text_repr(one_line_b),
text_repr(self._long_b, multiline=True)))
@@ -163,14 +163,14 @@ class Test_BinaryMismatch(TestCase):
one_line_u = self._long_u.replace("\n", " ")
mismatch = _BinaryMismatch(one_line_u, "!~", self._long_u)
self.assertEqual(mismatch.describe(),
- "%s:\nreference = %s\nactual = %s\n" % ("!~",
+ "%s:\nreference = %s\nactual = %s\n" % ("!~",
text_repr(one_line_u),
text_repr(self._long_u, multiline=True)))
def test_long_mixed_strings(self):
mismatch = _BinaryMismatch(self._long_b, "!~", self._long_u)
self.assertEqual(mismatch.describe(),
- "%s:\nreference = %s\nactual = %s\n" % ("!~",
+ "%s:\nreference = %s\nactual = %s\n" % ("!~",
text_repr(self._long_b, multiline=True),
text_repr(self._long_u, multiline=True)))
@@ -178,7 +178,7 @@ class Test_BinaryMismatch(TestCase):
obj = object()
mismatch = _BinaryMismatch(self._long_b, "!~", obj)
self.assertEqual(mismatch.describe(),
- "%s:\nreference = %s\nactual = %s\n" % ("!~",
+ "%s:\nreference = %s\nactual = %s\n" % ("!~",
text_repr(self._long_b, multiline=True),
repr(obj)))
@@ -186,7 +186,7 @@ class Test_BinaryMismatch(TestCase):
obj = object()
mismatch = _BinaryMismatch(self._long_u, "!~", obj)
self.assertEqual(mismatch.describe(),
- "%s:\nreference = %s\nactual = %s\n" % ("!~",
+ "%s:\nreference = %s\nactual = %s\n" % ("!~",
text_repr(self._long_u, multiline=True),
repr(obj)))
diff --git a/lib/testtools/testtools/tests/test_testcase.py b/lib/testtools/testtools/tests/test_testcase.py
index 52f93c3c52..bb0aba6496 100644
--- a/lib/testtools/testtools/tests/test_testcase.py
+++ b/lib/testtools/testtools/tests/test_testcase.py
@@ -550,7 +550,7 @@ class TestAssertions(TestCase):
expected_error = '\n'.join([
'!=:',
'reference = %s' % pformat(a),
- 'actual = %s' % pformat(b),
+ 'actual = %s' % pformat(b),
': ' + message,
])
self.assertFails(expected_error, self.assertEqual, a, b, message)
@@ -575,7 +575,7 @@ class TestAssertions(TestCase):
'a',
repr('\xa7')[1:-1],
"'''",
- 'actual = %r' % (b,),
+ 'actual = %r' % (b,),
': ' + message,
])
self.assertFails(expected_error, self.assertEqual, a, b, message)
diff --git a/lib/testtools/testtools/tests/test_testresult.py b/lib/testtools/testtools/tests/test_testresult.py
index a241788bea..69d2d6e2de 100644
--- a/lib/testtools/testtools/tests/test_testresult.py
+++ b/lib/testtools/testtools/tests/test_testresult.py
@@ -431,6 +431,13 @@ class TestMultiTestResult(TestCase):
self.assertEqual(expectedEvents, self.result1._events)
self.assertEqual(expectedEvents, self.result2._events)
+ def test_repr(self):
+ self.assertEqual(
+ '<MultiTestResult (%r, %r)>' % (
+ ExtendedToOriginalDecorator(self.result1),
+ ExtendedToOriginalDecorator(self.result2)),
+ repr(self.multiResult))
+
def test_empty(self):
# Initializing a `MultiTestResult` doesn't do anything to its
# `TestResult`s.