Beispiel #1
0
def test_get_kernel_metadata_no_match():
    '''Test that we get a ParseError when searching for a kernel that does
    not exist in the parse tree.

    '''
    module_parse_tree = parse(CODE)
    kernel_type_name = "no_matching_kernel"
    with pytest.raises(ParseError) as excinfo:
        get_kernel_metadata(
            kernel_type_name, module_parse_tree)
    assert 'Kernel type no_matching_kernel does not exist' in str(excinfo)
Beispiel #2
0
def test_get_kernel_metadata_match():
    '''Test that something (anything at this point) is returned when
    searching for a kernel that exists in the parse tree.

    '''
    module_parse_tree = parse(CODE)
    kernel_type_name = "test_type"
    meta = get_kernel_metadata(kernel_type_name, module_parse_tree)
    assert meta is not None
Beispiel #3
0
def test_get_kernel_metadata_match_case_insensitive():
    '''Test that searching for a kernel is not dependent upon the
    case of the name.

    '''
    module_parse_tree = parse(CODE)
    kernel_type_name = "TeSt_TyPe"
    meta = get_kernel_metadata(kernel_type_name, module_parse_tree)
    # Make sure we found it.
    assert meta is not None
Beispiel #4
0
def create_kernelprocedure(code):
    '''Support function that attempts to create an instance of the
    'KernelProcedure' class. It is assumed that the name of the
    metadata is 'test_type' which matches the example code in the
    'CODE' variable. The code is passed in by argument as it might be
    necessary to modify it beforehand.

    :param str code: kernel code

    :returns: An instance of the KernelProcedure class
    :rtype: :py:class:`psyclone.parse.kernel.KernelProcedure`

    '''
    module_parse_tree = parse(code)
    kernel_type_name = "test_type"
    kernel_type_parse_tree = get_kernel_metadata(kernel_type_name,
                                                 module_parse_tree)
    return KernelProcedure(kernel_type_parse_tree, kernel_type_name,
                           module_parse_tree)