copy _raise_from from chainer.utils to parameterized.py
import functools
import itertools
+import sys
import types
import typing as tp # NOQA
import unittest
@@ -8,7 +9,19 @@ import numpy
import six
from cupy.testing import _bundle
-from cupy import utils
+
+
+def _raise_from(exc_type, message, orig_exc):
+ # Raises an exception that wraps another exception.
+ message = (
+ '{}\n\n'
+ '(caused by)\n'
+ '{}: {}\n'.format(message, type(orig_exc).__name__, orig_exc))
+ new_exc = exc_type(message)
+ if sys.version_info < (3,):
+ six.reraise(exc_type, new_exc, sys.exc_info()[2])
+ else:
+ six.raise_from(new_exc.with_traceback(orig_exc.__traceback__), None)
def _param_to_str(obj):
@@ -89,7 +102,7 @@ def _parameterize_test_case(base, i, param):
s.write('Test parameters:\n')
for k, v in sorted(param.items()):
s.write(' {}: {}\n'.format(k, v))
- utils._raise_from(e.__class__, s.getvalue(), e)
+ _raise_from(e.__class__, s.getvalue(), e)
return new_method
return (cls_name, mb, method_generator)
