integrate the changes from the fix_encoding branch, with ostensible (but untested as yet) python 3 compatibility
This commit is contained in:
parent
c1bb22b3cd
commit
0c17fc4366
16
rednose.py
16
rednose.py
|
@ -27,7 +27,8 @@
|
|||
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import os
|
||||
from __future__ import print_function
|
||||
import os, sys
|
||||
import linecache
|
||||
import re
|
||||
import time
|
||||
|
@ -42,6 +43,9 @@ success = 'passed'
|
|||
skip = 'skipped'
|
||||
line_length = 77
|
||||
|
||||
PY3 = sys.version_info[0] >= 3
|
||||
to_unicode = str if PY3 else unicode
|
||||
|
||||
BLACKLISTED_WRITERS = [
|
||||
'nose[\\/]result\\.pyc?$',
|
||||
'unittest[\\/]runner\\.pyc?$'
|
||||
|
@ -105,7 +109,7 @@ class RedNose(nose.plugins.Plugin):
|
|||
self._in_test = False
|
||||
|
||||
def _format_test_name(self, test):
|
||||
return test.shortDescription() or str(test)
|
||||
return test.shortDescription() or to_unicode(test)
|
||||
|
||||
def prepareTestResult(self, result):
|
||||
result.stream = FilteringStream(self.stream, BLACKLISTED_WRITERS)
|
||||
|
@ -282,7 +286,7 @@ class RedNose(nose.plugins.Plugin):
|
|||
return '\n'.join(ret)
|
||||
|
||||
def _fmt_message(self, exception, color):
|
||||
orig_message_lines = str(exception).splitlines()
|
||||
orig_message_lines = to_unicode(exception).splitlines()
|
||||
|
||||
if len(orig_message_lines) == 0:
|
||||
return ''
|
||||
|
@ -339,9 +343,9 @@ class FilteringStream(object):
|
|||
print >> sys.stderr, "REDNOSE_DEBUG: got write call from %s, should_filter = %s" % (
|
||||
filename, should_filter)
|
||||
return should_filter
|
||||
except StandardError, e:
|
||||
except StandardError as e:
|
||||
if REDNOSE_DEBUG:
|
||||
print >> sys.stderr, "\nError in rednose filtering: %s" % (e,)
|
||||
print("\nError in rednose filtering: %s" % (e,), file=sys.stderr)
|
||||
traceback.print_exc(sys.stderr)
|
||||
return False
|
||||
|
||||
|
@ -356,5 +360,5 @@ class FilteringStream(object):
|
|||
# pass non-known methods through to self.__stream
|
||||
def __getattr__(self, name):
|
||||
if REDNOSE_DEBUG:
|
||||
print >> sys.stderr, "REDNOSE_DEBUG: getting attr %s" % (name,)
|
||||
print("REDNOSE_DEBUG: getting attr %s" % (name,), file=sys.stderr)
|
||||
return getattr(self.__stream, name)
|
||||
|
|
|
@ -95,7 +95,7 @@ nosetests --no-color
|
|||
<environment name="NOSE_REDNOSE" value="1"/>
|
||||
<environment insert="" name="PYTHONPATH"/>
|
||||
<command name="run">
|
||||
<runner interface="http://gfxmonk.net/dist/0install/nosetests-plugin-resolver.xml"/>
|
||||
<runner interface="http://gfxmonk.net/dist/0install/nosetests-runner.xml"/>
|
||||
</command>
|
||||
<requires interface="http://gfxmonk.net/dist/0install/python-termstyle.xml">
|
||||
<version not-before="0.1.7"/>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# vim: set fileencoding=utf-8 :
|
||||
from __future__ import print_function
|
||||
import unittest
|
||||
|
||||
|
@ -14,6 +15,9 @@ class SomeTest(unittest.TestCase):
|
|||
|
||||
def test_error(self):
|
||||
raise RuntimeError("things went south\nand here's a second line!")
|
||||
|
||||
def test_utf8(self):
|
||||
self.assertEqual(u'café', u'abc')
|
||||
|
||||
def test_skip(self):
|
||||
import nose
|
||||
|
@ -23,4 +27,3 @@ class SomeTest(unittest.TestCase):
|
|||
"""It's got a long description, you see?"""
|
||||
self.fail()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue