def test_unrecognised_builtin(): ''' Check that we raise an error if we call the BuiltInKernelTypeFactory with an unrecognised built-in name ''' from psyclone import dynamo0p3_builtins factory = BuiltInKernelTypeFactory() with pytest.raises(ParseError) as excinfo: _ = factory.create(dynamo0p3_builtins.BUILTIN_MAP, None, name="not_a_builtin") assert ("unrecognised built-in name. Got 'not_a_builtin' but" in str(excinfo.value))
def test_broken_builtin_metadata(): ''' Check that we raise an appropriate error if there is a problem with the meta-data describing the built-ins for a given API ''' from psyclone import dynamo0p3_builtins # The file containing broken meta-data for the built-ins test_builtin_name = "aX_plus_Y" defs_file = os.path.join(TEST_PATH, "broken_builtins_mod.f90") factory = BuiltInKernelTypeFactory(api="dynamo0.3") with pytest.raises(ParseError) as excinfo: _ = factory.create(dynamo0p3_builtins.BUILTIN_MAP, defs_file, name=test_builtin_name.lower()) assert ("Failed to parse the meta-data for PSyclone built-ins in" in str(excinfo.value))
def create_builtin_kernel_call(self, kernel_name, args): '''Takes the builtin kernel name and a list of Arg objects which capture information about the builtin call arguments and returns a BuiltinCall instance with content specific to the particular API (as specified in self._api). :param str kernel_name: the name of the builtin kernel being \ called :param args: a list of 'Arg' instances containing the required \ information for the arguments being passed from the algorithm \ layer. The list order is the same as the argument order. :type arg: list of :py:class:`psyclone.parse.algorithm.Arg` :returns: a BuiltInCall instance with information specific to \ the API. :rtype: :py:class:`psyclone.parse.algorithm.BuiltInCall` :raises ParseError: if the builtin is specified in a use \ statement in the algorithm layer ''' if kernel_name.lower() in self._arg_name_to_module_name: raise ParseError( "A built-in cannot be named in a use " "statement but '{0}' is used from " "module '{1}' in file {2}".format( kernel_name, self._arg_name_to_module_name[kernel_name.lower()], self._alg_filename)) from psyclone.parse.kernel import BuiltInKernelTypeFactory return BuiltInCall( BuiltInKernelTypeFactory(api=self._api).create( self._builtin_name_map.keys(), self._builtin_defs_file, name=kernel_name.lower()), args)
def test_builtinfactory_metadataerror(monkeypatch): '''Test that an appropriate exception is raised if the builtin metadata cannot be parsed. This is difficult to trigger so use monkeypatch. We just need to make the call to the parse function raise an exception. This can be simply done by setting it to None (which gives a TypeError as it is not callable). ''' from psyclone.dynamo0p3_builtins import BUILTIN_MAP as builtins from psyclone.dynamo0p3_builtins import BUILTIN_DEFINITIONS_FILE as \ fname from fparser import api as fpapi monkeypatch.setattr(fpapi, "parse", None) factory = BuiltInKernelTypeFactory() with pytest.raises(ParseError) as excinfo: _ = factory.create(builtins.keys(), fname, "setval_c") assert "Failed to parse the meta-data for PSyclone built-ins" \ in str(excinfo.value)