Skip to content

Commit

Permalink
#2451 tests for node_str
Browse files Browse the repository at this point in the history
  • Loading branch information
oakleybrunt committed May 14, 2024
1 parent e83df85 commit 91d945a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/psyclone/domain/lfric/lfric_invoke_schedule.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2017-2023, Science and Technology Facilities Council.
# Copyright (c) 2017-2024, Science and Technology Facilities Council.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -58,9 +58,9 @@ class LFRicInvokeSchedule(InvokeSchedule):
:param str name: name of the Invoke.
:param arg: list of KernelCalls parsed from the algorithm layer.
:type arg: list of :py:class:`psyclone.parse.algorithm.KernelCall`
:param reserved_names: optional list of names that are not allowed in the \
:param reserved_names: optional list of names that are not allowed in the
new InvokeSchedule SymbolTable.
:type reserved_names: list of str
:type reserved_names: list[str]
:param parent: the parent of this node in the PSyIR.
:type parent: :py:class:`psyclone.psyir.nodes.Node`
Expand All @@ -76,7 +76,7 @@ def node_str(self, colour=True):
:param bool colour: whether or not to include control codes for colour.
:returns: text summary of this node, optionally with control codes \
:returns: text summary of this node, optionally with control codes
for colour highlighting.
:rtype: str
Expand Down
6 changes: 3 additions & 3 deletions src/psyclone/dynamo0p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2629,10 +2629,10 @@ class DynBasisFunctions(LFRicCollection):
functions required by an invoke or kernel call. This covers both those
required for quadrature and for evaluators.
:param node: either the schedule of an Invoke or a single Kernel object \
for which to extract information on all required \
:param node: either the schedule of an Invoke or a single Kernel object
for which to extract information on all required
basis/diff-basis functions.
:type node: :py:class:`psyclone.domain.lfric.LFRicInvokeSchedule` or \
:type node: :py:class:`psyclone.domain.lfric.LFRicInvokeSchedule` or
:py:class:`psyclone.domain.lfric.LFRicKern`
:raises InternalError: if a call has an unrecognised evaluator shape.
Expand Down
57 changes: 55 additions & 2 deletions src/psyclone/tests/domain/lfric/lfric_invoke_schedule_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
import os
from psyclone.domain.lfric import LFRicSymbolTable, LFRicInvokeSchedule
from psyclone.parse.algorithm import parse
from psyclone.psyir.nodes import Container
from psyclone.psyir.nodes import Container, colored
from psyclone.psyGen import PSyFactory


BASE_PATH = os.path.join(
Expand All @@ -47,7 +48,7 @@
TEST_API = "dynamo0.3"


def test_dyninvsched_parent():
def test_lfricinvsched_parent():
''' Check the setting of the parent of a LFRicInvokeSchedule. '''
_, invoke_info = parse(os.path.join(BASE_PATH,
"1.0.1_single_named_invoke.f90"),
Expand All @@ -60,3 +61,55 @@ def test_dyninvsched_parent():
fake_parent = Container("my_mod", symbol_table=LFRicSymbolTable())
dsched2 = LFRicInvokeSchedule("my_sched", kcalls, parent=fake_parent)
assert dsched2.parent is fake_parent


def test_lfricinvsched_node_str_coloured():
'''
Check the node_str method of the LFRicInvokeSchedule class. We need an
Invoke object for this which we get using the dynamo0.3 API.
This test checks that `dm` is printed equal to `True` when dist_mem is
`True` in the config and that `InvokeSchedule` is coloured when requested
by the `node_str` method.
'''
_, invoke_info = parse(os.path.join(BASE_PATH,
"1.0.1_single_named_invoke.f90"),
api="dynamo0.3")

# distributed_memory set to True
psy = PSyFactory("dynamo0.3", distributed_memory=True).create(invoke_info)
# Create a plain LFRicInvokeSchedule
sched = LFRicInvokeSchedule('name', None, None)
# Manually supply it with an Invoke object created with the LFRic API.
sched.invoke = psy.invokes.invoke_list[0]
output = sched.node_str()

assert colored("InvokeSchedule", LFRicInvokeSchedule._colour) in output
assert str("[invoke='" + sched.invoke.name + "', dm=True]") in output


def test_lfricinvsched_node_str_colourless():
'''
Check the node_str method of the LFRicInvokeSchedule class. We need an
Invoke object for this which we get using the dynamo0.3 API.
This test checks that `dm` is printed equal to `False` when dist_mem is
`False` in the config and that `InvokeSchedule` is uncoloured when
requested by the `node_str` method.
'''
_, invoke_info = parse(os.path.join(BASE_PATH,
"1.0.1_single_named_invoke.f90"),
api="dynamo0.3")
psy = PSyFactory("dynamo0.3", distributed_memory=False).create(invoke_info)
# Create a plain LFRicInvokeSchedule
sched = LFRicInvokeSchedule('name', None, None)
# Manually supply it with an Invoke object created with the LFRic API.
sched.invoke = psy.invokes.invoke_list[0]

# colour set to False
output = sched.node_str(colour=False)

assert(str("InvokeSchedule[invoke='" + sched.invoke.name + "', dm=False]")
in output)
2 changes: 1 addition & 1 deletion src/psyclone/tests/psyir/tools/call_tree_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_call_tree_compute_all_non_locals_kernel():
mod_psyir, _ = get_invoke(test_file, "dynamo0.3", 0, dist_mem=False)
psyir = mod_psyir.invokes.invoke_list[0].schedule

# This will return three schedule - the DynInvokeSchedule, and two
# This will return three schedule - the LFRicInvokeSchedule, and two
# schedules for the kernel and builtin. Just make sure we have
# the right parts before doing the actual test:
schedules = psyir.walk(Schedule)
Expand Down

0 comments on commit 91d945a

Please sign in to comment.