diff --git a/setup.cfg b/setup.cfg index 01544d76c4..3070bce28f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,10 +46,6 @@ extend-ignore = E266 # errors on specific lines with # noqa: in a few other files. exclude = .git,__pycache__,conf.py, - # Contain deliberate Python errors for testing purposes - src/psyclone/tests/test_files/dynamo0p3/error_syntax.py, - src/psyclone/tests/test_files/dynamo0p3/error_import.py, - src/psyclone/tests/test_files/dynamo0p3/runtime_error.py, # Contain multiple imports flagged with F401 imported but unused __init__.py, tutorial/practicals/LFRic/single_node/1_openmp/omp_script.py, diff --git a/src/psyclone/tests/generator_test.py b/src/psyclone/tests/generator_test.py index 101b70d3f8..7e7a9d10a9 100644 --- a/src/psyclone/tests/generator_test.py +++ b/src/psyclone/tests/generator_test.py @@ -80,13 +80,32 @@ "test_files", "gocean1p0") -def delete_module(modname): - '''A function to remove a module from Python's internal modules - list. This is useful as some tests affect others by importing - modules. +@pytest.fixture(name="script_factory", scope="function") +def create_script_factor(tmpdir): + ''' Fixture that creates a psyclone optimisation script given the string + representing the body of the script: + + script_path = script_factory("def trans(psyir):\n pass") + + It has a 'function' scope and a tear down section because using a script + imports the file and this is kept in the python interpreter state, so we + delete it for future tests. ''' - del modules[modname] + tmpfile = os.path.join(tmpdir, "test_script.py") + + def populate_script(string): + with open(tmpfile, 'w+', encoding="utf8") as script: + script.write(string) + return tmpfile + + yield populate_script + # Tear down section executed after each test that uses the fixture + # If the created script was used, then its module (file) was imported + # into the interpreter runtime, we need to make sure it is deleted + modname = "test_script" + if modname in modules: + del modules[modname] for mod in modules.values(): try: delattr(mod, modname) @@ -142,30 +161,33 @@ def test_script_file_wrong_extension(): "extension" in str(error.value)) -def test_script_invalid_content(): +def test_script_invalid_content(script_factory): '''Checks that load_script() in generator.py raises the expected exception when a script file does not contain valid python. This test uses the generate() function to call load_script as this is a simple way to create its required arguments. ''' - with pytest.raises(Exception) as error_syntax: + error_syntax = script_factory(""" +this is invalid python + """) + with pytest.raises(Exception) as err: _, _ = generate( os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), - api="lfric", script_name=os.path.join(BASE_PATH, "dynamo0p3", - "error_syntax.py")) - assert ("invalid syntax (error_syntax.py, line 5)" - in str(error_syntax.value)) + api="lfric", script_name=error_syntax) + assert ("invalid syntax (test_script.py, line 2)" in str(err.value)) - with pytest.raises(Exception) as error_import: + error_import = script_factory(""" +import non_existent + """) + with pytest.raises(Exception) as err: _, _ = generate( os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), - api="lfric", script_name=os.path.join(BASE_PATH, "dynamo0p3", - "error_import.py")) - assert "No module named 'non_existent'" in str(error_import.value) + api="lfric", script_name=error_import) + assert "No module named 'non_existent'" in str(err.value) -def test_script_invalid_content_runtime(): +def test_script_invalid_content_runtime(script_factory): '''Checks that load_script() function in generator.py raises the expected exception when a script file contains valid python syntactically but produces a runtime exception. This test uses the @@ -173,16 +195,19 @@ def test_script_invalid_content_runtime(): to create its required arguments. ''' + runtime_error = script_factory(""" +def trans(psyir): + # this will produce a runtime error as b has not been assigned + psyir = b + """) with pytest.raises(Exception) as error: _, _ = generate( os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), - api="lfric", - script_name=os.path.join( - BASE_PATH, "dynamo0p3", "runtime_error.py")) + api="lfric", script_name=runtime_error) assert "name 'b' is not defined" in str(error.value) -def test_script_no_trans(): +def test_script_no_trans(script_factory): '''Checks that load_script() function in generator.py raises the expected exception when a script file does not contain a trans() function. This test uses the generate() function to call @@ -190,18 +215,23 @@ def test_script_no_trans(): arguments. ''' + no_trans_script = script_factory(""" +def nottrans(psyir): + pass + +def tran(): + pass +""") with pytest.raises(GenerationError) as error: _, _ = generate( os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), - api="lfric", - script_name=os.path.join( - BASE_PATH, "dynamo0p3", "no_trans.py")) + api="lfric", script_name=no_trans_script) assert ("attempted to use specified PSyclone transformation module " - "'no_trans' but it does not contain a callable 'trans' function" + "'test_script' but it does not contain a callable 'trans' function" in str(error.value)) -def test_script_no_trans_alg(capsys): +def test_script_no_trans_alg(capsys, script_factory): '''Checks that load_script() function in generator.py does not raise an exception when a script file does not contain a trans_alg() function as these are optional. At the moment this function is @@ -210,17 +240,17 @@ def test_script_no_trans_alg(capsys): its required arguments. ''' + no_alg_script = script_factory("def trans(psyir):\n pass") _, _ = generate( os.path.join(BASE_PATH, "gocean1p0", "single_invoke.f90"), - api="gocean", - script_name=os.path.join(BASE_PATH, "gocean1p0", "script.py")) + api="gocean", script_name=no_alg_script) # The legacy script deprecation warning is not printed in this case captured = capsys.readouterr() assert "Deprecation warning:" not in captured.err -def test_script_with_legacy_trans_signature(capsys): +def test_script_with_legacy_trans_signature(capsys, script_factory): '''Checks that load_script() function in generator.py does not raise an exception when a script file uses the legacy trans signature. @@ -230,10 +260,16 @@ def test_script_with_legacy_trans_signature(capsys): This will eventually be deprecated. ''' + legacy_script = script_factory(""" +def trans(psy): + # The following are backwards-compatible expressions with legacy scripts + _ = psy.invokes.invoke_list + _ = psy.invokes.names + return psy +""") _, _ = generate( os.path.join(BASE_PATH, "gocean1p0", "single_invoke.f90"), - api="gocean", - script_name=os.path.join(BASE_PATH, "gocean1p0", "legacy_script.py")) + api="gocean", script_name=legacy_script) # The deprecation warning message was printed captured = capsys.readouterr() @@ -391,16 +427,23 @@ def test_no_script_gocean(): assert "MODULE psy_single_invoke_test" in str(psy) -def test_script_gocean(): +def test_script_gocean(script_factory): '''Test that the generate function in generator.py returns successfully if a script (containing both trans_alg() and trans() functions) is specified. ''' + alg_script = script_factory(""" +def trans_alg(psyir): + pass + +def trans(psyir): + pass + """) + _, _ = generate( os.path.join(BASE_PATH, "gocean1p0", "single_invoke.f90"), - api="gocean", - script_name=os.path.join(BASE_PATH, "gocean1p0", "alg_script.py")) + api="gocean", script_name=alg_script) def test_profile_gocean(): @@ -417,41 +460,43 @@ def test_profile_gocean(): Profiler._options = [] -def test_script_attr_error(): +def test_script_attr_error(script_factory): '''Checks that generator.py raises an appropriate error when a script - file contains a trans() function which raises an attribute - error. This is what we previously used to check for a script file - not containing a trans() function. + file contains a trans() function which raises an attribute error. ''' + error_script = script_factory(""" +from psyclone.psyGen import Loop +from psyclone.transformations import ColourTrans + +def trans(psyir): + ''' A valid trans function which produces an attribute error as + we have mistyped apply()''' + ctrans = ColourTrans() + for child in psyir.walk(Loop): + if isinstance(child, Loop) and child.field_space != "w3": + ctrans.appy(child) +""") with pytest.raises(Exception) as excinfo: _, _ = generate(os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), - api="lfric", - script_name=os.path.join(BASE_PATH, - "dynamo0p3", - "error_trans.py")) + api="lfric", script_name=error_script) assert 'object has no attribute' in str(excinfo.value) -def test_script_null_trans(): +def test_script_null_trans(script_factory): '''Checks that generator.py works correctly when the trans() function - in a valid script file does no transformations (it simply passes - input to output). In this case the valid script file has an - explicit path and must therefore exist at this location. + in a valid script file does no transformations. In this case the valid + script file has an absolut path and must therefore exist at this location. ''' + empty_script = script_factory("def trans(psyir):\n pass") alg1, psy1 = generate(os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), api="lfric") alg2, psy2 = generate(os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), - api="lfric", - script_name=os.path.join(BASE_PATH, - "dynamo0p3", - "null_trans.py")) - # remove module so we do not affect any following tests - delete_module("null_trans") + api="lfric", script_name=empty_script) # we need to remove the first line before comparing output as # this line is an instance specific header assert '\n'.join(str(alg1).split('\n')[1:]) == \ @@ -460,7 +505,7 @@ def test_script_null_trans(): '\n'.join(str(psy2).split('\n')[1:]) -def test_script_null_trans_relative(): +def test_script_null_trans_relative(script_factory): '''Checks that generator.py works correctly when the trans() function in a valid script file does no transformations (it simply passes input to output). In this case the valid script file contains no @@ -470,13 +515,15 @@ def test_script_null_trans_relative(): alg1, psy1 = generate(os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), api="lfric") - # set up the python path so that null_trans.py can be found - os.sys.path.append(os.path.join(BASE_PATH, "dynamo0p3")) + empty_script = script_factory("def trans(psyir):\n pass") + basename = os.path.basename(empty_script) + path = os.path.dirname(empty_script) + # Set the script directory in the PYTHONPATH + os.sys.path.append(path) alg2, psy2 = generate(os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), - api="lfric", script_name="null_trans.py") - # remove imported module so we do not affect any following tests - delete_module("null_trans") + api="lfric", script_name=basename) + # Remove the path from PYTHONPATH os.sys.path.pop() # we need to remove the first line before comparing output as # this line is an instance specific header @@ -485,12 +532,22 @@ def test_script_null_trans_relative(): assert str(psy1) == str(psy2) -def test_script_trans_dynamo0p3(): +def test_script_trans_dynamo0p3(script_factory): '''Checks that generator.py works correctly when a transformation is provided as a script, i.e. it applies the transformations - correctly. We use loop fusion as an example. + correctly. ''' + fuse_loop_script = script_factory(""" +from psyclone.domain.lfric.transformations import LFRicLoopFuseTrans +def trans(psyir): + module = psyir.children[0] + schedule = [x for x in module.children if x.name == "invoke_0"][0] + loop1 = schedule.children[4] + loop2 = schedule.children[5] + transform = LFRicLoopFuseTrans() + transform.apply(loop1, loop2) +""") root_path = os.path.dirname(os.path.abspath(__file__)) base_path = os.path.join(root_path, "test_files", "dynamo0p3") # First loop fuse explicitly (without using generator.py) @@ -506,10 +563,7 @@ def test_script_trans_dynamo0p3(): generated_code_1 = psy.gen # Second loop fuse using generator.py and a script _, generated_code_2 = generate(parse_file, api="lfric", - script_name=os.path.join( - base_path, "loop_fuse_trans.py")) - # remove module so we do not affect any following tests - delete_module("loop_fuse_trans") + script_name=fuse_loop_script) # third - check that the results are the same ... assert str(generated_code_1) == str(generated_code_2) @@ -1347,7 +1401,7 @@ def test_no_script_lfric_new(monkeypatch): assert "use _psyclone_builtins" not in alg -def test_script_lfric_new(monkeypatch): +def test_script_lfric_new(monkeypatch, script_factory): '''Test that the generate function in generator.py returns successfully if a script (containing both trans_alg() and trans() functions) is specified. This test uses the new PSyIR approach to @@ -1356,11 +1410,17 @@ def test_script_lfric_new(monkeypatch): monkeypatching. ''' + alg_script = script_factory(""" +def trans_alg(psyir): + pass + +def trans(psyir): + pass + """) monkeypatch.setattr(generator, "LFRIC_TESTING", True) alg, _ = generate( os.path.join(BASE_PATH, "dynamo0p3", "1_single_invoke.f90"), - api="lfric", - script_name=os.path.join(BASE_PATH, "dynamo0p3", "alg_script.py")) + api="lfric", script_name=alg_script) # new call replaces invoke assert "use single_invoke_psy, only : invoke_0_testkern_type" in alg assert "call invoke_0_testkern_type(a, f1, f2, m1, m2)" in alg diff --git a/src/psyclone/tests/test_files/dynamo0p3/alg_script.py b/src/psyclone/tests/test_files/dynamo0p3/alg_script.py deleted file mode 100644 index bc15e40428..0000000000 --- a/src/psyclone/tests/test_files/dynamo0p3/alg_script.py +++ /dev/null @@ -1,59 +0,0 @@ -# ----------------------------------------------------------------------------- -# BSD 3-Clause License -# -# Copyright (c) 2023-2024, Science and Technology Facilities Council. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# ----------------------------------------------------------------------------- -# Author R. W. Ford STFC Daresbury Lab - -'''Null PSyclone transformation script that includes an example of the -optional 'trans_alg()' function. If included, the 'trans_alg()' -function allows modification of the algorithm layer. -''' - - -def trans_alg(psyir): - '''Function to modify the algorithm layer PSyIR. This function is - designed to be called by the psyclone script. - - :param psyir: algorithm-layer code represented in PSyIR. - :type psyir: :class:py:`psyclone.psyir.nodes.Node` - - ''' - - -def trans(psyir): - '''Function to modify the algorithm layer PSyIR. This function is - designed to be called by the psyclone script. - - :param psyir: the PSyIR of the PSy-layer. - :type psyir: :py:class:`psyclone.psyir.nodes.FileContainer` - - ''' diff --git a/src/psyclone/tests/test_files/dynamo0p3/error_import.py b/src/psyclone/tests/test_files/dynamo0p3/error_import.py deleted file mode 100644 index fcad5bdd82..0000000000 --- a/src/psyclone/tests/test_files/dynamo0p3/error_import.py +++ /dev/null @@ -1,5 +0,0 @@ -''' - A test transformation module containing valid python but an invalid import. -''' - -import non_existent diff --git a/src/psyclone/tests/test_files/dynamo0p3/error_syntax.py b/src/psyclone/tests/test_files/dynamo0p3/error_syntax.py deleted file mode 100644 index 900f217e70..0000000000 --- a/src/psyclone/tests/test_files/dynamo0p3/error_syntax.py +++ /dev/null @@ -1,5 +0,0 @@ -''' - A test transformation module containing invalid python. -''' - -this is invalid python diff --git a/src/psyclone/tests/test_files/dynamo0p3/error_trans.py b/src/psyclone/tests/test_files/dynamo0p3/error_trans.py deleted file mode 100644 index 9e98b9cb39..0000000000 --- a/src/psyclone/tests/test_files/dynamo0p3/error_trans.py +++ /dev/null @@ -1,19 +0,0 @@ -''' - A test module containing valid python but the trans() function - raises an attribute error. This was previously used to catch - whether a trans() function exists or not. -''' - -from psyclone.psyGen import Loop -from psyclone.transformations import ColourTrans - - -def trans(psyir): - ''' a valid trans function which produces an attribute error as - we have mistyped apply()''' - ctrans = ColourTrans() - for child in psyir.walk(Loop): - if isinstance(child, Loop) and child.field_space != "w3": - # The no-member issue below is intentional - # pylint: disable=no-member - ctrans.appy(child) diff --git a/src/psyclone/tests/test_files/dynamo0p3/loop_fuse_trans.py b/src/psyclone/tests/test_files/dynamo0p3/loop_fuse_trans.py deleted file mode 100644 index 4c51411eaf..0000000000 --- a/src/psyclone/tests/test_files/dynamo0p3/loop_fuse_trans.py +++ /dev/null @@ -1,57 +0,0 @@ -# ----------------------------------------------------------------------------- -# BSD 3-Clause License -# -# Copyright (c) 2017-2024, Science and Technology Facilities Council. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# ----------------------------------------------------------------------------- -# Author R. W. Ford, STFC Daresbury Lab -# Modified I. Kavcic, Met Office -# Modified by J. Henrichs, Bureau of Meteorology -# Modified by S. Siso, STFC Daresbury Lab - - -''' - A test module that provides a script to perform loop fusion on the - first two loops of an invoke called 'invoke_0'. This module does - not perform any error checking. It is used by the test system to - ensure that transformation scripts work correctly. -''' -from psyclone.domain.lfric.transformations import LFRicLoopFuseTrans - - -def trans(psyir): - ''' A test loop fusion transformation for use with the transformation - unit tests ''' - module = psyir.children[0] - schedule = [x for x in module.children if x.name == "invoke_0"][0] - loop1 = schedule.children[4] - loop2 = schedule.children[5] - transform = LFRicLoopFuseTrans() - transform.apply(loop1, loop2) diff --git a/src/psyclone/tests/test_files/dynamo0p3/no_trans.py b/src/psyclone/tests/test_files/dynamo0p3/no_trans.py deleted file mode 100644 index c8775681bd..0000000000 --- a/src/psyclone/tests/test_files/dynamo0p3/no_trans.py +++ /dev/null @@ -1,14 +0,0 @@ -''' - A test module containing valid python but not a trans() function - which is required for transformation scripts. Therefore an error - should be produced by PSyclone if this file is referenced as a - transformation script. -''' - - -def nottrans(psyir): - ''' first invalid name examples for a trans function ''' - - -def tran(psyir): - ''' second invalid name example for a trans function ''' diff --git a/src/psyclone/tests/test_files/dynamo0p3/null_trans.py b/src/psyclone/tests/test_files/dynamo0p3/null_trans.py deleted file mode 100644 index e27f2f9717..0000000000 --- a/src/psyclone/tests/test_files/dynamo0p3/null_trans.py +++ /dev/null @@ -1,3 +0,0 @@ -# contains a valid trans() function that performs the null operation -def trans(x): - return x diff --git a/src/psyclone/tests/test_files/dynamo0p3/runtime_error.py b/src/psyclone/tests/test_files/dynamo0p3/runtime_error.py deleted file mode 100644 index effd0a9505..0000000000 --- a/src/psyclone/tests/test_files/dynamo0p3/runtime_error.py +++ /dev/null @@ -1,3 +0,0 @@ -def trans(psyir): - # this will produce a runtime error as b has not been assigned - psyir = b diff --git a/src/psyclone/tests/test_files/gocean1p0/alg_script.py b/src/psyclone/tests/test_files/gocean1p0/alg_script.py deleted file mode 100644 index c7625cbeb0..0000000000 --- a/src/psyclone/tests/test_files/gocean1p0/alg_script.py +++ /dev/null @@ -1,59 +0,0 @@ -# ----------------------------------------------------------------------------- -# BSD 3-Clause License -# -# Copyright (c) 2022-2024, Science and Technology Facilities Council. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# ----------------------------------------------------------------------------- -# Author R. W. Ford STFC Daresbury Lab - -'''Null PSyclone transformation script that includes an example of the -optional 'trans_alg()' function. If included, the 'trans_alg()' -function allows modification of the algorithm layer. -''' - - -def trans_alg(psyir): - '''Function to modify the algorithm layer PSyIR. This function is - designed to be called by the psyclone script. - - :param psyir: algorithm-layer code represented in PSyIR. - :type psyir: :class:py:`psyclone.psyir.nodes.Node` - - ''' - - -def trans(psyir): - '''Function to modify the PSy-layer PSyIR. This function is - designed to be called by the psyclone script. - - :param psyir: the PSyIR of the PSy-layer. - :type psyir: :py:class:`psyclone.psyir.nodes.FileContainer` - - ''' diff --git a/src/psyclone/tests/test_files/gocean1p0/legacy_script.py b/src/psyclone/tests/test_files/gocean1p0/legacy_script.py deleted file mode 100644 index 30037d5d29..0000000000 --- a/src/psyclone/tests/test_files/gocean1p0/legacy_script.py +++ /dev/null @@ -1,52 +0,0 @@ -# ----------------------------------------------------------------------------- -# BSD 3-Clause License -# -# Copyright (c) 2024, Science and Technology Facilities Council. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# ----------------------------------------------------------------------------- -# Author: S. Siso, STFC Daresbury Lab - -''' PSyclone transformation script that expects the 'legacy' trans signature -with a psy object. ''' - - -def trans(psy): - ''' - :param psy: PSyclone's representation of the PSy-layer code. - :type psy: :class:py:`psyclone.psyGen.PSy` - - :returns: modified PSy-layer code. - :rtype: :class:py:`psyclone.psyGen.PSy` - - ''' - # The following are backwards-compatible expressions with legacy scripts - _ = psy.invokes.invoke_list - _ = psy.invokes.names - return psy diff --git a/src/psyclone/tests/test_files/gocean1p0/script.py b/src/psyclone/tests/test_files/gocean1p0/script.py deleted file mode 100644 index 6a8ebef58e..0000000000 --- a/src/psyclone/tests/test_files/gocean1p0/script.py +++ /dev/null @@ -1,49 +0,0 @@ -# ----------------------------------------------------------------------------- -# BSD 3-Clause License -# -# Copyright (c) 2022-2024, Science and Technology Facilities Council. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# * Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# ----------------------------------------------------------------------------- -# Author: R. W. Ford, STFC Daresbury Lab -# Modified: S. Siso, STFC Daresbury Lab - -'''Null PSyclone transformation script that only includes an example -of the 'trans()' function which is required for a valid script file. -''' - - -def trans(psyir): - '''Function to modify the PSy-layer PSyIR. This function is - designed to be called by the psyclone script. - - :param psyir: the PSyIR of the PSy-layer. - :type psyir: :py:class:`psyclone.psyir.nodes.FileContainer` - - '''