提交 4848c601 authored 作者: James Bergstra's avatar James Bergstra

fixed exception-raising errors from recent pep8 commit for MakeTester

上级 1e8f9cc5
...@@ -193,22 +193,22 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={}, ...@@ -193,22 +193,22 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
try: try:
#node = self.op.make_node(*inputrs) #node = self.op.make_node(*inputrs)
node = safe_make_node(self.op, *inputrs) node = safe_make_node(self.op, *inputrs)
except Exception: except Exception, exc:
type, exc_value, traceback = sys.exc_info()
err_msg = ("Test %s::%s: Error occurred while" err_msg = ("Test %s::%s: Error occurred while"
" making a node with inputs %s") % ( " making a node with inputs %s") % (
self.op, testname, inputs) self.op, testname, inputs)
exc_value.args = exc_value.args + (err_msg, ) exc.args += (err_msg,)
raise type(exc_value, traceback) print err_msg
raise
try: try:
f = inplace_func(inputrs, node.outputs, mode=mode) f = inplace_func(inputrs, node.outputs, mode=mode)
except Exception: except Exception, exc:
type, exc_value, traceback = sys.exc_info()
err_msg = ("Test %s::%s: Error occurred while" err_msg = ("Test %s::%s: Error occurred while"
" trying to make a Function") % (self.op, testname) " trying to make a Function") % (self.op, testname)
exc_value.args = exc_value.args + (err_msg, ) exc.args += (err_msg,)
raise type(exc_value, traceback) print err_msg
raise
if (isinstance(self.expected, dict) if (isinstance(self.expected, dict)
and testname in self.expected): and testname in self.expected):
expecteds = self.expected[testname] expecteds = self.expected[testname]
...@@ -226,13 +226,13 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={}, ...@@ -226,13 +226,13 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
try: try:
variables = f(*inputs) variables = f(*inputs)
except Exception: except Exception, exc:
type, exc_value, traceback = sys.exc_info()
err_msg = ("Test %s::%s: Error occurred while calling" err_msg = ("Test %s::%s: Error occurred while calling"
" the Function on the inputs %s") % ( " the Function on the inputs %s") % (
self.op, testname, inputs) self.op, testname, inputs)
exc_value.args = exc_value.args + (err_msg, ) exc.args += (err_msg,)
raise type(exc_value, traceback) print err_msg
raise
if not isinstance(expecteds, (list, tuple)): if not isinstance(expecteds, (list, tuple)):
expecteds = (expecteds, ) expecteds = (expecteds, )
...@@ -241,7 +241,7 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={}, ...@@ -241,7 +241,7 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
izip(variables, expecteds)): izip(variables, expecteds)):
if (variable.dtype != expected.dtype if (variable.dtype != expected.dtype
or variable.shape != expected.shape or variable.shape != expected.shape
or numpy.any(abs(variable - expected) > eps): or numpy.any(abs(variable - expected) > eps)):
self.fail(("Test %s::%s: Output %s gave the wrong" self.fail(("Test %s::%s: Output %s gave the wrong"
" value. With inputs %s, expected %s, got %s." " value. With inputs %s, expected %s, got %s."
" numpy.allclose return %s %s") % ( " numpy.allclose return %s %s") % (
...@@ -281,22 +281,22 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={}, ...@@ -281,22 +281,22 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
inputrs = [value(input) for input in inputs] inputrs = [value(input) for input in inputs]
try: try:
node = safe_make_node(self.op, *inputrs) node = safe_make_node(self.op, *inputrs)
except Exception: except Exception, exc:
type, exc_value, traceback = sys.exc_info()
err_msg = ("Test %s::%s: Error occurred while trying" err_msg = ("Test %s::%s: Error occurred while trying"
" to make a node with inputs %s") % ( " to make a node with inputs %s") % (
self.op, testname, inputs) self.op, testname, inputs)
exc_value.args = exc_value.args + (err_msg, ) exc.args += (err_msg,)
raise type(exc_value, traceback) print err_msg
raise
try: try:
f = inplace_func(inputrs, node.outputs, mode=mode) f = inplace_func(inputrs, node.outputs, mode=mode)
except Exception: except Exception, exc:
type, exc_value, traceback = sys.exc_info()
err_msg = ("Test %s::%s: Error occurred while trying" err_msg = ("Test %s::%s: Error occurred while trying"
" to make a Function") % (self.op, testname) " to make a Function") % (self.op, testname)
exc_value.args = exc_value.args + (err_msg, ) exc.args += (err_msg,)
raise type(exc_value, traceback) print err_msg
raise
# Add tester return a ValueError. Should we catch only this # Add tester return a ValueError. Should we catch only this
# one? # one?
...@@ -319,12 +319,12 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={}, ...@@ -319,12 +319,12 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
mode=self.mode, mode=self.mode,
rel_tol=_grad_rtol) rel_tol=_grad_rtol)
except Exception: except Exception:
type, exc_value, traceback = sys.exc_info()
err_msg = ("Test %s::%s: Error occurred while" err_msg = ("Test %s::%s: Error occurred while"
" computing the gradient on the following" " computing the gradient on the following"
" inputs: %s" ) % (self.op, testname, inputs) " inputs: %s" ) % (self.op, testname, inputs)
exc_value.args = exc_value.args + (err_msg, ) print err_msg
raise type(exc_value, traceback) exc.args += (err_msg,)
raise
finally: finally:
config.warn.sum_div_dimshuffle_bug = backup config.warn.sum_div_dimshuffle_bug = backup
...@@ -5129,10 +5129,10 @@ class test_size(unittest.TestCase): ...@@ -5129,10 +5129,10 @@ class test_size(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
if 1: if 0:
unittest.main() unittest.main()
else: else:
testcase = T_Join_and_Split testcase = FloorInplaceTester
suite = unittest.TestLoader() suite = unittest.TestLoader()
suite = suite.loadTestsFromTestCase(testcase) suite = suite.loadTestsFromTestCase(testcase)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论