def test_过滤Without(self) -> None:
     ce = None
     try:
         capture_exceptions.capture_exceptions(f, 1, without=E)
     except E as e:
         ce = e
     assert isinstance(ce, E)
     assert ce.args[0] == "将返回自身"
Exemple #2
0
 def test2(self) -> None:
     opts = trust_region.Trust_Region_Options(max_iter=500)
     opts.check_rel = numpy.inf
     opts.check_abs = 1.0e-6
     result = capture_exceptions(run, opts, catch=Grad_Check_Failed)
     assert isinstance(result, Captured_Exception)
     assert isinstance(result.exception, Grad_Check_Failed)
 def test_matmul_ERRimpl(self) -> None:
     assert matmulERR((numpy.zeros((1, 6)), numpy.zeros(
         (6, 1)))).shape == (1, 1)
     ce = capture_exceptions(matmulERR, (numpy.zeros(
         (7, 6)), numpy.zeros((6, 4))))
     assert isinstance(ce, Captured_Exception)
     assert isinstance(ce.exception, AssertionError)
 def test_matmul(self) -> None:
     assert matmul((numpy.zeros((2, 3)), numpy.zeros(
         (3, 4)))).shape == (2, 4)
     assert matmul((numpy.zeros((7, 6)), numpy.zeros(
         (6, 5)))).shape == (7, 5)
     ce = capture_exceptions(matmul, (numpy.zeros(
         (7, 6)), numpy.zeros((3, 4))))
     assert isinstance(ce, Captured_Exception)
     assert isinstance(ce.exception, AssertionError)
 def test_重放(self) -> None:
     ce = capture_exceptions.capture_exceptions(f, 1)
     assert isinstance(ce, capture_exceptions.Captured_Exception)
     assert isinstance(ce.exception, E)
     ee = None
     try:
         ce()
     except BaseException as eee:
         ee = eee
     assert isinstance(ee, E)
     assert ee.args == ce.exception.args
 def test_maker(self) -> None:
     checker[1]((dataOK, ))
     checker[2]((dataOK, dataOK))
     checker[3]((dataOK, dataOK, dataOK))
     checker[4]((dataOK, dataOK, dataOK, dataOK))
     checker[5]((dataOK, dataOK, dataOK, dataOK, dataOK))
     checker[6]((dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     checker[7]((dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     checker[8](
         (dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     checker[9]((dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK,
                 dataOK, dataOK))
     ce_1 = capture_exceptions(checker[1], (dataERR, ))
     ce_2 = capture_exceptions(checker[2], (dataOK, dataERR))
     ce_3 = capture_exceptions(checker[3], (dataOK, dataOK, dataERR))
     ce_4 = capture_exceptions(checker[4],
                               (dataOK, dataOK, dataOK, dataERR))
     ce_5 = capture_exceptions(checker[5],
                               (dataOK, dataOK, dataOK, dataOK, dataERR))
     ce_6 = capture_exceptions(
         checker[6], (dataOK, dataOK, dataOK, dataOK, dataOK, dataERR))
     ce_7 = capture_exceptions(
         checker[7],
         (dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataERR))
     ce_8 = capture_exceptions(
         checker[8],
         (dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataERR),
     )
     ce_9 = capture_exceptions(
         checker[9],
         (dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK,
          dataERR),
     )
     assert isinstance(ce_1, Captured_Exception)
     assert isinstance(ce_2, Captured_Exception)
     assert isinstance(ce_3, Captured_Exception)
     assert isinstance(ce_4, Captured_Exception)
     assert isinstance(ce_5, Captured_Exception)
     assert isinstance(ce_6, Captured_Exception)
     assert isinstance(ce_7, Captured_Exception)
     assert isinstance(ce_8, Captured_Exception)
     assert isinstance(ce_9, Captured_Exception)
     assert isinstance(ce_1.exception, AssertionError)
     assert isinstance(ce_2.exception, AssertionError)
     assert isinstance(ce_3.exception, AssertionError)
     assert isinstance(ce_4.exception, AssertionError)
     assert isinstance(ce_5.exception, AssertionError)
     assert isinstance(ce_6.exception, AssertionError)
     assert isinstance(ce_7.exception, AssertionError)
     assert isinstance(ce_8.exception, AssertionError)
     assert isinstance(ce_9.exception, AssertionError)
     cce_2 = capture_exceptions(checker[2], (dataERR, dataOK))
     cce_3 = capture_exceptions(checker[3], (dataERR, dataOK, dataOK))
     cce_4 = capture_exceptions(checker[4],
                                (dataERR, dataOK, dataOK, dataOK))
     cce_5 = capture_exceptions(checker[5],
                                (dataERR, dataOK, dataOK, dataOK, dataOK))
     cce_6 = capture_exceptions(
         checker[6], (dataERR, dataOK, dataOK, dataOK, dataOK, dataOK))
     cce_7 = capture_exceptions(
         checker[7],
         (dataERR, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     cce_8 = capture_exceptions(
         checker[8],
         (dataERR, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK),
     )
     cce_9 = capture_exceptions(
         checker[9],
         (dataERR, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK,
          dataOK),
     )
     assert isinstance(cce_2, Captured_Exception)
     assert isinstance(cce_3, Captured_Exception)
     assert isinstance(cce_4, Captured_Exception)
     assert isinstance(cce_5, Captured_Exception)
     assert isinstance(cce_6, Captured_Exception)
     assert isinstance(cce_7, Captured_Exception)
     assert isinstance(cce_8, Captured_Exception)
     assert isinstance(cce_9, Captured_Exception)
     assert isinstance(cce_2.exception, AssertionError)
     assert isinstance(cce_3.exception, AssertionError)
     assert isinstance(cce_4.exception, AssertionError)
     assert isinstance(cce_5.exception, AssertionError)
     assert isinstance(cce_6.exception, AssertionError)
     assert isinstance(cce_7.exception, AssertionError)
     assert isinstance(cce_8.exception, AssertionError)
     assert isinstance(cce_9.exception, AssertionError)
 def test_str函数暂时能用就行(self) -> None:
     ce = capture_exceptions.capture_exceptions(f, 1)
     assert isinstance(ce, capture_exceptions.Captured_Exception)
     assert isinstance(ce.exception, E)
     assert str(ce) == "{}".format(ce)
     print(ce)
 def test_正常情形(self) -> None:
     ce = capture_exceptions.capture_exceptions(f, 2)
     assert ce == 4
 def test_异常情形(self) -> None:
     ce = capture_exceptions.capture_exceptions(f, 1)
     assert isinstance(ce, capture_exceptions.Captured_Exception)
     assert isinstance(ce.exception, E)
     assert ce.exception.args[0] == "将返回自身"
Exemple #10
0
 def test1(self) -> None:
     opts = trust_region.Trust_Region_Options(max_iter=500)
     result = capture_exceptions(run, opts, catch=Grad_Check_Failed)
     assert isinstance(result, Captured_Exception)
     assert isinstance(result.exception, Grad_Check_Failed)
 def test_1(self) -> None:
     dataOK = 1
     dataERR = None
     fff[0](())
     fff[1]((dataOK, ))
     fff[2]((dataOK, dataOK))
     fff[3]((dataOK, dataOK, dataOK))
     fff[4]((dataOK, dataOK, dataOK, dataOK))
     fff[5]((dataOK, dataOK, dataOK, dataOK, dataOK))
     fff[6]((dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     fff[7]((dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     fff[8](
         (dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     fff[9]((dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK,
             dataOK))
     ce_1 = capture_exceptions(fff[1], (dataERR, ))
     ce_2 = capture_exceptions(fff[2], (dataOK, dataERR))
     ce_3 = capture_exceptions(fff[3], (dataOK, dataOK, dataERR))
     ce_4 = capture_exceptions(fff[4], (dataOK, dataOK, dataOK, dataERR))
     ce_5 = capture_exceptions(fff[5],
                               (dataOK, dataOK, dataOK, dataOK, dataERR))
     ce_6 = capture_exceptions(
         fff[6], (dataOK, dataOK, dataOK, dataOK, dataOK, dataERR))
     ce_7 = capture_exceptions(
         fff[7], (dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataERR))
     ce_8 = capture_exceptions(
         fff[8],
         (dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataERR))
     ce_9 = capture_exceptions(
         fff[9],
         (dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK,
          dataERR),
     )
     assert isinstance(ce_1, Captured_Exception)
     assert isinstance(ce_2, Captured_Exception)
     assert isinstance(ce_3, Captured_Exception)
     assert isinstance(ce_4, Captured_Exception)
     assert isinstance(ce_5, Captured_Exception)
     assert isinstance(ce_6, Captured_Exception)
     assert isinstance(ce_7, Captured_Exception)
     assert isinstance(ce_8, Captured_Exception)
     assert isinstance(ce_9, Captured_Exception)
     assert isinstance(ce_1.exception, AssertionError)
     assert isinstance(ce_2.exception, AssertionError)
     assert isinstance(ce_3.exception, AssertionError)
     assert isinstance(ce_4.exception, AssertionError)
     assert isinstance(ce_5.exception, AssertionError)
     assert isinstance(ce_6.exception, AssertionError)
     assert isinstance(ce_7.exception, AssertionError)
     assert isinstance(ce_8.exception, AssertionError)
     assert isinstance(ce_9.exception, AssertionError)
     cce_2 = capture_exceptions(fff[2], (dataERR, dataOK))
     cce_3 = capture_exceptions(fff[3], (dataERR, dataOK, dataOK))
     cce_4 = capture_exceptions(fff[4], (dataERR, dataOK, dataOK, dataOK))
     cce_5 = capture_exceptions(fff[5],
                                (dataERR, dataOK, dataOK, dataOK, dataOK))
     cce_6 = capture_exceptions(
         fff[6], (dataERR, dataOK, dataOK, dataOK, dataOK, dataOK))
     cce_7 = capture_exceptions(
         fff[7], (dataERR, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     cce_8 = capture_exceptions(
         fff[8],
         (dataERR, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK))
     cce_9 = capture_exceptions(
         fff[9],
         (dataERR, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK, dataOK,
          dataOK),
     )
     assert isinstance(cce_2, Captured_Exception)
     assert isinstance(cce_3, Captured_Exception)
     assert isinstance(cce_4, Captured_Exception)
     assert isinstance(cce_5, Captured_Exception)
     assert isinstance(cce_6, Captured_Exception)
     assert isinstance(cce_7, Captured_Exception)
     assert isinstance(cce_8, Captured_Exception)
     assert isinstance(cce_9, Captured_Exception)
     assert isinstance(cce_2.exception, AssertionError)
     assert isinstance(cce_3.exception, AssertionError)
     assert isinstance(cce_4.exception, AssertionError)
     assert isinstance(cce_5.exception, AssertionError)
     assert isinstance(cce_6.exception, AssertionError)
     assert isinstance(cce_7.exception, AssertionError)
     assert isinstance(cce_8.exception, AssertionError)
     assert isinstance(cce_9.exception, AssertionError)
Exemple #12
0
def parfor_helper(
    info_tuple: Tuple[int, Callable[[param_t], return_t], param_t]
) -> Tuple[int, Union[return_t, Captured_Exception[param_t, return_t]]]:
    idx, f, arg = info_tuple
    value = capture_exceptions(f, arg)
    return idx, value