DocTestMatches error when 'actual' is unicode

Bug #764170 reported by Ian Booth
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
testtools
Fix Released
Critical
Martin Packman

Bug Description

When TestCase.assertThat is invoked with a unicode string and a DocTestMatches instance, the _with_nl() call made by the DocTestMatches.match() method fails if the argument 'actual' is a unicode string.

class MyTestCase(TestCase)
  def myTest(self):
     foo = u"foo\u2026"
    self.assertThat(foo, DocTestMatches(foo))

Trackback:

  File "/home/ian/projects/lp-sourcedeps/eggs/testtools-0.9.10-py2.6.egg/testtools/testcase.py", line 341, in assertThat
    mismatch = matcher.match(matchee)
  File "/home/ian/projects/lp-sourcedeps/eggs/testtools-0.9.10-py2.6.egg/testtools/matchers.py", line 175, in match
    with_nl = self._with_nl(actual)
  File "/home/ian/projects/lp-sourcedeps/eggs/testtools-0.9.10-py2.6.egg/testtools/matchers.py", line 169, in _with_nl
    result = str(actual)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 3: ordinal not in range(128)
------------

Tags: unicode

Related branches

Revision history for this message
Jonathan Lange (jml) wrote :

Thanks. Will try to fix this soon.

Changed in testtools:
status: New → Triaged
importance: Undecided → Critical
Revision history for this message
Martin Packman (gz) wrote :

This is a distinct issue from bug 672056 I believe, though one aspect of that, bug 804122, also interferes with the fix here.

An additional complication on some Python versions is bug 804127, and the ones without that problem have a dodgy doctest._indent method that encodes any unicode given in output_difference.

Jonathan Lange (jml)
tags: added: unicode
Jonathan Lange (jml)
Changed in testtools:
status: Triaged → In Progress
assignee: nobody → Martin [gz] (gz)
Jonathan Lange (jml)
Changed in testtools:
status: In Progress → Fix Committed
milestone: none → next
Jonathan Lange (jml)
Changed in testtools:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.