Addressed comments for the fix for test interpreter_test.py with PY3
The type byte is defined only in Python3, that is why we need to check version of Python. I tested this test using Python3 and Python2 Removed unnecessary formatting.
This commit is contained in:
parent
093e00fee1
commit
f78701b5fc
@ -108,11 +108,11 @@ class Delegate(object):
|
|||||||
self.message = ''
|
self.message = ''
|
||||||
|
|
||||||
def report(self, x):
|
def report(self, x):
|
||||||
if (type(x) is not bytes):
|
if sys.version_info.major >= 3 and type(x) is bytes:
|
||||||
self.message += x
|
# To support PY3
|
||||||
|
self.message += ''.join(chr(l) for l in x)
|
||||||
else:
|
else:
|
||||||
# To support both: PY2 and PY3, we don't use the function decode, but do this way
|
self.message += x
|
||||||
self.message.join(chr(l) for l in x)
|
|
||||||
|
|
||||||
capture = ErrorMessageCapture()
|
capture = ErrorMessageCapture()
|
||||||
error_capturer_cb = ctypes.CFUNCTYPE(None, ctypes.c_char_p)(capture.report)
|
error_capturer_cb = ctypes.CFUNCTYPE(None, ctypes.c_char_p)(capture.report)
|
||||||
|
@ -305,12 +305,12 @@ class InterpreterDelegateTest(test_util.TensorFlowTestCase):
|
|||||||
if sys.platform == 'darwin': return
|
if sys.platform == 'darwin': return
|
||||||
destructions = []
|
destructions = []
|
||||||
def register_destruction(x):
|
def register_destruction(x):
|
||||||
if (type(x) is not bytes):
|
if sys.version_info.major >= 3 and type(x) is bytes:
|
||||||
destructions.append(x)
|
# To support PY3
|
||||||
else:
|
|
||||||
# To support both: PY2 and PY3, we don't use the function decode, but do this way
|
|
||||||
y = ''.join(chr(l) for l in x)
|
y = ''.join(chr(l) for l in x)
|
||||||
destructions.append(y)
|
destructions.append(y)
|
||||||
|
else:
|
||||||
|
destructions.append(x)
|
||||||
return 0
|
return 0
|
||||||
# Make a wrapper for the callback so we can send this to ctypes
|
# Make a wrapper for the callback so we can send this to ctypes
|
||||||
delegate = interpreter_wrapper.load_delegate(self._delegate_file)
|
delegate = interpreter_wrapper.load_delegate(self._delegate_file)
|
||||||
@ -347,8 +347,8 @@ class InterpreterDelegateTest(test_util.TensorFlowTestCase):
|
|||||||
|
|
||||||
delegate_b = interpreter_wrapper.load_delegate(
|
delegate_b = interpreter_wrapper.load_delegate(
|
||||||
self._delegate_file, options={
|
self._delegate_file, options={
|
||||||
'unused': False,
|
'unused': False,
|
||||||
'options_counter': 2
|
'options_counter': 2
|
||||||
})
|
})
|
||||||
lib = delegate_b._library
|
lib = delegate_b._library
|
||||||
|
|
||||||
@ -359,6 +359,7 @@ class InterpreterDelegateTest(test_util.TensorFlowTestCase):
|
|||||||
|
|
||||||
del delegate_a
|
del delegate_a
|
||||||
del delegate_b
|
del delegate_b
|
||||||
|
|
||||||
self.assertEqual(lib.get_num_delegates_created(), 2)
|
self.assertEqual(lib.get_num_delegates_created(), 2)
|
||||||
self.assertEqual(lib.get_num_delegates_destroyed(), 2)
|
self.assertEqual(lib.get_num_delegates_destroyed(), 2)
|
||||||
self.assertEqual(lib.get_num_delegates_invoked(), 0)
|
self.assertEqual(lib.get_num_delegates_invoked(), 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user