Message153518
| Author |
ezio.melotti |
| Recipients |
ezio.melotti, jaap.karssenberg, michael.foord, r.david.murray |
| Date |
2012年02月17日.00:23:33 |
| SpamBayes Score |
1.4304877e-08 |
| Marked as misclassified |
No |
| Message-id |
<1329438214.0.0.844924574792.issue14025@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
If you really want the diff you could use assertMultiLineEqual, but even on Python 2 you shouldn't mix str and unicode. I would rather fix the code to return unicode than using assertMultilineEqual to get a diff between str and unicode. Moreover assertMultiLineEqual only works if the str happens to be ASCII-only:
>>> class MyTest(TestCase):
... def test_foo(self):
... self.assertMultiLineEqual('bàr', u'bàz')
...
>>> unittest.main(exit=False)
E
======================================================================
ERROR: test_foo (__main__.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<stdin>", line 3, in test_foo
File "/home/wolf/dev/py/2.7/Lib/unittest/case.py", line 920, in assertMultiLineEqual
diff = '\n' + ''.join(difflib.ndiff(firstlines, secondlines))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)
---------------------------------------------------------------------- |
|