Skip to content

Commit 3c6df4a

Browse files
authored
Fix unicode logs
1 parent c90ba34 commit 3c6df4a

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

openhtf/core/test_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def finalize_from_phase_outcome(self, phase_execution_outcome):
222222
result = phase_execution_outcome.phase_result
223223
if isinstance(result, phase_executor.ExceptionInfo):
224224
code = result.exc_type.__name__
225-
description = str(result.exc_val).decode('utf8', 'replace')
225+
description = unicode(result.exc_val)
226226
else:
227227
# openhtf.util.threads.ThreadTerminationError gets str'd directly.
228228
code = str(type(phase_execution_outcome.phase_result).__name__)

openhtf/util/logs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ def emit(self, record):
178178
"""
179179
message = record.getMessage()
180180
if record.exc_info:
181-
message += '\n' + ''.join(traceback.format_exception(
181+
message += u'\n' + u''.join(traceback.format_exception(
182182
*record.exc_info))
183-
message = message.decode('utf8', 'replace')
184183

185184
log_record = LogRecord(
186185
record.levelno, record.name, os.path.basename(record.pathname),

test/util/data_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding=utf-8
2+
13
# Copyright 2016 Google Inc. All Rights Reserved.
24

35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +30,7 @@ class FloatSubclass(float):
2830
'list': [10],
2931
'tuple': (10,),
3032
'str': '10',
31-
'unicode': u'10',
33+
'unicode': u'',
3234
'int': 2 ** 40,
3335
'float': 10.0,
3436
'long': 2 ** 80,
@@ -43,6 +45,7 @@ class FloatSubclass(float):
4345
self.assertIs(type(converted['tuple']), tuple)
4446
self.assertIs(type(converted['str']), str)
4547
self.assertIs(type(converted['unicode']), unicode)
48+
self.assertEqual(converted['unicode'], example_data['unicode'])
4649
self.assertIs(type(converted['int']), int)
4750
self.assertIs(type(converted['float']), float)
4851
self.assertIs(type(converted['long']), long)

0 commit comments

Comments
 (0)