Handle filenames that can't be decoded to unicode.
Another Python2 specific case to handle.
This commit is contained in:
parent
652c95d267
commit
9df5538af8
|
@ -380,7 +380,7 @@ class StackSummary(list):
|
||||||
for frame in self:
|
for frame in self:
|
||||||
row = []
|
row = []
|
||||||
row.append(u(' File "{0}", line {1}, in {2}\n').format(
|
row.append(u(' File "{0}", line {1}, in {2}\n').format(
|
||||||
frame.filename, frame.lineno, frame.name))
|
_some_str(frame.filename), frame.lineno, frame.name))
|
||||||
if frame.line:
|
if frame.line:
|
||||||
row.append(u(' {0}\n').format(frame.line.strip()))
|
row.append(u(' {0}\n').format(frame.line.strip()))
|
||||||
if frame.locals:
|
if frame.locals:
|
||||||
|
|
|
@ -605,6 +605,16 @@ class TestStack(unittest.TestCase):
|
||||||
[' File "foo.py", line 1, in fred\n line\n'],
|
[' File "foo.py", line 1, in fred\n line\n'],
|
||||||
s.format())
|
s.format())
|
||||||
|
|
||||||
|
def test_format_bad_filename(self):
|
||||||
|
# Filenames in Python2 may be bytestrings that will fail to implicit
|
||||||
|
# decode.
|
||||||
|
# This won't decode via the implicit(ascii) codec.
|
||||||
|
fname = u('\u5341').encode('shift-jis')
|
||||||
|
s = traceback.StackSummary.from_list([(fname, 1, 'fred', 'line')])
|
||||||
|
self.assertEqual(
|
||||||
|
[' File "b\'\\x8f\\\\\'", line 1, in fred\n line\n'],
|
||||||
|
s.format())
|
||||||
|
|
||||||
def test_locals(self):
|
def test_locals(self):
|
||||||
linecache.updatecache('/foo.py', globals())
|
linecache.updatecache('/foo.py', globals())
|
||||||
c = test_code('/foo.py', 'method')
|
c = test_code('/foo.py', 'method')
|
||||||
|
@ -627,7 +637,7 @@ class TestStack(unittest.TestCase):
|
||||||
traceback.walk_stack(None), capture_locals=True, limit=1)
|
traceback.walk_stack(None), capture_locals=True, limit=1)
|
||||||
s = some_inner(3, 4)
|
s = some_inner(3, 4)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[' File "' + FNAME + '", line 627, '
|
[' File "' + FNAME + '", line 637, '
|
||||||
'in some_inner\n'
|
'in some_inner\n'
|
||||||
' traceback.walk_stack(None), capture_locals=True, limit=1)\n'
|
' traceback.walk_stack(None), capture_locals=True, limit=1)\n'
|
||||||
' a = 1\n'
|
' a = 1\n'
|
||||||
|
|
Loading…
Reference in New Issue