From a3ce77ac8876ff59e451ec9d2917cbb0a583e7dd Mon Sep 17 00:00:00 2001 From: Tim Cuthbertson Date: Mon, 4 Jun 2012 22:08:54 +1000 Subject: [PATCH] fall back to repr() when we can't actually decode a failure message, fixes #14 --- Makefile | 5 ++++- encoding_test.py | 7 +++++++ rednose.py | 9 ++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 encoding_test.py diff --git a/Makefile b/Makefile index 428a182..b32edc8 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ rednose-local.xml: rednose.xml 0launch http://gfxmonk.net/dist/0install/0local.xml rednose.xml rednose-local.xml test: rednose-local.xml - 0launch http://0install.net/2008/interfaces/0test.xml rednose-local.xml http://repo.roscidus.com/python/python 2.7.2-7 3.2.2-0 + 0launch http://0install.net/2008/interfaces/0test.xml \ + rednose-local.xml \ + http://repo.roscidus.com/python/python \ + 2.7.3-6 3.2.3-5 .PHONY: 0 pypi diff --git a/encoding_test.py b/encoding_test.py new file mode 100644 index 0000000..b9bde14 --- /dev/null +++ b/encoding_test.py @@ -0,0 +1,7 @@ +# vim: fileencoding=utf-8: + +#NOTE: this file does *not* import unicode_literals, +# so the assertion message is actually just utf-8 bytes + +def test(): + assert False, "รค" diff --git a/rednose.py b/rednose.py index 1bdaa2b..45e8ff3 100644 --- a/rednose.py +++ b/rednose.py @@ -44,7 +44,14 @@ skip = 'skipped' line_length = 77 PY3 = sys.version_info[0] >= 3 -to_unicode = str if PY3 else unicode +if PY3: + to_unicode = str +else: + def to_unicode(s): + try: + return unicode(s) + except UnicodeDecodeError: + return unicode(repr(str(s))) BLACKLISTED_WRITERS = [ 'nose[\\/]result\\.pyc?$',