def test_call_init_error(): '''Test that the appropriate exception is raised if the routine argument is not a RoutineSymbol. ''' with pytest.raises(TypeError) as info: _ = Call(None) assert ("Call routine argument should be a RoutineSymbol but found " "'NoneType'." in str(info.value))
def test_call_init(): '''Test that a Call can be created as expected. Also test the routine property. ''' # routine argument routine = RoutineSymbol("jo") call = Call(routine) assert call._routine is routine assert call.routine is call._routine assert call.parent is None assert call.children == [] # optional parent argument parent = Schedule() call = Call(routine, parent=parent) assert call.routine is routine assert call.parent is parent assert call.children == []
def test_invoke_error(): '''Test that the expected exception is raised in the validate method when the supplied node is a call but its name is not the expected 'invoke' name. ''' invoke_trans = InvokeCallTrans() with pytest.raises(TransformationError) as info: invoke_trans.validate(Call(RoutineSymbol("hello"))) assert ("Error in InvokeCallTrans transformation. The supplied call " "argument should be a `Call` node with name 'invoke' but " "found 'hello'." in str(info.value))
def _parse_args(code_block, fp2_node): '''Return the arguments from a Structure Constructor stored as a CodeBlock containing an fparser2 ast. :param code_block: the CodeBlock containing a StructureConstructor. :type code_block: :py:class:`psyclone.psyir.nodes.CodeBlock` :param fp2_node: the fparser2 Structure Constructor node. :type fp2_node: \ :py:class:`fparser.two.Fortran2003.Structure_Constructor` :returns: a list of PSyIR nodes containing the \ StructureConstructor arguments. :rtype: list of :py:class:`psyclone.psyir.nodes.Node` ''' dummy_call = Call(RoutineSymbol("dummy"), parent=code_block.parent) fparser2 = Fparser2Reader() for arg in fp2_node.children[1].children: fparser2.process_nodes(dummy_call, [arg]) return dummy_call.pop_all_children()
def test_call_str(): ''' Test that the str method behaves as expected ''' routine = RoutineSymbol("roo") call = Call(routine) assert str(call) == "Call[name='roo']"
def test_call_node_str(): ''' Test that the node_str method behaves as expected ''' routine = RoutineSymbol("isaac") call = Call(routine) colouredtext = colored("Call", SCHEDULE_COLOUR_MAP["Call"]) assert call.node_str() == colouredtext + "[name='isaac']"