def test_call_float_function_errors(self): """Test call_float_function error cases.""" vm = values.Values(None, False) vm.set_handler(values.FloatErrorHandler(None)) def itimes(x): return complex(0, x) with self.assertRaises(error.BASICError): values._call_float_function(itimes, vm.new_single().from_int(1))
def test_float_error_handler_errors(self): """Test FloatErrorHandler error cases.""" vm = values.Values(None, False) vm.set_handler(values.FloatErrorHandler(None)) # use an exception class not supported by FloatErrorHandler def typerr(x): raise TypeError() with self.assertRaises(TypeError): values._call_float_function(typerr, vm.new_single().from_int(1))
def test_float_error_handler_soft(self): """Test FloatErrorHandler.""" class MockConsole(object): def write_line(self, s): pass vm = values.Values(None, double_math=False) vm.set_handler(values.FloatErrorHandler(MockConsole())) # overflowerror *is* handled def ovflerr(x): e = OverflowError() raise e assert isinstance( values._call_float_function(ovflerr, vm.new_double().from_int(1)), Single)