def test_kerntypefactory_create_broken_type(): ''' Check that we raise an error if the KernelTypeFactory.create() method encounters an unrecognised API. ''' factory = KernelTypeFactory(api="") # Deliberately break the 'type' (API) of this factory factory._type = "invalid_api" test_builtin_name = "aX_plus_Y" with pytest.raises(ParseError) as excinfo: _ = factory.create(None, name=test_builtin_name.lower()) assert ("KernelTypeFactory:create: Unsupported kernel type" in str(excinfo.value))
def test_kerneltypefactory_default_api(): ''' Check that the KernelTypeFactory correctly defaults to using the default API ''' from psyclone.configuration import Config _config = Config.get() factory = KernelTypeFactory(api="") assert factory._type == _config.default_api
def create_coded_kernel_call(self, kernel_name, args): '''Takes a coded kernel name and a list of Arg objects which capture information about the coded call arguments and returns a KernelCall instance with content specific to the particular API (as specified in self._api). :param str kernel_name: the name of the coded 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 KernelCall instance with information specific to \ the API. :rtype: :py:class:`psyclone.parse.algorithm.KernelCall` :raises ParseError: if the kernel is not specified in a use \ statement in the algorithm layer ''' try: module_name = self._arg_name_to_module_name[kernel_name.lower()] except KeyError: raise ParseError( "kernel call '{0}' must either be named " "in a use " "statement (found {1}) or be a recognised built-in " "(one of '{2}' for this API)".format( kernel_name, list(self._arg_name_to_module_name.values()), list(self._builtin_name_map.keys()))) from psyclone.parse.kernel import get_kernel_ast modast = get_kernel_ast(module_name, self._alg_filename, self._kernel_path, self._line_length) from psyclone.parse.kernel import KernelTypeFactory return KernelCall( module_name, KernelTypeFactory(api=self._api).create(modast, name=kernel_name), args)
def test_kerneltypefactory_wrong_api(): ''' Check that we raise an appropriate error if we try to create a KernelTypeFactory with an invalid API ''' with pytest.raises(ParseError) as excinfo: _ = KernelTypeFactory(api="invalid_api") assert "check_api: Unsupported API 'invalid_api'" in str(excinfo.value)