def test_dyninvokebasisfns(monkeypatch): ''' Check that we raise internal errors as required ''' _, invoke_info = parse(os.path.join(BASE_PATH, "1.1.0_single_invoke_xyoz_qr.f90"), api=API) psy = PSyFactory(API).create(invoke_info) # Get hold of a DynInvokeBasisFns object evaluator = psy.invokes.invoke_list[0].evaluators # Test the error check in dynamo0p3.qr_basis_alloc_args() by passing in a # dictionary containing an invalid shape entry basis_dict = {"shape": "gh_wrong_shape"} from psyclone import dynamo0p3 with pytest.raises(GenerationError) as excinfo: _ = dynamo0p3.qr_basis_alloc_args("size1", basis_dict) assert "unrecognised shape (gh_wrong_shape) specified " in str(excinfo) # Monkey-patch it so that it doesn't have any quadrature args monkeypatch.setattr(evaluator, "_qr_vars", value=[]) # Check that calling the various _initialise_... routines does nothing. # We pass parent=None so that if any of the routines get beyond the # initial check then they will fail. evaluator._initialise_xyz_qr(None) evaluator._initialise_xyoz_qr(None) evaluator._initialise_xoyoz_qr(None)
def test_dynbasisfunctions(monkeypatch): ''' Check that we raise internal errors as required. ''' _, invoke_info = parse(os.path.join(BASE_PATH, "1.1.0_single_invoke_xyoz_qr.f90"), api=API) psy = PSyFactory(API, distributed_memory=False).create(invoke_info) # Get hold of a DynBasisFunctions object evaluator = psy.invokes.invoke_list[0].evaluators # Test the error check in dynamo0p3.qr_basis_alloc_args() by passing in a # dictionary containing an invalid shape entry basis_dict = {"shape": "gh_wrong_shape"} from psyclone.dynamo0p3 import qr_basis_alloc_args with pytest.raises(InternalError) as excinfo: _ = qr_basis_alloc_args("size1", basis_dict) assert ("Unrecognised shape ('gh_wrong_shape') specified " in str(excinfo.value)) # Monkey-patch it so that it doesn't have any quadrature args monkeypatch.setattr(evaluator, "_qr_vars", value=[]) # Check that calling the various _initialise_... routines does nothing. # We pass parent=None so that if any of the routines get beyond the # initial check then they will fail. evaluator._initialise_xyz_qr(None) evaluator._initialise_xyoz_qr(None) evaluator._initialise_xoyoz_qr(None) evaluator._initialise_face_or_edge_qr(None, "face") evaluator._initialise_face_or_edge_qr(None, "edge") with pytest.raises(InternalError) as err: evaluator._initialise_face_or_edge_qr(None, "Face") assert ("qr_type argument must be either 'face' or 'edge' but got: " "'Face'" in str(err.value)) # Check that the constructor raises an internal error if it encounters # a shape it doesn't recognise invoke = psy.invokes.invoke_list[0] sched = invoke.schedule call = sched.children[0].loop_body[0] assert isinstance(call, DynKern) monkeypatch.setattr(call, "_eval_shapes", ["not-a-shape"]) with pytest.raises(InternalError) as err: _ = DynBasisFunctions(invoke) assert "Unrecognised evaluator shape: 'not-a-shape'" in str(err.value)