From d6c949b0748014587a05d2af1c2b4770d16d68a9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Oct 2011 12:20:19 +0200 Subject: testtools: Import new upstream snapshot. Autobuild-User: Jelmer Vernooij Autobuild-Date: Mon Oct 3 13:54:06 CEST 2011 on sn-devel-104 --- lib/testtools/doc/for-test-authors.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/testtools/doc/for-test-authors.rst') diff --git a/lib/testtools/doc/for-test-authors.rst b/lib/testtools/doc/for-test-authors.rst index eec98b14f8..04c4be6b0d 100644 --- a/lib/testtools/doc/for-test-authors.rst +++ b/lib/testtools/doc/for-test-authors.rst @@ -717,7 +717,7 @@ generates. Here's an example mismatch:: self.remainder = remainder def describe(self): - return "%s is not divisible by %s, %s remains" % ( + return "%r is not divisible by %r, %r remains" % ( self.number, self.divider, self.remainder) def get_details(self): @@ -738,11 +738,19 @@ in the Matcher itself like this:: remainder = actual % self.divider if remainder != 0: return Mismatch( - "%s is not divisible by %s, %s remains" % ( + "%r is not divisible by %r, %r remains" % ( actual, self.divider, remainder)) else: return None +When writing a ``describe`` method or constructing a ``Mismatch`` object the +code should ensure it only emits printable unicode. As this output must be +combined with other text and forwarded for presentation, letting through +non-ascii bytes of ambiguous encoding or control characters could throw an +exception or mangle the display. In most cases simply avoiding the ``%s`` +format specifier and using ``%r`` instead will be enough. For examples of +more complex formatting see the ``testtools.matchers`` implementatons. + Details ======= -- cgit