diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 84ddca67c..5ef9860e4 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -51,11 +51,17 @@ jobs: # It is the responsibility of the developer to apply Black. (Auto- # committing the results of running Black here is possible but # then breaks the normal GitHub reviewing workflow.) + # NOTE: Black's decisions depend upon the version of Python being + # used. Therefore, fparser developers are recommended to use the + # the version of Python that is specified below. black: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.14 - uses: psf/black@stable with: src: "./src ./example" @@ -65,7 +71,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9', '3.10', '3.13'] + python-version: ['3.9', '3.10', '3.14'] steps: - uses: actions/checkout@v3 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dae84d2a..34817c38b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ Modifications by (in alphabetical order): * P. Vitt, University of Siegen, Germany * A. Voysey, UK Met Office +13/03/2026 PR #495 for #494. Fix CI issues with the black formatting check. + 13/03/2026 PR #491 for #490. Fix syntax warning and add build artifact to gitignore. diff --git a/doc/source/developers_guide.rst b/doc/source/developers_guide.rst index 44218df25..7c35e6b34 100644 --- a/doc/source/developers_guide.rst +++ b/doc/source/developers_guide.rst @@ -976,13 +976,24 @@ Python versions and the coverage reports are uploaded automatically to CodeCov (https://codecov.io/gh/stfc/fparser). The configuration for this is in the `.github/workflows/unit-tests.yml` file. -In addition, an Action is also used check that all of the code conforms -to Black (https://black.readthedocs.io) formatting. It is up to the developer -to ensure that this passes (e.g. by running `black` locally and committing -the results). Note that it is technically possibly to have the Action -actually make the changes and commit them but this was found to break +Black Formatting +++++++++++++++++ + +A second job within the GitHub Action is used to check that all of the +code conforms to Black (https://black.readthedocs.io) formatting. It +is up to the developer to ensure that this passes (e.g. by running +`black` locally and committing the results). + +The formatting choices made by Black are influenced by the version of Python +being used. Therefore it is recommended that a developer use the version of +Python that is specfied for the `Black` job within the yml configuration +file mentioned above. (This will normally be the most recent, stable version +of Python.) + +Note that while it is technically possibly to have the Action +actually make the changes and commit them, this was found to break the Github review process since the automated commit is not permitted to -trigger further Actions and this then leaves GitHub thinking that the +trigger further Actions. This then leaves GitHub thinking that the various checks have not run. Automatic Packaging diff --git a/example/create_dependencies.py b/example/create_dependencies.py index 833278dc8..5a678289d 100755 --- a/example/create_dependencies.py +++ b/example/create_dependencies.py @@ -45,7 +45,6 @@ Usage: create_dependencies.py file1.f90 file2.F90 ... """ - import os import sys diff --git a/example/split_file.py b/example/split_file.py index 97babd226..74dd7cf2d 100755 --- a/example/split_file.py +++ b/example/split_file.py @@ -42,7 +42,6 @@ Usage: split_file.py file.f90 """ - import os import subprocess import sys @@ -107,8 +106,7 @@ def create_makefile(main_name, all_objs, all_filenames): clean_actions = "\trm -f $(OBJS) *.mod" with open(makefile, mode="w", encoding="utf-8") as f_out: - f_out.write( - f""" + f_out.write(f""" F90 ?= {f90} # We have to enforce this setting, since using ?= will not # change the value of CPP, which will then be using `cc -E`, which @@ -142,8 +140,7 @@ def create_makefile(main_name, all_objs, all_filenames): # ======= clean: {clean_actions} -""" - ) +""") # ----------------------------------------------------------------------------- diff --git a/src/fparser/api.py b/src/fparser/api.py index 6c1b6e301..34894edb1 100644 --- a/src/fparser/api.py +++ b/src/fparser/api.py @@ -68,6 +68,7 @@ Module content -------------- """ + # Author: Pearu Peterson # Created: Oct 2006 diff --git a/src/fparser/common/readfortran.py b/src/fparser/common/readfortran.py index c149d203b..bd536832e 100644 --- a/src/fparser/common/readfortran.py +++ b/src/fparser/common/readfortran.py @@ -147,7 +147,6 @@ import fparser.common.sourceinfo from fparser.common.splitline import String, string_replace_map, splitquote - __all__ = [ "FortranFileReader", "FortranStringReader", diff --git a/src/fparser/common/sourceinfo.py b/src/fparser/common/sourceinfo.py index de01d03d1..60a008346 100644 --- a/src/fparser/common/sourceinfo.py +++ b/src/fparser/common/sourceinfo.py @@ -69,10 +69,10 @@ I'm not sure what that is. """ + import os import re - ############################################################################## diff --git a/src/fparser/common/splitline.py b/src/fparser/common/splitline.py index bdcf55b20..f2b6a04f9 100644 --- a/src/fparser/common/splitline.py +++ b/src/fparser/common/splitline.py @@ -74,7 +74,6 @@ """ - import re from typing import List, Tuple, Optional, Union diff --git a/src/fparser/common/tests/conftest.py b/src/fparser/common/tests/conftest.py index c0a616f0f..a3e1f0227 100644 --- a/src/fparser/common/tests/conftest.py +++ b/src/fparser/common/tests/conftest.py @@ -36,6 +36,7 @@ directory """ + import pytest diff --git a/src/fparser/common/tests/logging_utils.py b/src/fparser/common/tests/logging_utils.py index 4d8ec135d..6b358a19a 100644 --- a/src/fparser/common/tests/logging_utils.py +++ b/src/fparser/common/tests/logging_utils.py @@ -39,6 +39,7 @@ """ Helps with testing methods which write to the standard logger. """ + import logging diff --git a/src/fparser/common/tests/test_base_classes.py b/src/fparser/common/tests/test_base_classes.py index 178e924b6..359077cd9 100644 --- a/src/fparser/common/tests/test_base_classes.py +++ b/src/fparser/common/tests/test_base_classes.py @@ -39,6 +39,7 @@ """ Test battery associated with fparser.common.base_classes package. """ + import re import pytest diff --git a/src/fparser/common/tests/test_sourceinfo.py b/src/fparser/common/tests/test_sourceinfo.py index 5f4aa57bf..8221632dd 100644 --- a/src/fparser/common/tests/test_sourceinfo.py +++ b/src/fparser/common/tests/test_sourceinfo.py @@ -51,7 +51,6 @@ get_source_info, ) - ############################################################################## diff --git a/src/fparser/common/tests/test_utils.py b/src/fparser/common/tests/test_utils.py index e1a2526f6..4b63d9928 100644 --- a/src/fparser/common/tests/test_utils.py +++ b/src/fparser/common/tests/test_utils.py @@ -36,6 +36,7 @@ Test the various utility functions """ + import pytest from fparser.common.utils import split_comma, ParseError diff --git a/src/fparser/one/parsefortran.py b/src/fparser/one/parsefortran.py index 03530303c..afb6b8c4a 100644 --- a/src/fparser/one/parsefortran.py +++ b/src/fparser/one/parsefortran.py @@ -65,6 +65,7 @@ # DAMAGE. """Provides FortranParser.""" + # Author: Pearu Peterson # Created: May 2006 diff --git a/src/fparser/one/tests/test_where_construct_stmt_r745.py b/src/fparser/one/tests/test_where_construct_stmt_r745.py index c19ffee22..b4030b31c 100644 --- a/src/fparser/one/tests/test_where_construct_stmt_r745.py +++ b/src/fparser/one/tests/test_where_construct_stmt_r745.py @@ -38,6 +38,7 @@ R745 where-construct-stmt is [where-construct-name:] WHERE ( mask-expr ) """ + import pytest from fparser.common.sourceinfo import FortranFormat diff --git a/src/fparser/scripts/fparser2_bench.py b/src/fparser/scripts/fparser2_bench.py index 2eb895e43..94a80c6ab 100755 --- a/src/fparser/scripts/fparser2_bench.py +++ b/src/fparser/scripts/fparser2_bench.py @@ -39,6 +39,7 @@ by Ondřej Čertík via Ioannis Nikiteas. """ + from time import perf_counter from fparser.common.sourceinfo import FortranFormat diff --git a/src/fparser/scripts/read.py b/src/fparser/scripts/read.py index d888ca022..74ebeaa7f 100755 --- a/src/fparser/scripts/read.py +++ b/src/fparser/scripts/read.py @@ -69,6 +69,7 @@ representation of the code(s). """ + import sys import logging from fparser.scripts.script_options import set_read_options diff --git a/src/fparser/scripts/script_options.py b/src/fparser/scripts/script_options.py index 9fbb515eb..c8da74f2b 100644 --- a/src/fparser/scripts/script_options.py +++ b/src/fparser/scripts/script_options.py @@ -68,13 +68,11 @@ def set_read_options(parser): - parser.set_usage( - """\ + parser.set_usage("""\ %prog [options] Description: - %prog reads Fortran codes.""" - ) + %prog reads Fortran codes.""") parser.add_option( "--task", default="show", @@ -85,13 +83,11 @@ def set_read_options(parser): def set_parse_options(parser): - parser.set_usage( - """\ + parser.set_usage("""\ %prog [options] Description: - %prog parses Fortran codes.""" - ) + %prog parses Fortran codes.""") parser.add_option( "--task", default="show", @@ -109,13 +105,11 @@ def set_fparser_options(parser): """ - parser.set_usage( - """\ + parser.set_usage("""\ %prog [options] Description: - %prog parses Fortran code.""" - ) + %prog parses Fortran code.""") parser.add_option( "--task", default="show", diff --git a/src/fparser/tests/test_fparser_module.py b/src/fparser/tests/test_fparser_module.py index a23d390d4..b76206ee6 100644 --- a/src/fparser/tests/test_fparser_module.py +++ b/src/fparser/tests/test_fparser_module.py @@ -36,6 +36,7 @@ Test the setup performed for the fparser module. """ + import os import fparser diff --git a/src/fparser/two/C99Preprocessor.py b/src/fparser/two/C99Preprocessor.py index c282bf269..3b42a2116 100644 --- a/src/fparser/two/C99Preprocessor.py +++ b/src/fparser/two/C99Preprocessor.py @@ -33,6 +33,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """C99 Preprocessor Syntax Rules.""" + # Author: Balthasar Reuter # Based on previous work by Martin Schlipf (https://github.com/martin-schlipf) # First version created: Jan 2020 @@ -44,7 +45,6 @@ from fparser.two import pattern_tools as pattern from fparser.two.utils import Base, StringBase, WORDClsBase - # The list of classes that implement preprocessor directives # This list is used in match_cpp_directive() and # fparser.two.utils.BlockBase.match(). diff --git a/src/fparser/two/Fortran2003.py b/src/fparser/two/Fortran2003.py index babf04cb7..19ab1171c 100644 --- a/src/fparser/two/Fortran2003.py +++ b/src/fparser/two/Fortran2003.py @@ -66,6 +66,7 @@ # DAMAGE. """Fortran 2003 Syntax Rules.""" + # Original author: Pearu Peterson # First version created: Oct 2006 @@ -13290,36 +13291,27 @@ def tostr(self): _names.append(n) n = n[:-5] # Generate 'list' class - exec( - """\ + exec("""\ class %s_List(SequenceBase): subclass_names = [\'%s\'] use_names = [] def match(string): return SequenceBase.match(r\',\', %s, string) -""" - % (n, n, n) - ) +""" % (n, n, n)) elif n.endswith("_Name"): _names.append(n) n = n[:-5] - exec( - """\ + exec("""\ class %s_Name(Base): subclass_names = [\'Name\'] -""" - % (n) - ) +""" % (n)) elif n.startswith("Scalar_"): _names.append(n) n = n[7:] - exec( - """\ + exec("""\ class Scalar_%s(Base): subclass_names = [\'%s\'] -""" - % (n, n) - ) +""" % (n, n)) DynamicImport().import_now() diff --git a/src/fparser/two/Fortran2008/__init__.py b/src/fparser/two/Fortran2008/__init__.py index fe1350210..7510cadcb 100644 --- a/src/fparser/two/Fortran2008/__init__.py +++ b/src/fparser/two/Fortran2008/__init__.py @@ -37,6 +37,7 @@ 2003 standard to implement the Fortran 2008 standard. """ + import inspect import sys @@ -99,7 +100,6 @@ from fparser.two.Fortran2008.label_do_stmt_r816 import Label_Do_Stmt from fparser.two.Fortran2008.nonlabel_do_stmt_r817 import Nonlabel_Do_Stmt - # pylint: disable=eval-used # pylint: disable=exec-used @@ -125,33 +125,27 @@ _names.append(n) n = n[:-5] # Generate 'list' class - exec( - f"""\ + exec(f"""\ class {n}_List(SequenceBase): subclass_names = [\'{n}\'] use_names = [] @staticmethod def match(string): return SequenceBase.match(r\',\', {n}, string) -""" - ) +""") elif n.endswith("_Name"): _names.append(n) n = n[:-5] - exec( - f"""\ + exec(f"""\ class {n}_Name(Base): subclass_names = [\'Name\'] -""" - ) +""") elif n.startswith("Scalar_"): _names.append(n) n = n[7:] - exec( - f"""\ + exec(f"""\ class Scalar_{n}(Base): subclass_names = [\'{n}\'] -""" - ) +""") # Make sure NEW_CLS does not reference a class so is not accidentally # picked up in __all__. NEW_CLS = None diff --git a/src/fparser/two/Fortran2008/action_stmt_c201.py b/src/fparser/two/Fortran2008/action_stmt_c201.py index 1171b7628..d208d5c1c 100644 --- a/src/fparser/two/Fortran2008/action_stmt_c201.py +++ b/src/fparser/two/Fortran2008/action_stmt_c201.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Action_Stmt constraint C201 """ + from fparser.two.Fortran2003 import Action_Stmt_C201 as Action_Stmt_C201_2003 from fparser.two.Fortran2008.action_stmt_r214 import Action_Stmt diff --git a/src/fparser/two/Fortran2008/action_stmt_c816.py b/src/fparser/two/Fortran2008/action_stmt_c816.py index 8c026bc00..5351aeff0 100644 --- a/src/fparser/two/Fortran2008/action_stmt_c816.py +++ b/src/fparser/two/Fortran2008/action_stmt_c816.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Action_Stmt constraint C816 """ + from fparser.two.Fortran2003 import Action_Stmt_C824 as Action_Stmt_C824_2003 from fparser.two.Fortran2008.action_stmt_r214 import Action_Stmt diff --git a/src/fparser/two/Fortran2008/action_stmt_c828.py b/src/fparser/two/Fortran2008/action_stmt_c828.py index c431f9215..8a61bcf6e 100644 --- a/src/fparser/two/Fortran2008/action_stmt_c828.py +++ b/src/fparser/two/Fortran2008/action_stmt_c828.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Action_Stmt constraint C828 """ + from fparser.two.Fortran2003 import Action_Stmt_C802 as Action_Stmt_C802_2003 from fparser.two.Fortran2008.action_stmt_r214 import Action_Stmt diff --git a/src/fparser/two/Fortran2008/action_stmt_r214.py b/src/fparser/two/Fortran2008/action_stmt_r214.py index 91e15b1f0..5976278b5 100644 --- a/src/fparser/two/Fortran2008/action_stmt_r214.py +++ b/src/fparser/two/Fortran2008/action_stmt_r214.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Action_Stmt rule R214 """ + from fparser.two.Fortran2003 import Action_Stmt as Action_Stmt_2003 diff --git a/src/fparser/two/Fortran2008/alloc_opt_r627.py b/src/fparser/two/Fortran2008/alloc_opt_r627.py index 7e0a7c936..4172f6eaf 100644 --- a/src/fparser/two/Fortran2008/alloc_opt_r627.py +++ b/src/fparser/two/Fortran2008/alloc_opt_r627.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Alloc_Opt rule R627 """ + from fparser.two.Fortran2003 import ( Alloc_Opt as Alloc_Opt_2003, Stat_Variable, diff --git a/src/fparser/two/Fortran2008/allocate_stmt_r626.py b/src/fparser/two/Fortran2008/allocate_stmt_r626.py index 51d963b69..49c8e74d3 100644 --- a/src/fparser/two/Fortran2008/allocate_stmt_r626.py +++ b/src/fparser/two/Fortran2008/allocate_stmt_r626.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Allocate_Stmt rule R626 """ + from fparser.two.Fortran2003 import Allocate_Stmt as Allocate_Stmt_2003 diff --git a/src/fparser/two/Fortran2008/attr_spec_r502.py b/src/fparser/two/Fortran2008/attr_spec_r502.py index c0444fc24..2a34d620b 100644 --- a/src/fparser/two/Fortran2008/attr_spec_r502.py +++ b/src/fparser/two/Fortran2008/attr_spec_r502.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Attr_Spec rule R502 """ + from fparser.two import pattern_tools as pattern from fparser.two.Fortran2003 import Attr_Spec as Attr_Spec_2003 from fparser.two.utils import STRINGBase diff --git a/src/fparser/two/Fortran2008/block_construct_r807.py b/src/fparser/two/Fortran2008/block_construct_r807.py index 29a8a00a6..b595db6f2 100644 --- a/src/fparser/two/Fortran2008/block_construct_r807.py +++ b/src/fparser/two/Fortran2008/block_construct_r807.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Block_Construct rule R807 """ + from fparser.two.Fortran2003 import Specification_Part, Execution_Part_Construct from fparser.two.Fortran2008.block_stmt_r808 import Block_Stmt from fparser.two.Fortran2008.end_block_stmt_r809 import End_Block_Stmt diff --git a/src/fparser/two/Fortran2008/block_stmt_r808.py b/src/fparser/two/Fortran2008/block_stmt_r808.py index 3a727e66c..7913e2164 100644 --- a/src/fparser/two/Fortran2008/block_stmt_r808.py +++ b/src/fparser/two/Fortran2008/block_stmt_r808.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Block_Stmt rule R808 """ + from fparser.two.utils import StmtBase, WORDClsBase, ScopingRegionMixin diff --git a/src/fparser/two/Fortran2008/coarray_bracket_spec_r502d0.py b/src/fparser/two/Fortran2008/coarray_bracket_spec_r502d0.py index 21f45b8ca..4907628ab 100644 --- a/src/fparser/two/Fortran2008/coarray_bracket_spec_r502d0.py +++ b/src/fparser/two/Fortran2008/coarray_bracket_spec_r502d0.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Coarray_Bracket_Spec rule R502.d.0 """ + from fparser.two.Fortran2008.coarray_spec_r509 import Coarray_Spec from fparser.two.utils import BracketBase diff --git a/src/fparser/two/Fortran2008/coarray_spec_r509.py b/src/fparser/two/Fortran2008/coarray_spec_r509.py index cbe239dec..6291eae47 100644 --- a/src/fparser/two/Fortran2008/coarray_spec_r509.py +++ b/src/fparser/two/Fortran2008/coarray_spec_r509.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Coarray_Spec rule R509 """ + from fparser.two.utils import Base diff --git a/src/fparser/two/Fortran2008/codimension_attr_spec_r502d.py b/src/fparser/two/Fortran2008/codimension_attr_spec_r502d.py index a90502c42..e41f8b56a 100644 --- a/src/fparser/two/Fortran2008/codimension_attr_spec_r502d.py +++ b/src/fparser/two/Fortran2008/codimension_attr_spec_r502d.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Codimension_Attr_Spec rule R502.d """ + from fparser.two.Fortran2008.coarray_bracket_spec_r502d0 import Coarray_Bracket_Spec from fparser.two.utils import WORDClsBase diff --git a/src/fparser/two/Fortran2008/component_attr_spec_r437.py b/src/fparser/two/Fortran2008/component_attr_spec_r437.py index 4c4e9bb15..2f5fa3c5d 100644 --- a/src/fparser/two/Fortran2008/component_attr_spec_r437.py +++ b/src/fparser/two/Fortran2008/component_attr_spec_r437.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Component_Attr_Spec rule R437 """ + from fparser.two.Fortran2003 import Component_Attr_Spec as Component_Attr_Spec_2003 diff --git a/src/fparser/two/Fortran2008/connect_spec_r905.py b/src/fparser/two/Fortran2008/connect_spec_r905.py index 1cf60cc5c..460ae2d2d 100644 --- a/src/fparser/two/Fortran2008/connect_spec_r905.py +++ b/src/fparser/two/Fortran2008/connect_spec_r905.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Connect_Spec rule R905 """ + from fparser.two.Fortran2003 import ( Connect_Spec as Connect_Spec_2003, File_Unit_Number, diff --git a/src/fparser/two/Fortran2008/coshape_spec_r511a.py b/src/fparser/two/Fortran2008/coshape_spec_r511a.py index d514c5552..dc56c1ab2 100644 --- a/src/fparser/two/Fortran2008/coshape_spec_r511a.py +++ b/src/fparser/two/Fortran2008/coshape_spec_r511a.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Coshape_Spec rule R511.a """ + from fparser.common.splitline import string_replace_map from fparser.two.Fortran2008.lower_cobound_r512 import Lower_Cobound from fparser.two.Fortran2008.upper_cobound_r513 import Upper_Cobound diff --git a/src/fparser/two/Fortran2008/critical_construct_r810.py b/src/fparser/two/Fortran2008/critical_construct_r810.py index b6b9b8f7e..c1aa144bd 100644 --- a/src/fparser/two/Fortran2008/critical_construct_r810.py +++ b/src/fparser/two/Fortran2008/critical_construct_r810.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Critical_Construct rule R810 """ + from fparser.two.Fortran2003 import Execution_Part_Construct from fparser.two.Fortran2008.critical_stmt_r811 import Critical_Stmt from fparser.two.Fortran2008.end_critical_stmt_r812 import End_Critical_Stmt diff --git a/src/fparser/two/Fortran2008/critical_stmt_r811.py b/src/fparser/two/Fortran2008/critical_stmt_r811.py index 2e4c3211e..b5af83eca 100644 --- a/src/fparser/two/Fortran2008/critical_stmt_r811.py +++ b/src/fparser/two/Fortran2008/critical_stmt_r811.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Critical_Stmt rule R811 """ + from fparser.two.utils import StmtBase, WORDClsBase diff --git a/src/fparser/two/Fortran2008/data_component_def_stmt_r436.py b/src/fparser/two/Fortran2008/data_component_def_stmt_r436.py index a838824bb..f642787e5 100644 --- a/src/fparser/two/Fortran2008/data_component_def_stmt_r436.py +++ b/src/fparser/two/Fortran2008/data_component_def_stmt_r436.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Data_Component_Def_Stmt rule R436 """ + from fparser.two.Fortran2003 import ( Data_Component_Def_Stmt as Data_Component_Def_Stmt_2003, ) diff --git a/src/fparser/two/Fortran2008/declaration_construct_c1112.py b/src/fparser/two/Fortran2008/declaration_construct_c1112.py index 453388939..2f01ed352 100644 --- a/src/fparser/two/Fortran2008/declaration_construct_c1112.py +++ b/src/fparser/two/Fortran2008/declaration_construct_c1112.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Declaration_Construct constraint C1112 """ + from fparser.two.Fortran2003 import Declaration_Construct diff --git a/src/fparser/two/Fortran2008/deferred_coshape_spec_r510.py b/src/fparser/two/Fortran2008/deferred_coshape_spec_r510.py index 73b757627..a64a80f87 100644 --- a/src/fparser/two/Fortran2008/deferred_coshape_spec_r510.py +++ b/src/fparser/two/Fortran2008/deferred_coshape_spec_r510.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Deferred_Coshape_Spec rule R510 """ + from fparser.two.utils import SeparatorBase diff --git a/src/fparser/two/Fortran2008/do_term_action_stmt_r826.py b/src/fparser/two/Fortran2008/do_term_action_stmt_r826.py index 46e0f7685..d3733fc4b 100644 --- a/src/fparser/two/Fortran2008/do_term_action_stmt_r826.py +++ b/src/fparser/two/Fortran2008/do_term_action_stmt_r826.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Do_Term_Action_Stmt rule R826 """ + from fparser.two.Fortran2003 import Do_Term_Action_Stmt as Do_Term_Action_Stmt_2003 diff --git a/src/fparser/two/Fortran2008/end_block_stmt_r809.py b/src/fparser/two/Fortran2008/end_block_stmt_r809.py index dd65a790f..1ab1a066d 100644 --- a/src/fparser/two/Fortran2008/end_block_stmt_r809.py +++ b/src/fparser/two/Fortran2008/end_block_stmt_r809.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 End_Block_Stmt rule R809 """ + from fparser.two.utils import EndStmtBase diff --git a/src/fparser/two/Fortran2008/end_critical_stmt_r812.py b/src/fparser/two/Fortran2008/end_critical_stmt_r812.py index 898f8967b..b3c2cffe9 100644 --- a/src/fparser/two/Fortran2008/end_critical_stmt_r812.py +++ b/src/fparser/two/Fortran2008/end_critical_stmt_r812.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 End_Critical_Stmt rule R812 """ + from fparser.two.utils import EndStmtBase diff --git a/src/fparser/two/Fortran2008/end_submodule_stmt_r1119.py b/src/fparser/two/Fortran2008/end_submodule_stmt_r1119.py index d8deb2b8b..0e0ab1080 100644 --- a/src/fparser/two/Fortran2008/end_submodule_stmt_r1119.py +++ b/src/fparser/two/Fortran2008/end_submodule_stmt_r1119.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 End_Submodule_Stmt rule R1119 """ + from fparser.two.utils import EndStmtBase diff --git a/src/fparser/two/Fortran2008/error_stop_stmt_r856.py b/src/fparser/two/Fortran2008/error_stop_stmt_r856.py index a9c012181..6d75c9dc4 100644 --- a/src/fparser/two/Fortran2008/error_stop_stmt_r856.py +++ b/src/fparser/two/Fortran2008/error_stop_stmt_r856.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Error_Stop_Stmt rule R856 """ + from fparser.two.Fortran2003 import Stop_Code from fparser.two.utils import StmtBase, WORDClsBase diff --git a/src/fparser/two/Fortran2008/executable_construct_c201.py b/src/fparser/two/Fortran2008/executable_construct_c201.py index 5061450f0..8cafd0643 100644 --- a/src/fparser/two/Fortran2008/executable_construct_c201.py +++ b/src/fparser/two/Fortran2008/executable_construct_c201.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Executable_Construct constraint C201 """ + from fparser.two.Fortran2003 import ( Executable_Construct_C201 as Executable_Construct_C201_2003, ) diff --git a/src/fparser/two/Fortran2008/executable_construct_r213.py b/src/fparser/two/Fortran2008/executable_construct_r213.py index 387ffb620..74fc602c0 100644 --- a/src/fparser/two/Fortran2008/executable_construct_r213.py +++ b/src/fparser/two/Fortran2008/executable_construct_r213.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Executable_Construct rule R213 """ + from fparser.two.Fortran2003 import Executable_Construct as Executable_Construct_2003 diff --git a/src/fparser/two/Fortran2008/explicit_coshape_spec_r511.py b/src/fparser/two/Fortran2008/explicit_coshape_spec_r511.py index 308b2fafa..d62648b70 100644 --- a/src/fparser/two/Fortran2008/explicit_coshape_spec_r511.py +++ b/src/fparser/two/Fortran2008/explicit_coshape_spec_r511.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Explicit_Coshape_Spec rule R511 """ + from fparser.common.splitline import string_replace_map from fparser.two.Fortran2008.lower_cobound_r512 import Lower_Cobound from fparser.two.utils import SeparatorBase diff --git a/src/fparser/two/Fortran2008/if_stmt_r837.py b/src/fparser/two/Fortran2008/if_stmt_r837.py index 30adb18ba..d7f7f6f31 100644 --- a/src/fparser/two/Fortran2008/if_stmt_r837.py +++ b/src/fparser/two/Fortran2008/if_stmt_r837.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 If_Stmt rule R837 """ + from fparser.two.Fortran2003 import If_Stmt as If_Stmt_2003 from fparser.two.Fortran2008.action_stmt_c828 import Action_Stmt_C828 diff --git a/src/fparser/two/Fortran2008/implicit_part_c1112.py b/src/fparser/two/Fortran2008/implicit_part_c1112.py index 016b6f9fe..9ac9faead 100644 --- a/src/fparser/two/Fortran2008/implicit_part_c1112.py +++ b/src/fparser/two/Fortran2008/implicit_part_c1112.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Implicit_Part_Stmt constraint C1112 """ + from fparser.two.Fortran2003 import Implicit_Part from fparser.two.Fortran2008.implicit_part_stmt_c1112 import Implicit_Part_Stmt_C1112 from fparser.two.utils import BlockBase diff --git a/src/fparser/two/Fortran2008/implicit_part_stmt_c1112.py b/src/fparser/two/Fortran2008/implicit_part_stmt_c1112.py index c60fd6ec5..ee27e8475 100644 --- a/src/fparser/two/Fortran2008/implicit_part_stmt_c1112.py +++ b/src/fparser/two/Fortran2008/implicit_part_stmt_c1112.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Implicit_Part_Stmt constraint C1112 """ + from fparser.two.Fortran2003 import Implicit_Part_Stmt diff --git a/src/fparser/two/Fortran2008/label_do_stmt_r816.py b/src/fparser/two/Fortran2008/label_do_stmt_r816.py index ffcaf477d..09ec2db5a 100644 --- a/src/fparser/two/Fortran2008/label_do_stmt_r816.py +++ b/src/fparser/two/Fortran2008/label_do_stmt_r816.py @@ -40,6 +40,7 @@ use the F2008 version of loop-control """ + from fparser.two.Fortran2003 import Label_Do_Stmt as Label_Do_Stmt_2003 from fparser.two.Fortran2008 import Loop_Control diff --git a/src/fparser/two/Fortran2008/loop_control_r818.py b/src/fparser/two/Fortran2008/loop_control_r818.py index d143ccd37..35c4e599a 100644 --- a/src/fparser/two/Fortran2008/loop_control_r818.py +++ b/src/fparser/two/Fortran2008/loop_control_r818.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Loop_Control rule R818 """ + from fparser.two.Fortran2003 import Loop_Control as Loop_Control_2003, Forall_Header @@ -54,10 +55,10 @@ class Loop_Control(Loop_Control_2003): # R818 class. Something like the suggestion below. However, this would result in a different fparser tree, see issue #416. - F2003: While_Loop_Cntl: scalar-logical-expression, delim - F2003: Counter_Loop_Cntl: var, lower, upper, [step], delim - F2008: Concurrent_Loop_Cntl: conc_expr, delim - F2018: Concurrent_Loop_Cntl: conc_expr, local_x, delim + F2003 - While_Loop_Cntl: scalar-logical-expression, delim + F2003 - Counter_Loop_Cntl: var, lower, upper, [step], delim + F2008 - Concurrent_Loop_Cntl: conc_expr, delim + F2018 - Concurrent_Loop_Cntl: conc_expr, local_x, delim """ diff --git a/src/fparser/two/Fortran2008/lower_cobound_r512.py b/src/fparser/two/Fortran2008/lower_cobound_r512.py index 59842c548..d2c8e86b8 100644 --- a/src/fparser/two/Fortran2008/lower_cobound_r512.py +++ b/src/fparser/two/Fortran2008/lower_cobound_r512.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Lower_Cobound rule R512 """ + from fparser.two.utils import Base diff --git a/src/fparser/two/Fortran2008/nonlabel_do_stmt_r817.py b/src/fparser/two/Fortran2008/nonlabel_do_stmt_r817.py index 8db76f2c7..094423e4d 100644 --- a/src/fparser/two/Fortran2008/nonlabel_do_stmt_r817.py +++ b/src/fparser/two/Fortran2008/nonlabel_do_stmt_r817.py @@ -40,6 +40,7 @@ to use the F2008 version of loop-control """ + from fparser.two.Fortran2003 import Nonlabel_Do_Stmt as Nonlabel_Do_Stmt_2003 from fparser.two.Fortran2008 import Loop_Control diff --git a/src/fparser/two/Fortran2008/open_stmt_r904.py b/src/fparser/two/Fortran2008/open_stmt_r904.py index acdcc706a..e372b7fe8 100644 --- a/src/fparser/two/Fortran2008/open_stmt_r904.py +++ b/src/fparser/two/Fortran2008/open_stmt_r904.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Open_Stmt rule R904 """ + from fparser.two.Fortran2003 import Open_Stmt as Open_Stmt_2003 from fparser.two.utils import CALLBase diff --git a/src/fparser/two/Fortran2008/parent_identifier_r1118.py b/src/fparser/two/Fortran2008/parent_identifier_r1118.py index 345cef40a..67809c51c 100644 --- a/src/fparser/two/Fortran2008/parent_identifier_r1118.py +++ b/src/fparser/two/Fortran2008/parent_identifier_r1118.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Parent_Identifier rule R1118 """ + from fparser.two.utils import Base diff --git a/src/fparser/two/Fortran2008/procedure_stmt_r1206.py b/src/fparser/two/Fortran2008/procedure_stmt_r1206.py index b3cdbd3d3..d6aa4ce2b 100644 --- a/src/fparser/two/Fortran2008/procedure_stmt_r1206.py +++ b/src/fparser/two/Fortran2008/procedure_stmt_r1206.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Procedure_Stmt rule R1206 """ + from fparser.two.Fortran2003 import Procedure_Stmt as Procedure_Stmt_2003 diff --git a/src/fparser/two/Fortran2008/program_unit_r202.py b/src/fparser/two/Fortran2008/program_unit_r202.py index 3b5095ef5..7e4e5819e 100644 --- a/src/fparser/two/Fortran2008/program_unit_r202.py +++ b/src/fparser/two/Fortran2008/program_unit_r202.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Program_Unit rule R202 """ + from fparser.two.Fortran2003 import Program_Unit as Program_Unit_2003 diff --git a/src/fparser/two/Fortran2008/specification_part_c1112.py b/src/fparser/two/Fortran2008/specification_part_c1112.py index b89a69bde..20e3ef401 100644 --- a/src/fparser/two/Fortran2008/specification_part_c1112.py +++ b/src/fparser/two/Fortran2008/specification_part_c1112.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Specification_Part constraint C1112 """ + from fparser.two.Fortran2003 import Specification_Part, Use_Stmt, Import_Stmt from fparser.two.Fortran2008.declaration_construct_c1112 import ( Declaration_Construct_C1112, diff --git a/src/fparser/two/Fortran2008/stop_code_r857.py b/src/fparser/two/Fortran2008/stop_code_r857.py index e67c5180f..47d06daf7 100644 --- a/src/fparser/two/Fortran2008/stop_code_r857.py +++ b/src/fparser/two/Fortran2008/stop_code_r857.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Error_Stop_Stmt rule R857 """ + from fparser.two.utils import Base diff --git a/src/fparser/two/Fortran2008/submodule_r1116.py b/src/fparser/two/Fortran2008/submodule_r1116.py index 5b67d1af8..3b8fdbe17 100644 --- a/src/fparser/two/Fortran2008/submodule_r1116.py +++ b/src/fparser/two/Fortran2008/submodule_r1116.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Submodule rule R1116 """ + from fparser.two.Fortran2003 import Module_Subprogram_Part from fparser.two.Fortran2008.end_submodule_stmt_r1119 import End_Submodule_Stmt from fparser.two.Fortran2008.specification_part_c1112 import Specification_Part_C1112 diff --git a/src/fparser/two/Fortran2008/submodule_stmt_r1117.py b/src/fparser/two/Fortran2008/submodule_stmt_r1117.py index 92ef826a5..1ced0b232 100644 --- a/src/fparser/two/Fortran2008/submodule_stmt_r1117.py +++ b/src/fparser/two/Fortran2008/submodule_stmt_r1117.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Submodule_Stmt rule R1117 """ + from fparser.two.Fortran2008.parent_identifier_r1118 import Parent_Identifier from fparser.two.utils import Base, ScopingRegionMixin diff --git a/src/fparser/two/Fortran2008/type_declaration_stmt_r501.py b/src/fparser/two/Fortran2008/type_declaration_stmt_r501.py index db38e5605..353844cad 100644 --- a/src/fparser/two/Fortran2008/type_declaration_stmt_r501.py +++ b/src/fparser/two/Fortran2008/type_declaration_stmt_r501.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Type_Declaration_Stmt rule R501 """ + from fparser.two.Fortran2003 import Type_Declaration_Stmt as Type_Declaration_Stmt_2003 diff --git a/src/fparser/two/Fortran2008/upper_cobound_r513.py b/src/fparser/two/Fortran2008/upper_cobound_r513.py index 747cf635d..1ddaa3d34 100644 --- a/src/fparser/two/Fortran2008/upper_cobound_r513.py +++ b/src/fparser/two/Fortran2008/upper_cobound_r513.py @@ -35,6 +35,7 @@ """ Module containing Fortran2008 Upper_Cobound rule R513 """ + from fparser.two.utils import Base diff --git a/src/fparser/two/pattern_tools.py b/src/fparser/two/pattern_tools.py index 11c727188..22b640762 100644 --- a/src/fparser/two/pattern_tools.py +++ b/src/fparser/two/pattern_tools.py @@ -74,6 +74,7 @@ Created: Oct 2006 """ + import re dollar_ok = True diff --git a/src/fparser/two/symbol_table.py b/src/fparser/two/symbol_table.py index feed1994b..c5870b3ca 100644 --- a/src/fparser/two/symbol_table.py +++ b/src/fparser/two/symbol_table.py @@ -38,6 +38,7 @@ for all of the top-level scoping units encountered during parsing. """ + from collections import namedtuple diff --git a/src/fparser/two/tests/conftest.py b/src/fparser/two/tests/conftest.py index 67bd6bad7..1c757811c 100644 --- a/src/fparser/two/tests/conftest.py +++ b/src/fparser/two/tests/conftest.py @@ -36,6 +36,7 @@ directory """ + import pytest from fparser.two.parser import ParserFactory from fparser.two.symbol_table import SYMBOL_TABLES diff --git a/src/fparser/two/tests/fortran2003/conftest.py b/src/fparser/two/tests/fortran2003/conftest.py index 065bf475d..c0ece3828 100644 --- a/src/fparser/two/tests/fortran2003/conftest.py +++ b/src/fparser/two/tests/fortran2003/conftest.py @@ -36,6 +36,7 @@ directory """ + import pytest from fparser.two.parser import ParserFactory from fparser.two.Fortran2003 import Defined_Unary_Op, Defined_Binary_Op diff --git a/src/fparser/two/tests/fortran2003/test_associate_construct_r816.py b/src/fparser/two/tests/fortran2003/test_associate_construct_r816.py index 3f50156c1..3ef519578 100644 --- a/src/fparser/two/tests/fortran2003/test_associate_construct_r816.py +++ b/src/fparser/two/tests/fortran2003/test_associate_construct_r816.py @@ -111,28 +111,20 @@ def test_associate_construct(fake_symbol_table, code, expected_string): def test_end_block_missing_name(f2003_create, fake_symbol_table): """Check that a named associate block has a name at the end""" with pytest.raises(FortranSyntaxError) as exc_info: - Associate_Construct( - get_reader( - """\ + Associate_Construct(get_reader("""\ name:associate (xc => ax%b(i,j)%c) xc%dv = xc%dv + product(xc%ev(1:n)) end associate - """ - ) - ) + """)) assert exc_info.value.args[0].endswith("Expecting name 'name' but none given") def test_end_block_wrong_name(f2003_create, fake_symbol_table): """Check that a named associate block has the correct name at the end""" with pytest.raises(FortranSyntaxError) as exc_info: - Associate_Construct( - get_reader( - """\ + Associate_Construct(get_reader("""\ name:associate (xc => ax%b(i,j)%c) xc%dv = xc%dv + product(xc%ev(1:n)) end associate wrong - """ - ) - ) + """)) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") diff --git a/src/fparser/two/tests/fortran2003/test_block_do_construct_r826.py b/src/fparser/two/tests/fortran2003/test_block_do_construct_r826.py index b076813a0..812b0ee7e 100644 --- a/src/fparser/two/tests/fortran2003/test_block_do_construct_r826.py +++ b/src/fparser/two/tests/fortran2003/test_block_do_construct_r826.py @@ -51,81 +51,57 @@ def test_block_label_do_construct(): is parsed correctly (R826_1).""" tcls = Block_Label_Do_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do 12 a = 1 12 continue - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "DO 12\n a = 1\n12 CONTINUE" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ foo: do 21, i=1,10 a = 1 21 end do foo - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "foo:DO 21 , i = 1, 10\n a = 1\n21 END DO foo" - obj = tcls( - get_reader( - """ + obj = tcls(get_reader(""" do 51 while (a < 10) a = a + 1 51 continue - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "DO 51 WHILE (a < 10)\n a = a + 1\n51 CONTINUE" - obj = tcls( - get_reader( - """ + obj = tcls(get_reader(""" do 52 a = a + 1 if (a > 10) exit 52 continue - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "DO 52\n a = a + 1\n IF (a > 10) EXIT\n52 CONTINUE" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do 12 do 13 a = 1 13 continue 12 continue - """ - ) - ) + """)) assert str(obj) == "DO 12\n DO 13\n a = 1\n13 CONTINUE\n12 CONTINUE" assert len(obj.content) == 3, repr(len(obj.content)) assert str(obj.content[1]) == "DO 13\n a = 1\n13 CONTINUE" - obj = tcls( - get_reader( - """ + obj = tcls(get_reader(""" do 52, i = 1,10 do 53, while (j /= n) j = j + i 53 continue 52 continue - """ - ) - ) + """)) assert len(obj.content) == 3, repr(len(obj.content)) assert str(obj) == ( "DO 52 , i = 1, 10\n DO 53 , WHILE (j /= n)\n" @@ -141,97 +117,69 @@ def test_block_nonlabel_do_construct(): correctly (R826_2)""" tcls = Block_Nonlabel_Do_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do i=1,10 a = 1 end do - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "DO i = 1, 10\n a = 1\nEND DO" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do while (a < 10) a = a + 1 end do - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "DO WHILE (a < 10)\n a = a + 1\nEND DO" - obj = tcls( - get_reader( - """ + obj = tcls(get_reader(""" do a = a - 1 if (a < 10) exit end do - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "DO\n a = a - 1\n IF (a < 10) EXIT\nEND DO" assert len(obj.content) == 4, repr(len(obj.content)) assert str(obj.content[2]) == "IF (a < 10) EXIT" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ foo:do i=1,10 a = 1 end do foo - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "foo:DO i = 1, 10\n a = 1\nEND DO foo" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ foo:do while (a < 10) a = a + 1 end do foo - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "foo:DO WHILE (a < 10)\n a = a + 1\nEND DO foo" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do j=1,2 foo:do i=1,10 a = 1 end do foo end do - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == ( "DO j = 1, 2\n" " foo:DO i = 1, 10\n a = 1\n END DO foo\nEND DO" ) - obj = tcls( - get_reader( - """ + obj = tcls(get_reader(""" do while (j >= n) bar:do i=1,10 a = i + j end do bar j = j - 1 end do - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == ( "DO WHILE (j >= n)\n" @@ -239,17 +187,13 @@ def test_block_nonlabel_do_construct(): " j = j - 1\nEND DO" ) - obj = tcls( - get_reader( - """ + obj = tcls(get_reader(""" do, i = 1,10 bar: do, while (j /= n) a = i - j end do bar end do - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == ( "DO , i = 1, 10\n" @@ -274,28 +218,20 @@ def test_doconstruct_tofortran_non_ascii(): def test_do_construct_wrong_name(f2003_create, fake_symbol_table): """Check that named 'do' block has correct name at end of block""" with pytest.raises(FortranSyntaxError) as exc_info: - Block_Nonlabel_Do_Construct( - get_reader( - """\ + Block_Nonlabel_Do_Construct(get_reader("""\ name: do a = 1 - end do wrong""" - ) - ) + end do wrong""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_do_construct_missing_start_name(f2003_create, fake_symbol_table): """Check that named 'do' block has correct name at end of block""" with pytest.raises(FortranSyntaxError) as exc_info: - Block_Nonlabel_Do_Construct( - get_reader( - """\ + Block_Nonlabel_Do_Construct(get_reader("""\ do a = 1 - end do name""" - ) - ) + end do name""")) assert exc_info.value.args[0].endswith( "Name 'name' has no corresponding starting name" ) @@ -304,12 +240,8 @@ def test_do_construct_missing_start_name(f2003_create, fake_symbol_table): def test_do_construct_missing_end_name(f2003_create, fake_symbol_table): """Check that named 'do' block has correct name at end of block""" with pytest.raises(FortranSyntaxError) as exc_info: - Block_Nonlabel_Do_Construct( - get_reader( - """\ + Block_Nonlabel_Do_Construct(get_reader("""\ name: do a = 1 - end do""" - ) - ) + end do""")) assert exc_info.value.args[0].endswith("Expecting name 'name' but none given") diff --git a/src/fparser/two/tests/fortran2003/test_case_construct_r808.py b/src/fparser/two/tests/fortran2003/test_case_construct_r808.py index 057d6c74c..fe36a4e65 100644 --- a/src/fparser/two/tests/fortran2003/test_case_construct_r808.py +++ b/src/fparser/two/tests/fortran2003/test_case_construct_r808.py @@ -48,9 +48,7 @@ def test_case_construct(): """Basic test that we parse a Case Construct successfully.""" tcls = Case_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ select case (n) case (:-1) signum = -1 @@ -61,9 +59,7 @@ def test_case_construct(): case default signum = -2 end select -""" - ) - ) +""")) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "SELECT CASE (n)\nCASE (: - 1)\n signum = - 1\nCASE (0)\n" @@ -75,9 +71,7 @@ def test_case_construct(): def test_case_construct_name(f2003_create): """Basic test that we parse a Case Construct successfully.""" tcls = Case_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ name: select case (n) case (:-1) name signum = -1 @@ -88,9 +82,7 @@ def test_case_construct_name(f2003_create): case default name signum = -2 end select name - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) @@ -119,30 +111,22 @@ def test_tofortran_non_ascii(): def test_case_construct_wrong_name(f2003_create, fake_symbol_table): """Check that named 'case' block has correct matching start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Case_Construct( - get_reader( - """\ + Case_Construct(get_reader("""\ name: select case (n) case (:-1) a = 1 - end select wrong""" - ) - ) + end select wrong""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_case_construct_missing_start_name(f2003_create, fake_symbol_table): """Check that named 'case' block has correct matching start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Case_Construct( - get_reader( - """\ + Case_Construct(get_reader("""\ select case(n) case (:-1) a = 1 - end select name""" - ) - ) + end select name""")) assert exc_info.value.args[0].endswith( "Name 'name' has no corresponding starting name" ) @@ -151,28 +135,20 @@ def test_case_construct_missing_start_name(f2003_create, fake_symbol_table): def test_case_construct_missing_end_name(f2003_create, fake_symbol_table): """Check that named 'case' block has correct matching start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Case_Construct( - get_reader( - """\ + Case_Construct(get_reader("""\ name: select case(n) case (:-1) a = 1 - end select""" - ) - ) + end select""")) assert exc_info.value.args[0].endswith("Expecting name 'name' but none given") def test_case_construct_case_wrong_name(f2003_create, fake_symbol_table): """Check that named 'case' block has correct matching start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Case_Construct( - get_reader( - """\ + Case_Construct(get_reader("""\ name: select case(n) case (:-1) wrong a = 1 - end select name""" - ) - ) + end select name""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") diff --git a/src/fparser/two/tests/fortran2003/test_designator_r603.py b/src/fparser/two/tests/fortran2003/test_designator_r603.py index d72a688f0..7fe72a5f3 100644 --- a/src/fparser/two/tests/fortran2003/test_designator_r603.py +++ b/src/fparser/two/tests/fortran2003/test_designator_r603.py @@ -53,6 +53,7 @@ substring-range is a substring. """ + import pytest from fparser.two.Fortran2003 import ( Designator, diff --git a/src/fparser/two/tests/fortran2003/test_if_construct_r802.py b/src/fparser/two/tests/fortran2003/test_if_construct_r802.py index aacaf7bf0..d4983a187 100644 --- a/src/fparser/two/tests/fortran2003/test_if_construct_r802.py +++ b/src/fparser/two/tests/fortran2003/test_if_construct_r802.py @@ -48,33 +48,23 @@ def test_if_construct(): """Basic tests for the if construct.""" tcls = If_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (expr) then a = 1 end if - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "IF (expr) THEN\n a = 1\nEND IF" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ name: if (expr) then a = 1 end if name - """ - ) - ) + """)) assert str(obj) == "name:IF (expr) THEN\n a = 1\nEND IF name" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (expr) then a = 1 if (expr2) then @@ -82,45 +72,33 @@ def test_if_construct(): endif a = 3 end if - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "IF (expr) THEN\n a = 1\n IF (expr2) THEN\n a = 2\n" " END IF\n a = 3\nEND IF" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (expr) then a = 1 else if (expr2) then a = 2 end if - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "IF (expr) THEN\n a = 1\nELSE IF (expr2) THEN\n a = 2\nEND IF" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (expr) then a = 1 else a = 2 end if - """ - ) - ) + """)) assert str(obj) == "IF (expr) THEN\n a = 1\nELSE\n a = 2\nEND IF" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (expr) then a = 1 else if (expr2) then @@ -128,49 +106,37 @@ def test_if_construct(): else a = 3 end if - """ - ) - ) + """)) assert ( str(obj) == "IF (expr) THEN\n a = 1\nELSE IF (expr2) THEN\n a = 2\n" "ELSE\n a = 3\nEND IF" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ named: if (expr) then a = 1 else named a = 2 end if named - """ - ) - ) + """)) assert ( str(obj) == "named:IF (expr) THEN\n a = 1\nELSE named\n a = 2\nEND IF named" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ named: if (expr) then a = 1 named2: if (expr2) then a = 2 end if named2 end if named -""" - ) - ) +""")) assert ( str(obj) == "named:IF (expr) THEN\n a = 1\n named2:IF (expr2) THEN\n" " a = 2\n END IF named2\nEND IF named" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (expr) then a = 1 else if (expr2) then @@ -178,18 +144,14 @@ def test_if_construct(): else if (expr3) then a = 3 end if - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "IF (expr) THEN\n a = 1\nELSE IF (expr2) THEN\n a = 2\n" "ELSE IF (expr3) THEN\n a = 3\nEND IF" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (dxmx .gt. 0d0) then diff = 0 do 80 k = 1, n @@ -204,9 +166,7 @@ def test_if_construct(): do 82 k = 1, n 82 xnew(k) = xin(k) + betx*(xnew(k)-xin(k)) endif - endif""" - ) - ) + endif""")) assert isinstance(obj, tcls) @@ -224,28 +184,20 @@ def test_ifconstruct_tofortran_non_ascii(): def test_if_construct_wrong_name(f2003_create, fake_symbol_table): """Check named 'if' constructs have correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - If_Construct( - get_reader( - """\ + If_Construct(get_reader("""\ name: if (expr) then a = 1 - end if wrong""" - ) - ) + end if wrong""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_if_construct_missing_start_name(f2003_create, fake_symbol_table): """Check named 'if' constructs have correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - If_Construct( - get_reader( - """\ + If_Construct(get_reader("""\ if (expr) then a = 1 - end if name""" - ) - ) + end if name""")) assert exc_info.value.args[0].endswith( "Name 'name' has no corresponding starting name" ) @@ -254,60 +206,44 @@ def test_if_construct_missing_start_name(f2003_create, fake_symbol_table): def test_if_construct_missing_end_name(f2003_create, fake_symbol_table): """Check named 'if' constructs have correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - If_Construct( - get_reader( - """\ + If_Construct(get_reader("""\ name: if (expr) then a = 1 - end if""" - ) - ) + end if""")) assert exc_info.value.args[0].endswith("Expecting name 'name' but none given") def test_if_construct_else_wrong_end_name(f2003_create, fake_symbol_table): """Check named 'if' constructs have correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - If_Construct( - get_reader( - """\ + If_Construct(get_reader("""\ name: if (expr) then a = 1 else a = 2 - end if wrong""" - ) - ) + end if wrong""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_if_construct_else_wrong_name(f2003_create, fake_symbol_table): """Check named 'if' constructs have correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - If_Construct( - get_reader( - """\ + If_Construct(get_reader("""\ name: if (expr) then a = 1 else wrong a = 2 - end if name""" - ) - ) + end if name""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_if_construct_else_if_wrong_name(f2003_create, fake_symbol_table): """Check named 'if' constructs have correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - If_Construct( - get_reader( - """\ + If_Construct(get_reader("""\ name: if (expr) then a = 1 else if (other_expr) then wrong a = 2 - end if name""" - ) - ) + end if name""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") diff --git a/src/fparser/two/tests/fortran2003/test_intrinsics.py b/src/fparser/two/tests/fortran2003/test_intrinsics.py index 21a5270b0..fee4a98aa 100644 --- a/src/fparser/two/tests/fortran2003/test_intrinsics.py +++ b/src/fparser/two/tests/fortran2003/test_intrinsics.py @@ -282,9 +282,7 @@ def test_intrinsic_inside_intrinsic(): def test_locally_shadowed_intrinsic(f2003_parser): """Check that a locally-defined symbol that shadows (overwrites) a Fortran intrinsic is correctly identified.""" - tree = f2003_parser( - get_reader( - """\ + tree = f2003_parser(get_reader("""\ module my_mod use some_mod real :: dot_product(2,2) @@ -294,9 +292,7 @@ def test_locally_shadowed_intrinsic(f2003_parser): result = dot_product(1,1) end subroutine my_sub end module my_mod - """ - ) - ) + """)) tables = SYMBOL_TABLES # We should not have an intrinsic-function reference in the parse tree assert not walk(tree, Intrinsic_Function_Reference) @@ -308,9 +304,7 @@ def test_locally_shadowed_intrinsic(f2003_parser): def test_shadowed_intrinsic_named_import(f2003_parser): """Check that an imported symbol that shadows (overwrites) a Fortran intrinsic is correctly identified.""" - tree = f2003_parser( - get_reader( - """\ + tree = f2003_parser(get_reader("""\ module my_mod use some_mod, only: dot_product contains @@ -319,9 +313,7 @@ def test_shadowed_intrinsic_named_import(f2003_parser): result = dot_product(1,1) end subroutine my_sub end module my_mod - """ - ) - ) + """)) tables = SYMBOL_TABLES # We should not have an intrinsic-function reference in the parse tree assert not walk(tree, Intrinsic_Function_Reference) @@ -337,9 +329,7 @@ def test_shadowed_intrinsic_import(f2003_parser, use_stmts): number of 'arguments'. """ - tree = f2003_parser( - get_reader( - f"""\ + tree = f2003_parser(get_reader(f"""\ module my_mod {use_stmts[0]}\n contains @@ -365,9 +355,7 @@ def test_shadowed_intrinsic_import(f2003_parser, use_stmts): end function tricky end subroutine my_sub end module my_mod - """ - ) - ) + """)) # We should not have an intrinsic-function reference in the parse tree assert not walk(tree, Intrinsic_Function_Reference) @@ -377,9 +365,7 @@ def test_shadowed_intrinsic_error(f2003_parser): Fortran intrinsic is not identified as an intrinsic if it has the wrong types of argument. At the moment we are unable to check the types of arguments (TODO #201) and so this test x-fails.""" - tree = f2003_parser( - get_reader( - """\ + tree = f2003_parser(get_reader("""\ module my_mod use some_mod contains @@ -388,9 +374,7 @@ def test_shadowed_intrinsic_error(f2003_parser): result = dot_product(1,1) end subroutine my_sub end module my_mod - """ - ) - ) + """)) # We should not have an intrinsic-function reference in the parse tree if walk(tree, Intrinsic_Function_Reference): pytest.xfail("TODO #201: incorrect match of Intrinsic_Function_Reference") diff --git a/src/fparser/two/tests/fortran2003/test_kindselector_r404.py b/src/fparser/two/tests/fortran2003/test_kindselector_r404.py index 00c50b0ac..39923175e 100644 --- a/src/fparser/two/tests/fortran2003/test_kindselector_r404.py +++ b/src/fparser/two/tests/fortran2003/test_kindselector_r404.py @@ -238,12 +238,10 @@ def test_to_be_moved(f2003_create): here for the moment until the reason for the error is fixed. """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutine test() integer( x) y end subroutine - """ - ) + """) ast = Program(reader) assert ("SUBROUTINE test\n" " integer( x) y\n" "END SUBROUTINE") in str(ast) diff --git a/src/fparser/two/tests/fortran2003/test_loop_control_r830.py b/src/fparser/two/tests/fortran2003/test_loop_control_r830.py index a758342d0..8aa6de472 100644 --- a/src/fparser/two/tests/fortran2003/test_loop_control_r830.py +++ b/src/fparser/two/tests/fortran2003/test_loop_control_r830.py @@ -36,6 +36,7 @@ loop-control rule. """ + import pytest from fparser.two.Fortran2003 import Loop_Control from fparser.two.utils import NoMatchError diff --git a/src/fparser/two/tests/fortran2003/test_namelist_stmt_r552.py b/src/fparser/two/tests/fortran2003/test_namelist_stmt_r552.py index bdedf824e..5701d6fb2 100644 --- a/src/fparser/two/tests/fortran2003/test_namelist_stmt_r552.py +++ b/src/fparser/two/tests/fortran2003/test_namelist_stmt_r552.py @@ -36,6 +36,7 @@ NAMELIST statement. """ + import pytest from fparser.two.Fortran2003 import Namelist_Stmt diff --git a/src/fparser/two/tests/fortran2003/test_nonblock_do_construct_r835.py b/src/fparser/two/tests/fortran2003/test_nonblock_do_construct_r835.py index 7b7886d38..5a0710c54 100644 --- a/src/fparser/two/tests/fortran2003/test_nonblock_do_construct_r835.py +++ b/src/fparser/two/tests/fortran2003/test_nonblock_do_construct_r835.py @@ -46,37 +46,25 @@ def test_nonblock_do_construct(): """Tests that nonblock DO construct is parsed correctly (R835).""" tcls = Nonblock_Do_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do 20, i = 1, 3 20 rotm(i,j) = r2(j,i) - """ - ) - ) + """)) assert isinstance(obj, Action_Term_Do_Construct), repr(obj) assert str(obj) == "DO 20 , i = 1, 3\n20 rotm(i, j) = r2(j, i)" # Without the comma after the label - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do 20 i = 1, 3 20 rotm(i,j) = r2(j,i) - """ - ) - ) + """)) assert isinstance(obj, Action_Term_Do_Construct), repr(obj) assert str(obj) == "DO 20 i = 1, 3\n20 rotm(i, j) = r2(j, i)" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do 50, i = n, m, -1 50 call foo(a) - """ - ) - ) + """)) assert isinstance(obj, Action_Term_Do_Construct), repr(obj) assert str(obj) == "DO 50 , i = n, m, - 1\n50 CALL foo(a)" @@ -85,17 +73,13 @@ def test_nonblock_do_construct(): def test_outer_shared_do_construct(): """Test for parsing of an outer-shared do construct (R839).""" tcls = Nonblock_Do_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ do 20, i = 1, 3 k = 3 do 20, j = 1, 3 l = 3 20 rotm(i,j) = r2(j,i) - """ - ) - ) + """)) assert isinstance(obj, Action_Term_Do_Construct), repr(obj) assert str(obj) == ( "DO 20 , i = 1, 3\n k = 3\n DO 20 , j = 1, 3\n l = 3\n" diff --git a/src/fparser/two/tests/fortran2003/test_prefix_r1227.py b/src/fparser/two/tests/fortran2003/test_prefix_r1227.py index b6a947d5d..496b05e38 100644 --- a/src/fparser/two/tests/fortran2003/test_prefix_r1227.py +++ b/src/fparser/two/tests/fortran2003/test_prefix_r1227.py @@ -33,6 +33,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Test Fortran 2003 rule R1227 : prefix.""" + import pytest import fparser.two.Fortran2003 as f2003 diff --git a/src/fparser/two/tests/fortran2003/test_primary_r701.py b/src/fparser/two/tests/fortran2003/test_primary_r701.py index 41040d1cf..b672c41c2 100644 --- a/src/fparser/two/tests/fortran2003/test_primary_r701.py +++ b/src/fparser/two/tests/fortran2003/test_primary_r701.py @@ -42,6 +42,7 @@ type defined outside of Primary. """ + import sys import pytest diff --git a/src/fparser/two/tests/fortran2003/test_program_r201.py b/src/fparser/two/tests/fortran2003/test_program_r201.py index ded1ed6b2..beac0079b 100644 --- a/src/fparser/two/tests/fortran2003/test_program_r201.py +++ b/src/fparser/two/tests/fortran2003/test_program_r201.py @@ -80,12 +80,10 @@ def test_only_comments(f2003_create, ignore_comments): @pytest.mark.usefixtures("f2003_create") def test_single(): """Test that a single program_unit can be parsed successfully.""" - reader = get_reader( - """\ + reader = get_reader("""\ subroutine test() end subroutine - """ - ) + """) ast = Program(reader) assert "SUBROUTINE test\n" "END SUBROUTINE" in str(ast) # Check that the Name of the subroutine has the correct parent @@ -96,12 +94,10 @@ def test_single(): def test_single_with_end_name(): """Test that a single program_unit can be parsed successfully when it has a name specified on the end clause.""" - reader = get_reader( - """\ + reader = get_reader("""\ subroutine test() end subroutine test - """ - ) + """) ast = Program(reader) assert "SUBROUTINE test\n" "END SUBROUTINE test" in str(ast) # Check parent information has been set-up correctly @@ -117,13 +113,11 @@ def test_single2(f2003_create): of the line reports an error on the correct (first) line """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutin test() end subroutine - """ - ) + """) with pytest.raises(FortranSyntaxError) as excinfo: dummy_ = Program(reader) assert "at line 1\n>>> subroutin test()\n" in str(excinfo.value) @@ -137,13 +131,11 @@ def test_single3(f2003_create): of the line reports an error on the correct (second) line """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutine test() end subroutin - """ - ) + """) with pytest.raises(FortranSyntaxError) as excinfo: dummy_ = Program(reader) assert "at line 2\n>>> end subroutin\n" in str(excinfo.value) @@ -154,12 +146,10 @@ def test_single_error1(f2003_create): statement raises an appropriate exception """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutin test() end subroutine - """ - ) + """) with pytest.raises(FortranSyntaxError) as excinfo: dummy_ = Program(reader) assert "at line 1\n>>> subroutin test()\n" in str(excinfo.value) @@ -181,14 +171,12 @@ def test_single_error2(f2003_create): def test_multiple(f2003_create): """Test that multiple program_units can be parsed successfully.""" - reader = get_reader( - """\ + reader = get_reader("""\ subroutine test() end subroutine subroutine test2() end subroutine test2 - """ - ) + """) ast = Program(reader) assert "SUBROUTINE test\n" "END SUBROUTINE" in str(ast) @@ -202,14 +190,12 @@ def test_multiple_error1(f2003_create): exception """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutine test() end subroutine subroutine test() end subroutine - """ - ) + """) with pytest.raises(FortranSyntaxError) as excinfo: dummy_ = Program(reader) assert "XXX" in str(excinfo.value) @@ -220,14 +206,12 @@ def test_multiple_error2(f2003_create): exception """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutine 1test() end subroutine subroutine test() end subroutine - """ - ) + """) with pytest.raises(FortranSyntaxError) as excinfo: dummy_ = Program(reader) assert "at line 1\n>>> subroutine 1test()\n" in str(excinfo.value) @@ -238,13 +222,11 @@ def test_multiple_error3(f2003_create): appropriate exception """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutine test() end subroutine subroutine test() - end subroutin""" - ) + end subroutin""") with pytest.raises(FortranSyntaxError) as excinfo: dummy_ = Program(reader) assert "at line 4\n>>> end subroutin\n" in str(excinfo.value) @@ -260,11 +242,9 @@ def test_missing_prog(f2003_create): in Program. """ - reader = get_reader( - """\ + reader = get_reader("""\ end - """ - ) + """) ast = Program(reader) assert "END" in str(ast) reader = get_reader( @@ -285,13 +265,11 @@ def test_missing_prog_multi(f2003_create): can be parsed successfully when it is not the first program_unit. """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutine first end end - """ - ) + """) ast = Program(reader) assert "SUBROUTINE first\n" "END SUBROUTINE" in str(ast) assert "END PROGRAM" in str(ast) @@ -303,14 +281,12 @@ def test_missing_prog_multi(f2003_create): @pytest.mark.xfail(reason="Only one main program is allowed in a program") def test_one_main1(f2003_create): """Test that multiple main programs raise an exception.""" - reader = get_reader( - """\ + reader = get_reader("""\ program first end program second end - """ - ) + """) with pytest.raises(FortranSyntaxError) as excinfo: dummy_ = Program(reader) assert "XXX" in str(excinfo.value) @@ -334,14 +310,12 @@ def test_comment0(f2003_create): def test_comment1(f2003_create): """Test that a single program_unit can be parsed successfully with comments being ignored.""" - reader = get_reader( - """\ + reader = get_reader("""\ ! comment1 subroutine test() end subroutine ! comment2 - """ - ) + """) ast = Program(reader) assert "SUBROUTINE test\n" "END SUBROUTINE" in str(ast) assert "! comment" not in str(ast) diff --git a/src/fparser/two/tests/fortran2003/test_select_type_construct_r821.py b/src/fparser/two/tests/fortran2003/test_select_type_construct_r821.py index 8143dd8f2..86e1b6133 100644 --- a/src/fparser/two/tests/fortran2003/test_select_type_construct_r821.py +++ b/src/fparser/two/tests/fortran2003/test_select_type_construct_r821.py @@ -70,30 +70,22 @@ def test_select_type_construct(): def test_select_type_construct_wrong_name(f2003_create, fake_symbol_table): """Check named 'select type' construct has correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - Select_Type_Construct( - get_reader( - """\ + Select_Type_Construct(get_reader("""\ name: select type (n) type is (point) a = 1 - end select wrong""" - ) - ) + end select wrong""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_select_type_construct_missing_start_name(f2003_create, fake_symbol_table): """Check named 'select type' construct has correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - Select_Type_Construct( - get_reader( - """\ + Select_Type_Construct(get_reader("""\ select type(n) type is (point) a = 1 - end select name""" - ) - ) + end select name""")) assert exc_info.value.args[0].endswith( "Name 'name' has no corresponding starting name" ) @@ -102,28 +94,20 @@ def test_select_type_construct_missing_start_name(f2003_create, fake_symbol_tabl def test_select_type_construct_missing_end_name(f2003_create, fake_symbol_table): """Check named 'select type' construct has correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - Select_Type_Construct( - get_reader( - """\ + Select_Type_Construct(get_reader("""\ name: select type(n) type is (point) a = 1 - end select""" - ) - ) + end select""")) assert exc_info.value.args[0].endswith("Expecting name 'name' but none given") def test_select_type_construct_select_type_wrong_name(f2003_create, fake_symbol_table): """Check named 'select type' construct has correct start/end names""" with pytest.raises(FortranSyntaxError) as exc_info: - Select_Type_Construct( - get_reader( - """\ + Select_Type_Construct(get_reader("""\ name: select type(n) type is (point) wrong a = 1 - end select name""" - ) - ) + end select name""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") diff --git a/src/fparser/two/tests/fortran2003/test_stmt_function_stmt_r1238.py b/src/fparser/two/tests/fortran2003/test_stmt_function_stmt_r1238.py index cb1934656..865a3e95a 100644 --- a/src/fparser/two/tests/fortran2003/test_stmt_function_stmt_r1238.py +++ b/src/fparser/two/tests/fortran2003/test_stmt_function_stmt_r1238.py @@ -36,6 +36,7 @@ Stmt_Function_Stmt class. """ + import pytest from fparser.two.Fortran2003 import Stmt_Function_Stmt diff --git a/src/fparser/two/tests/fortran2003/test_type_guard_stmt_r823.py b/src/fparser/two/tests/fortran2003/test_type_guard_stmt_r823.py index 0913a57bc..c7861af94 100644 --- a/src/fparser/two/tests/fortran2003/test_type_guard_stmt_r823.py +++ b/src/fparser/two/tests/fortran2003/test_type_guard_stmt_r823.py @@ -39,6 +39,7 @@ or CLASS DEFAULT [ select-construct-name ] """ + import pytest from fparser.two.Fortran2003 import Type_Guard_Stmt diff --git a/src/fparser/two/tests/fortran2003/test_where_construct_r744.py b/src/fparser/two/tests/fortran2003/test_where_construct_r744.py index 7a8f5f01e..32c589784 100644 --- a/src/fparser/two/tests/fortran2003/test_where_construct_r744.py +++ b/src/fparser/two/tests/fortran2003/test_where_construct_r744.py @@ -48,18 +48,14 @@ def test_where_construct(): """Tests for the WHERE construct, R744.""" tcls = Where_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ where (pressure <= 1.0) pressure = pressure + inc_pressure temp = temp - 5.0 elsewhere raining = .true. end where -""" - ) - ) +""")) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "WHERE (pressure <= 1.0)\n " @@ -68,58 +64,42 @@ def test_where_construct(): "ELSEWHERE\n raining = .TRUE.\nEND WHERE" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ where (cond1) else where (cond2) end where -""" - ) - ) +""")) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "WHERE (cond1)\nELSEWHERE(cond2)\nEND WHERE" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ n:where (cond1) elsewhere (cond2) n else where n end where n -""" - ) - ) +""")) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "n:WHERE (cond1)\nELSEWHERE(cond2) n\n" "ELSEWHERE n\nEND WHERE n" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ n:where (cond1) else where (cond2) n else where n end where n -""" - ) - ) +""")) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "n:WHERE (cond1)\nELSEWHERE(cond2) n\nELSEWHERE n\n" "END WHERE n" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ n:where (me(:)=="hello") else where (me(:)=="goodbye") n else where n end where n -""" - ) - ) +""")) assert ( str(obj) == 'n:WHERE (me(:) == "hello")\nELSEWHERE(me(:) == "goodbye") n\n' "ELSEWHERE n\n" @@ -141,28 +121,20 @@ def test_where_tofortran_non_ascii(): def test_where_construct_wrong_name(f2003_create, fake_symbol_table): """Check named 'where' construct has correct start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Where_Construct( - get_reader( - """\ + Where_Construct(get_reader("""\ name: where (expr) a = 1 - end where wrong""" - ) - ) + end where wrong""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_where_construct_missing_start_name(f2003_create, fake_symbol_table): """Check named 'where' construct has correct start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Where_Construct( - get_reader( - """\ + Where_Construct(get_reader("""\ where (expr) a = 1 - end where name""" - ) - ) + end where name""")) assert exc_info.value.args[0].endswith( "Name 'name' has no corresponding starting name" ) @@ -171,60 +143,44 @@ def test_where_construct_missing_start_name(f2003_create, fake_symbol_table): def test_where_construct_missing_end_name(f2003_create, fake_symbol_table): """Check named 'where' construct has correct start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Where_Construct( - get_reader( - """\ + Where_Construct(get_reader("""\ name: where (expr) a = 1 - end where""" - ) - ) + end where""")) assert exc_info.value.args[0].endswith("Expecting name 'name' but none given") def test_where_construct_else_wrong_end_name(f2003_create, fake_symbol_table): """Check named 'where' construct has correct start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Where_Construct( - get_reader( - """\ + Where_Construct(get_reader("""\ name: where (expr) a = 1 elsewhere a = 2 - end where wrong""" - ) - ) + end where wrong""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_where_construct_else_wrong_name(f2003_create, fake_symbol_table): """Check named 'where' construct has correct start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Where_Construct( - get_reader( - """\ + Where_Construct(get_reader("""\ name: where (expr) a = 1 elsewhere wrong a = 2 - end where name""" - ) - ) + end where name""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") def test_where_construct_else_where_wrong_name(f2003_create, fake_symbol_table): """Check named 'where' construct has correct start/end name""" with pytest.raises(FortranSyntaxError) as exc_info: - Where_Construct( - get_reader( - """\ + Where_Construct(get_reader("""\ name: where (expr) a = 1 elsewhere (other_expr) wrong a = 2 - end where name""" - ) - ) + end where name""")) assert exc_info.value.args[0].endswith("Expecting name 'name', got 'wrong'") diff --git a/src/fparser/two/tests/fortran2008/conftest.py b/src/fparser/two/tests/fortran2008/conftest.py index 3805d6756..87eb8d992 100644 --- a/src/fparser/two/tests/fortran2008/conftest.py +++ b/src/fparser/two/tests/fortran2008/conftest.py @@ -36,6 +36,7 @@ directory """ + import pytest from fparser.two.parser import ParserFactory diff --git a/src/fparser/two/tests/fortran2008/test_action_stmt_r214.py b/src/fparser/two/tests/fortran2008/test_action_stmt_r214.py index 8de726cc5..74080a294 100644 --- a/src/fparser/two/tests/fortran2008/test_action_stmt_r214.py +++ b/src/fparser/two/tests/fortran2008/test_action_stmt_r214.py @@ -162,15 +162,11 @@ def test_other(string, cls): def test_other_functional(f2008_parser): """Test previous subclasses are still matched correctly in a subroutine.""" - tree = f2008_parser( - get_reader( - """\ + tree = f2008_parser(get_reader("""\ subroutine my_abort stop end subroutine my_abort - """ - ) - ) + """)) assert walk(tree, Stop_Stmt) assert "STOP" in str(tree) diff --git a/src/fparser/two/tests/fortran2008/test_action_term_do_construct_r824.py b/src/fparser/two/tests/fortran2008/test_action_term_do_construct_r824.py index 2254ca066..f8b42fe0d 100644 --- a/src/fparser/two/tests/fortran2008/test_action_term_do_construct_r824.py +++ b/src/fparser/two/tests/fortran2008/test_action_term_do_construct_r824.py @@ -42,6 +42,7 @@ use the F2008 version of label-do-stmt """ + import pytest from fparser.api import get_reader diff --git a/src/fparser/two/tests/fortran2008/test_block.py b/src/fparser/two/tests/fortran2008/test_block.py index ba63e4a3c..590c004a9 100644 --- a/src/fparser/two/tests/fortran2008/test_block.py +++ b/src/fparser/two/tests/fortran2008/test_block.py @@ -46,16 +46,12 @@ def test_block(): """Test that the Block_Construct matches as expected.""" - block = Block_Construct( - get_reader( - """\ + block = Block_Construct(get_reader("""\ block integer :: b = 4 a = 1 + b end block - """ - ) - ) + """)) assert isinstance(block.children[0], Block_Stmt) assert isinstance(block.children[0], ScopingRegionMixin) name = block.children[0].get_scope_name() @@ -68,9 +64,7 @@ def test_block(): ) def test_block_new_scope(f2008_parser, before, after): """Test that a Block_Construct creates a new scoping region.""" - block = f2008_parser( - get_reader( - f"""\ + block = f2008_parser(get_reader(f"""\ program foo integer :: b = 3 {before} @@ -80,9 +74,7 @@ def test_block_new_scope(f2008_parser, before, after): end block {after} end program foo - """ - ) - ) + """)) assert "BLOCK\nINTEGER :: b = 4\na = 1 + b\nEND BLOCK" in str(block).replace( " ", "" @@ -96,9 +88,7 @@ def test_block_new_scope(f2008_parser, before, after): def test_block_in_if(f2008_parser): """Test that a Block may appear inside an IF.""" - ptree = f2008_parser( - get_reader( - """\ + ptree = f2008_parser(get_reader("""\ program foo integer :: b = 3 if (b == 2) then @@ -109,9 +99,7 @@ def test_block_in_if(f2008_parser): end block end if end program foo - """ - ) - ) + """)) blocks = walk([ptree], Block_Construct) assert len(blocks) == 1 @@ -122,16 +110,12 @@ def test_named_block(): reproduced. """ - block = Block_Construct( - get_reader( - """\ + block = Block_Construct(get_reader("""\ foo: block integer :: b = 4 a = 1 + b end block foo - """ - ) - ) + """)) assert "foo:BLOCK\n INTEGER :: b = 4\n a = 1 + b\nEND BLOCK foo" in str(block) @@ -143,14 +127,10 @@ def test_end_block_missing_start_name(): # C808 """ with pytest.raises(FortranSyntaxError) as err: - Block_Construct( - get_reader( - """\ + Block_Construct(get_reader("""\ block end block foo - """ - ) - ) + """)) assert "Name 'foo' has no corresponding starting name" in str(err) @@ -161,14 +141,10 @@ def test_end_block_missing_end_name(): # C808 """ with pytest.raises(FortranSyntaxError) as err: - Block_Construct( - get_reader( - """\ + Block_Construct(get_reader("""\ foo: block end block - """ - ) - ) + """)) assert "Expecting name 'foo' but none given" in str(err) @@ -179,14 +155,10 @@ def test_end_block_wrong_name(): # C808 """ with pytest.raises(FortranSyntaxError) as err: - Block_Construct( - get_reader( - """\ + Block_Construct(get_reader("""\ foo: block end block bar - """ - ) - ) + """)) assert "Expecting name 'foo', got 'bar'" in str(err) diff --git a/src/fparser/two/tests/fortran2008/test_block_label_do_construct_r814_1.py b/src/fparser/two/tests/fortran2008/test_block_label_do_construct_r814_1.py index dee8ffe25..d99516ec3 100644 --- a/src/fparser/two/tests/fortran2008/test_block_label_do_construct_r814_1.py +++ b/src/fparser/two/tests/fortran2008/test_block_label_do_construct_r814_1.py @@ -46,6 +46,7 @@ use the F2008 version of label-do-stmt """ + import pytest from fparser.api import get_reader diff --git a/src/fparser/two/tests/fortran2008/test_block_nonlabel_do_construct_r814_2.py b/src/fparser/two/tests/fortran2008/test_block_nonlabel_do_construct_r814_2.py index ae234e99d..3a8aa97ab 100644 --- a/src/fparser/two/tests/fortran2008/test_block_nonlabel_do_construct_r814_2.py +++ b/src/fparser/two/tests/fortran2008/test_block_nonlabel_do_construct_r814_2.py @@ -46,6 +46,7 @@ use the F2008 version of nonlabel-do-stmt """ + import pytest from fparser.api import get_reader diff --git a/src/fparser/two/tests/fortran2008/test_critical.py b/src/fparser/two/tests/fortran2008/test_critical.py index e9e6d6d26..6acdfc662 100644 --- a/src/fparser/two/tests/fortran2008/test_critical.py +++ b/src/fparser/two/tests/fortran2008/test_critical.py @@ -35,7 +35,6 @@ """Module containing pytest tests for the support of the Fortran2008 Critical construct.""" - import pytest from fparser.api import get_reader @@ -46,15 +45,11 @@ def test_critical(): """Test that a basic critical construct is correctly constructed.""" - critical = Critical_Construct( - get_reader( - """\ + critical = Critical_Construct(get_reader("""\ critical a = 1 + b end critical - """ - ) - ) + """)) assert isinstance(critical.children[0], Critical_Stmt) assert isinstance(critical.children[1], Assignment_Stmt) assert isinstance(critical.children[2], End_Critical_Stmt) @@ -65,15 +60,11 @@ def test_critical(): def test_named_critical(): """Test that a named critical construct is matched correctly and that its name can be queried.""" - critical = Critical_Construct( - get_reader( - """\ + critical = Critical_Construct(get_reader("""\ foo: critical a = 1 + b end critical foo - """ - ) - ) + """)) assert critical.children[0].get_start_name() == "foo" assert "foo:CRITICAL\n a = 1 + b\nEND CRITICAL foo" in str(critical) @@ -82,14 +73,10 @@ def test_end_critical_missing_start_name(): # C809 """Check that a critical construct with an end name but no start name results in a syntax error (C809).""" with pytest.raises(FortranSyntaxError) as err: - Critical_Construct( - get_reader( - """\ + Critical_Construct(get_reader("""\ critical end critical foo - """ - ) - ) + """)) assert "Name 'foo' has no corresponding starting name" in str(err) @@ -97,26 +84,18 @@ def test_end_critical_missing_end_name(): # C809 """Test that a named critical construct with the name omitted from the end critical results in a syntax error (C809).""" with pytest.raises(FortranSyntaxError) as err: - Critical_Construct( - get_reader( - """\ + Critical_Construct(get_reader("""\ foo: critical end critical - """ - ) - ) + """)) assert "Expecting name 'foo' but none given" in str(err) def test_end_critical_wrong_name(): # C809 """Test that mismatched start and end names result in a syntax error (C809)""" with pytest.raises(FortranSyntaxError) as err: - Critical_Construct( - get_reader( - """\ + Critical_Construct(get_reader("""\ foo: critical end critical bar - """ - ) - ) + """)) assert "Expecting name 'foo', got 'bar'" in str(err) diff --git a/src/fparser/two/tests/fortran2008/test_end_submodule_stmt_r1119.py b/src/fparser/two/tests/fortran2008/test_end_submodule_stmt_r1119.py index 12d8664dc..d45013afd 100644 --- a/src/fparser/two/tests/fortran2008/test_end_submodule_stmt_r1119.py +++ b/src/fparser/two/tests/fortran2008/test_end_submodule_stmt_r1119.py @@ -37,6 +37,7 @@ end-submodule-stmt is END [ SUBMODULE [ submodule-name ] ] """ + import pytest from fparser.two.utils import NoMatchError from fparser.two.Fortran2008 import End_Submodule_Stmt diff --git a/src/fparser/two/tests/fortran2008/test_error_stop_stmt_r856.py b/src/fparser/two/tests/fortran2008/test_error_stop_stmt_r856.py index 4be761d5a..16ac2093d 100644 --- a/src/fparser/two/tests/fortran2008/test_error_stop_stmt_r856.py +++ b/src/fparser/two/tests/fortran2008/test_error_stop_stmt_r856.py @@ -69,31 +69,23 @@ def test_error1(): def test_functional1(f2008_parser): """Test error-stop-stmt is matched in a subroutine.""" - tree = f2008_parser( - get_reader( - """\ + tree = f2008_parser(get_reader("""\ subroutine my_abort error stop end subroutine my_abort - """ - ) - ) + """)) assert walk(tree, Error_Stop_Stmt) assert "ERROR STOP" in str(tree) def test_functional2(f2008_parser): """Test error-stop-stmt is matched in a if-stmt.""" - tree = f2008_parser( - get_reader( - """\ + tree = f2008_parser(get_reader("""\ subroutine my_abort(err_code) implicit none integer, intent(in) :: err_code if (err_code /= 0) error stop err_code end subroutine my_abort - """ - ) - ) + """)) assert walk(tree, Error_Stop_Stmt) assert "ERROR STOP err_code" in str(tree) diff --git a/src/fparser/two/tests/fortran2008/test_intrinsics_2008.py b/src/fparser/two/tests/fortran2008/test_intrinsics_2008.py index 68ab54eec..10d9e195e 100644 --- a/src/fparser/two/tests/fortran2008/test_intrinsics_2008.py +++ b/src/fparser/two/tests/fortran2008/test_intrinsics_2008.py @@ -51,8 +51,7 @@ def test_intrinsic_in_submodule(): assume that is bringing the shadowed symbol into scope). """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar contains @@ -61,7 +60,6 @@ def test_intrinsic_in_submodule(): a = dot_product(1,2,3) end subroutine my_sub end - """ - ) + """) ast = Fortran2008.Submodule(reader) assert not walk(ast, Fortran2003.Intrinsic_Function_Reference) diff --git a/src/fparser/two/tests/fortran2008/test_label_do_stmt_r816.py b/src/fparser/two/tests/fortran2008/test_label_do_stmt_r816.py index 14d377330..c19a686a7 100644 --- a/src/fparser/two/tests/fortran2008/test_label_do_stmt_r816.py +++ b/src/fparser/two/tests/fortran2008/test_label_do_stmt_r816.py @@ -40,6 +40,7 @@ use the F2008 version of loop-control """ + import pytest from fparser.api import get_reader diff --git a/src/fparser/two/tests/fortran2008/test_loop_control_r818.py b/src/fparser/two/tests/fortran2008/test_loop_control_r818.py index 81cc3026e..3c61dc5d5 100644 --- a/src/fparser/two/tests/fortran2008/test_loop_control_r818.py +++ b/src/fparser/two/tests/fortran2008/test_loop_control_r818.py @@ -42,6 +42,7 @@ Extends the Fortran2003 rule R830 with the additional CONCURRENT clause. """ + import pytest from fparser.two.Fortran2008 import Loop_Control from fparser.two.utils import NoMatchError diff --git a/src/fparser/two/tests/fortran2008/test_nonlabel_do_stmt_r817.py b/src/fparser/two/tests/fortran2008/test_nonlabel_do_stmt_r817.py index 34da69de7..1a107355b 100644 --- a/src/fparser/two/tests/fortran2008/test_nonlabel_do_stmt_r817.py +++ b/src/fparser/two/tests/fortran2008/test_nonlabel_do_stmt_r817.py @@ -40,6 +40,7 @@ use the F2008 version of loop-control """ + import pytest from fparser.api import get_reader diff --git a/src/fparser/two/tests/fortran2008/test_open_stmt_r904.py b/src/fparser/two/tests/fortran2008/test_open_stmt_r904.py index da682f0ca..47186fed9 100644 --- a/src/fparser/two/tests/fortran2008/test_open_stmt_r904.py +++ b/src/fparser/two/tests/fortran2008/test_open_stmt_r904.py @@ -102,17 +102,13 @@ def test_open_f2003_args(open_args): def test_open_newunit(f2008_parser): """Test that NEWUNIT is a valid argument to OPEN.""" - tree = f2008_parser( - get_reader( - """\ + tree = f2008_parser(get_reader("""\ subroutine myopen( unit, file ) integer, intent(out):: unit character(len=*), intent(in):: file open( newunit=unit, file=file ) endsubroutine myopen - """ - ) - ) + """)) open_stmts = walk(tree, Fortran2008.Open_Stmt) assert open_stmts assert len(open_stmts[0].children) == 2 diff --git a/src/fparser/two/tests/fortran2008/test_parent_identifier_r1118.py b/src/fparser/two/tests/fortran2008/test_parent_identifier_r1118.py index 381e567d3..52f096b78 100644 --- a/src/fparser/two/tests/fortran2008/test_parent_identifier_r1118.py +++ b/src/fparser/two/tests/fortran2008/test_parent_identifier_r1118.py @@ -44,6 +44,7 @@ in different files. """ + import pytest from fparser.two.utils import NoMatchError from fparser.two.Fortran2008 import Parent_Identifier diff --git a/src/fparser/two/tests/fortran2008/test_program_unit_r202.py b/src/fparser/two/tests/fortran2008/test_program_unit_r202.py index 1dbd82331..310522cce 100644 --- a/src/fparser/two/tests/fortran2008/test_program_unit_r202.py +++ b/src/fparser/two/tests/fortran2008/test_program_unit_r202.py @@ -49,36 +49,30 @@ def test_other(f2008_create): program-unit options. """ - reader = get_reader( - """\ + reader = get_reader("""\ subroutine test() end subroutine - """ - ) + """) ast = Program_Unit(reader) assert "SUBROUTINE test\n" "END SUBROUTINE" in str(ast) def test_submodule(f2008_create): """Test that submodule as a top-level program unit can be parsed.""" - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar end - """ - ) + """) ast = Program_Unit(reader) assert "SUBMODULE (foobar) bar\n" "END" in str(ast) def test_submodule_nomatch(f2008_create): """Test an exception is raised if there is a syntax error.""" - reader = get_reader( - """\ + reader = get_reader("""\ submod (foobar) bar end - """ - ) + """) with pytest.raises(NoMatchError) as excinfo: dummy_ = Program_Unit(reader) assert "at line 1\n>>> submod (foobar) bar\n" in str(excinfo.value) diff --git a/src/fparser/two/tests/fortran2008/test_submodule_r1116.py b/src/fparser/two/tests/fortran2008/test_submodule_r1116.py index a70848408..bca693a02 100644 --- a/src/fparser/two/tests/fortran2008/test_submodule_r1116.py +++ b/src/fparser/two/tests/fortran2008/test_submodule_r1116.py @@ -56,12 +56,10 @@ def test_submodule(f2008_create): """Test the parsing of a minimal submodule.""" - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar end - """ - ) + """) ast = Submodule(reader) assert "SUBMODULE (foobar) bar\n" "END" in str(ast) # A new symbol table should have been created @@ -74,13 +72,11 @@ def test_submodule_sp(f2008_create): part. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar use empty end - """ - ) + """) ast = Submodule(reader) assert "SUBMODULE (foobar) bar\n" " USE empty\n" "END" in str(ast) @@ -90,15 +86,13 @@ def test_submodule_msp(f2008_create): part. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar contains subroutine info() end subroutine info end - """ - ) + """) ast = Submodule(reader) assert ( "SUBMODULE (foobar) bar\n" @@ -118,16 +112,14 @@ def test_submodule_both(f2008_create): and a module subprogram part. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar use empty contains subroutine info() end subroutine info end - """ - ) + """) ast = Submodule(reader) assert ( "SUBMODULE (foobar) bar\n" @@ -148,13 +140,11 @@ def test_submodule_format_error1(f2008_create): implicit part of the specification. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar 1 format(a) end - """ - ) + """) with pytest.raises(NoMatchError) as excinfo: dummy_ = Submodule(reader) assert "at line 2\n" ">>> 1 format(a)\n" in str(excinfo.value) @@ -166,14 +156,12 @@ def test_submodule_format_error2(f2008_create): declaration part of the specification. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar contains 1 format(a) end - """ - ) + """) with pytest.raises(NoMatchError) as excinfo: dummy_ = Submodule(reader) assert "at line 3\n" ">>> 1 format(a)\n" in str(excinfo.value) @@ -188,13 +176,11 @@ def test_submodule_entry_error1(f2008_create): implicit part of the specification. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar entry here end - """ - ) + """) with pytest.raises(NoMatchError) as excinfo: dummy_ = Submodule(reader) assert "at line 2\n" ">>> entry here\n" in str(excinfo.value) @@ -206,14 +192,12 @@ def test_submodule_entry_error2(f2008_create): declaration part of the specification. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar contains entry here end - """ - ) + """) with pytest.raises(NoMatchError) as excinfo: dummy_ = Submodule(reader) assert "at line 3\n" ">>> entry here\n" in str(excinfo.value) @@ -228,14 +212,12 @@ def test_submodule_stmt_func_error(f2008_create): validly occur is in the declaration part of the specification. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar contains statefunc(x) = x*2 end - """ - ) + """) with pytest.raises(NoMatchError) as excinfo: dummy_ = Submodule(reader) assert "at line 3\n" ">>> statefunc(x) = x*2\n" in str(excinfo.value) @@ -249,12 +231,10 @@ def test_submodule_samename(f2008_create): end statements: C1114. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar end submodule bar - """ - ) + """) ast = Submodule(reader) assert "SUBMODULE (foobar) bar\n" "END SUBMODULE bar" in str(ast) @@ -264,11 +244,9 @@ def test_submodule_differentname(f2008_create): different name to that of the submodule statement : C1114. """ - reader = get_reader( - """\ + reader = get_reader("""\ submodule (foobar) bar end submodule error - """ - ) + """) with pytest.raises(SystemExit): dummy_ = Submodule(reader) diff --git a/src/fparser/two/tests/fortran2008/test_submodule_stmt_r1117.py b/src/fparser/two/tests/fortran2008/test_submodule_stmt_r1117.py index d87bc40f9..ec0a0f287 100644 --- a/src/fparser/two/tests/fortran2008/test_submodule_stmt_r1117.py +++ b/src/fparser/two/tests/fortran2008/test_submodule_stmt_r1117.py @@ -37,6 +37,7 @@ submodule-stmt is SUBMODULE ( parent-identifier ) submodule-name """ + import pytest from fparser.common import splitline from fparser.two.utils import NoMatchError diff --git a/src/fparser/two/tests/fortran2008/test_type_declaration_stmt_r501.py b/src/fparser/two/tests/fortran2008/test_type_declaration_stmt_r501.py index c0c6d2cf1..a12385c19 100644 --- a/src/fparser/two/tests/fortran2008/test_type_declaration_stmt_r501.py +++ b/src/fparser/two/tests/fortran2008/test_type_declaration_stmt_r501.py @@ -100,9 +100,7 @@ def test_type_declaration_stmt(): # R501 def test_shadowed_intrinsic(f2008_parser): """Check that a locally-defined symbol that shadows (overwrites) a Fortran intrinsic is correctly identified.""" - tree = f2008_parser( - get_reader( - """\ + tree = f2008_parser(get_reader("""\ module my_mod use some_mod real :: dot_product(2,2) @@ -112,9 +110,7 @@ def test_shadowed_intrinsic(f2008_parser): result = dot_product(1,1) end subroutine my_sub end module my_mod - """ - ) - ) + """)) tables = SYMBOL_TABLES # We should not have an intrinsic-function reference in the parse tree assert not walk(tree, Intrinsic_Function_Reference) diff --git a/src/fparser/two/tests/test_c99preprocessor.py b/src/fparser/two/tests/test_c99preprocessor.py index b43c6946c..921796a68 100644 --- a/src/fparser/two/tests/test_c99preprocessor.py +++ b/src/fparser/two/tests/test_c99preprocessor.py @@ -40,6 +40,7 @@ keep the directives in the Fortran parse tree and output it again. """ + # Author: Balthasar Reuter # Based on previous work by Martin Schlipf (https://github.com/martin-schlipf) # First version created: Jan 2020 diff --git a/src/fparser/two/tests/test_comments_and_directives.py b/src/fparser/two/tests/test_comments_and_directives.py index 4293bf625..b7914decb 100644 --- a/src/fparser/two/tests/test_comments_and_directives.py +++ b/src/fparser/two/tests/test_comments_and_directives.py @@ -63,16 +63,12 @@ def test_ignore_comments(): assert "block gets executed" not in gen # Check that the default behaviour is to ignore comments - tree = Program( - get_reader( - """\ + tree = Program(get_reader("""\ PROGRAM a_prog ! A full line comment PRINT *, "Hello" ! This block gets executed END PROGRAM a_prog - """ - ) - ) + """)) gen = str(tree) assert "full line comment" not in gen assert "block gets executed" not in gen @@ -513,12 +509,9 @@ def test_all_directive_formats(directive, expected, free): integer :: x """ source = source + directive + "\n" - source = ( - source - + """ do x= 1 , 100 + source = source + """ do x= 1 , 100 end do End Program""" - ) else: source = """\ program foo @@ -578,12 +571,9 @@ def test_directives_as_comments(directive, expected, free): integer :: x """ source = source + directive + "\n" - source = ( - source - + """ do x= 1 , 100 + source = source + """ do x= 1 , 100 end do End Program""" - ) else: source = """\ program foo diff --git a/src/fparser/two/tests/test_fortran2003.py b/src/fparser/two/tests/test_fortran2003.py index 948a72e01..9c8e27e64 100644 --- a/src/fparser/two/tests/test_fortran2003.py +++ b/src/fparser/two/tests/test_fortran2003.py @@ -109,10 +109,8 @@ def assert_raises(exc, fcls, string): def test_specification_part(): """Tests for parsing specification-part (R204).""" - reader = get_reader( - """\ - integer a""" - ) + reader = get_reader("""\ + integer a""") tcls = Specification_Part obj = tcls(reader) assert isinstance(obj, tcls), repr(obj) @@ -130,16 +128,12 @@ def test_specification_part(): assert obj.content[0].items[2].parent is obj.content[0] assert obj.content[0].items[2].items[0].parent is obj.content[0].items[2] - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ type a end type a type b end type b -""" - ) - ) +""")) assert isinstance(obj, tcls), repr(obj) assert "TYPE :: a\nEND TYPE a\nTYPE :: b\nEND TYPE b" in str(obj) @@ -709,13 +703,9 @@ def test_private_components_stmt(): def test_type_bound_procedure_part(): """Tests for type-bound procedure (R448).""" tcls = Type_Bound_Procedure_Part - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ contains -procedure, pass :: length => point_length""" - ) - ) +procedure, pass :: length => point_length""")) assert isinstance(obj, tcls), repr(obj) assert "CONTAINS\nPROCEDURE, PASS :: length => point_length" in str(obj) @@ -855,16 +845,12 @@ def test_component_spec_list(): # R458-list def test_enum_def(): # R460 tcls = Enum_Def - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ enum, bind(c) enumerator :: red = 4, blue = 9 enumerator yellow end enum - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "ENUM, BIND(C)\n ENUMERATOR :: red = 4, blue = 9\n" @@ -1931,9 +1917,7 @@ def test_pointer_assignment_stmt(): # R735 EVERY_OTHER => VECTOR(1 : N : 2) WINDOW2(0 :, 0 :) => MAT2D(ML : MU, NL : NU) P => BESSEL -STRUCT % COMPONENT => BESSEL""".split( - "\n" - ): +STRUCT % COMPONENT => BESSEL""".split("\n"): obj = tcls(stmt) assert isinstance(obj, tcls), repr(obj) assert str(obj) == stmt @@ -1969,16 +1953,12 @@ def test_where_construct_stmt(): # R745 @pytest.mark.usefixtures("fake_symbol_table") def test_forall_construct(): # R752 tcls = Forall_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ forall (i = 1:10, j = 1:10, b(i, j) /= 0.0) a(i, j) = real (i + j - 2) b(i, j) = a(i, j) + b(i, j) * real (i * j) end forall - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "FORALL(i = 1 : 10, j = 1 : 10, b(i, j) /= 0.0)\n" @@ -1986,15 +1966,11 @@ def test_forall_construct(): # R752 "b(i, j) * REAL(i * j)\nEND FORALL" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ n: forall (x = 1:5:2, j = 1:4) a(x, j) = j end forall n - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "n:FORALL(x = 1 : 5 : 2, j = 1 : 4)\n a(x, j) = j\nEND FORALL n" @@ -2019,9 +1995,7 @@ def test_if_nonblock_do(): """Tests that conditional nonblock DO construct is parsed correctly.""" tcls = If_Construct - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (expr) then do 20 i = 1, 3 a = 1 @@ -2031,9 +2005,7 @@ def test_if_nonblock_do(): a = 3 20 rotm(i,j) = r2(j,i) endif -""" - ) - ) +""")) assert isinstance(obj, tcls), repr(obj) assert len(obj.content) == 3, repr(obj) obj = obj.content[1] @@ -2043,15 +2015,11 @@ def test_if_nonblock_do(): "DO 20 k = 1, 3\n a = 3\n20 rotm(i, j) = r2(j, i)" ) - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ if (expr) then do 50 i = n, m, -1 50 call foo(a) -endif""" - ) - ) +endif""")) assert isinstance(obj, tcls), repr(obj) assert len(obj.content) == 3, repr(obj) obj = obj.content[1] @@ -2681,39 +2649,27 @@ def test_main_program0(): case matches with the Main_Program0 class. """ - obj0 = Fortran2003.Main_Program0( - get_reader( - """\ + obj0 = Fortran2003.Main_Program0(get_reader("""\ end - """ - ) - ) + """)) assert isinstance(obj0, Fortran2003.Main_Program0), repr(obj0) assert str(obj0) == "END" - obj0 = Fortran2003.Main_Program0( - get_reader( - """\ + obj0 = Fortran2003.Main_Program0(get_reader("""\ contains function foo() end end - """ - ) - ) + """)) assert isinstance(obj0, Fortran2003.Main_Program0), repr(obj0) assert str(obj0) == "CONTAINS\nFUNCTION foo()\nEND\nEND" # Check that the expected symbol table is created and populated - obj0 = Fortran2003.Main_Program0( - get_reader( - """\ + obj0 = Fortran2003.Main_Program0(get_reader("""\ integer :: i i = 9 end - """ - ) - ) + """)) assert isinstance(obj0, Fortran2003.Main_Program0), repr(obj0) assert str(obj0) == "INTEGER :: i\n i = 9\nEND" table = SYMBOL_TABLES.lookup("fparser2:main_program") @@ -2731,29 +2687,21 @@ def test_invalid_main_program0(): def test_module(): # R1104 tcls = Module - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ module m end - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "MODULE m\nEND" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ module m type a end type type b end type b end - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "MODULE m\n TYPE :: a\n END TYPE\n TYPE :: b\n END TYPE b" @@ -2802,27 +2750,19 @@ def test_module_nature(): @pytest.mark.xfail(reason="Match fails with multiple spaces, see issue #197") def test_block_data(): # R1116 tcls = Block_Data - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ block data a real b end block data - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "BLOCK DATA a\n REAL :: b\nEND BLOCK DATA" tcls = Block_Data - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ block data a end block data a - """ - ) - ) + """)) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "BLOCK DATA a\nEND BLOCK DATA a" @@ -2834,26 +2774,18 @@ def test_block_data(): # R1116 def test_interface_block(): # R1201 tcls = Interface_Block - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ interface -end interface""" - ) - ) +end interface""")) assert isinstance(obj, tcls), repr(obj) assert str(obj) == "INTERFACE\nEND INTERFACE" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ abstract interface procedure a module procedure b,c end interface -""" - ) - ) +""")) assert isinstance(obj, tcls), repr(obj) assert ( str(obj) == "ABSTRACT INTERFACE\n MODULE PROCEDURE a\n MODULE PROCEDURE b, " @@ -2863,14 +2795,10 @@ def test_interface_block(): # R1201 def test_interface_specification(): # R1202 tcls = Interface_Specification - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ function foo() end - """ - ) - ) + """)) assert isinstance(obj, Function_Body), repr(obj) assert str(obj) == "FUNCTION foo()\nEND" @@ -2907,26 +2835,18 @@ def test_end_interface_stmt(): # R1204 def test_interface_body(): # R1205 tcls = Interface_Body - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ subroutine foo end subroutine foo -""" - ) - ) +""")) assert isinstance(obj, Subroutine_Body), repr(obj) assert str(obj) == "SUBROUTINE foo\nEND SUBROUTINE foo" - obj = tcls( - get_reader( - """\ + obj = tcls(get_reader("""\ function foo(a) result(c) real a, c end -""" - ) - ) +""")) assert isinstance(obj, Function_Body), repr(obj) assert str(obj) == "FUNCTION foo(a) RESULT(c)\n REAL :: a, c\nEND" @@ -3156,11 +3076,9 @@ def test_alt_return_spec(): # R1222 def test_function_subprogram(): # R1223 - reader = get_reader( - """\ + reader = get_reader("""\ function foo() - end function foo""" - ) + end function foo""") tcls = Function_Subprogram obj = tcls(reader) assert isinstance(obj, tcls), repr(obj) @@ -3170,12 +3088,10 @@ def test_function_subprogram(): # R1223 " End_Function_Stmt('FUNCTION', Name('foo')))" ) - reader = get_reader( - """\ + reader = get_reader("""\ pure real function foo(a) result(b) bind(c) integer a - end function foo""" - ) + end function foo""") tcls = Function_Subprogram obj = tcls(reader) assert isinstance(obj, tcls), repr(obj) @@ -3314,11 +3230,9 @@ def test_end_function_stmt(): # R1230 def test_subroutine_subprogram(): # R1231 - reader = get_reader( - """\ + reader = get_reader("""\ subroutine foo - end subroutine foo""" - ) + end subroutine foo""") tcls = Subroutine_Subprogram obj = tcls(reader) assert isinstance(obj, tcls), repr(obj) @@ -3329,12 +3243,10 @@ def test_subroutine_subprogram(): # R1231 "Name('foo')))" ) - reader = get_reader( - """\ + reader = get_reader("""\ subroutine foo integer a - end subroutine foo""" - ) + end subroutine foo""") tcls = Subroutine_Subprogram obj = tcls(reader) assert isinstance(obj, tcls), repr(obj) diff --git a/src/fparser/two/tests/test_symbol_table.py b/src/fparser/two/tests/test_symbol_table.py index 2432543ff..6c924e31b 100644 --- a/src/fparser/two/tests/test_symbol_table.py +++ b/src/fparser/two/tests/test_symbol_table.py @@ -221,15 +221,11 @@ def test_root_property(): def test_module_use(f2003_parser): """Check that a USE of a module is captured in the symbol table.""" - _ = f2003_parser( - get_reader( - """\ + _ = f2003_parser(get_reader("""\ PROGRAM a_prog use some_mod END PROGRAM a_prog - """ - ) - ) + """)) tables = SYMBOL_TABLES table = tables.lookup("a_prog") assert isinstance(table, SymbolTable) @@ -240,16 +236,12 @@ def test_module_use(f2003_parser): def test_module_use_with_only(f2003_parser): """Check that USE statements with an ONLY: clause are correctly captured in the symbol table.""" - _ = f2003_parser( - get_reader( - """\ + _ = f2003_parser(get_reader("""\ PROGRAM a_prog use some_mod, only: use mod2, only: this_one, that_one END PROGRAM a_prog - """ - ) - ) + """)) tables = SYMBOL_TABLES table = tables.lookup("a_prog") assert isinstance(table, SymbolTable) @@ -269,18 +261,14 @@ def test_module_use_with_only(f2003_parser): def test_module_use_with_rename(f2003_parser): """Check that USE statements with renamed imported symbols are correctly captured in the symbol table and do not clash.""" - _ = f2003_parser( - get_reader( - """\ + _ = f2003_parser(get_reader("""\ PROGRAM a_prog use mod2, only: this_one => that_one use mod3, local => other integer :: that_one logical :: other END PROGRAM a_prog - """ - ) - ) + """)) tables = SYMBOL_TABLES table = tables.lookup("a_prog") assert isinstance(table, SymbolTable) @@ -299,9 +287,7 @@ def test_module_use_with_rename(f2003_parser): def test_wildcard_module_search(f2003_parser): """Test the wildcard_imports method of the SymbolTable.""" - _ = f2003_parser( - get_reader( - """\ + _ = f2003_parser(get_reader("""\ module my_mod use other_mod, only: b use medium_mod @@ -314,9 +300,7 @@ def test_wildcard_module_search(f2003_parser): use pointless_mod, only: end subroutine sub end module my_mod - """ - ) - ) + """)) # Module symbol table should have two modules listed with wildcard imports. mod_table = SYMBOL_TABLES.lookup("my_mod") assert mod_table.wildcard_imports == ["medium_mod", "some_mod"] @@ -324,9 +308,7 @@ def test_wildcard_module_search(f2003_parser): sub_table = mod_table.children[0] assert sub_table.wildcard_imports == ["big_mod", "medium_mod", "some_mod"] # Repeat for a program containing a subroutine containing a function. - _ = f2003_parser( - get_reader( - """\ + _ = f2003_parser(get_reader("""\ program my_prog use pointless_mod, only: dee use medium_mod @@ -348,9 +330,7 @@ def test_wildcard_module_search(f2003_parser): end function my_fn end subroutine sub end program my_prog - """ - ) - ) + """)) prog_table = SYMBOL_TABLES.lookup("my_prog") assert prog_table.wildcard_imports == ["medium_mod", "no_really_mod"] sub_table = prog_table.children[0] @@ -367,16 +347,12 @@ def test_wildcard_module_search(f2003_parser): def test_module_definition(f2003_parser): """Check that a SymbolTable is created for a module and populated with the symbols it defines.""" - _ = f2003_parser( - get_reader( - """\ + _ = f2003_parser(get_reader("""\ module my_mod use some_mod real :: a end module my_mod - """ - ) - ) + """)) tables = SYMBOL_TABLES assert list(tables._symbol_tables.keys()) == ["my_mod"] table = tables.lookup("my_mod") @@ -392,9 +368,7 @@ def test_module_definition(f2003_parser): def test_routine_in_module(f2003_parser): """Check that we get two, nested symbol tables when a module contains a subroutine.""" - _ = f2003_parser( - get_reader( - """\ + _ = f2003_parser(get_reader("""\ module my_mod use some_mod real :: a @@ -402,9 +376,7 @@ def test_routine_in_module(f2003_parser): subroutine my_sub() end subroutine my_sub end module my_mod - """ - ) - ) + """)) tables = SYMBOL_TABLES assert list(tables._symbol_tables.keys()) == ["my_mod"] table = tables.lookup("my_mod") @@ -421,9 +393,7 @@ def test_routine_in_module(f2003_parser): def test_routine_in_prog(f2003_parser): """Check that we get two, nested symbol tables when a program contains a subroutine.""" - _ = f2003_parser( - get_reader( - """\ + _ = f2003_parser(get_reader("""\ program my_prog use some_mod real :: a @@ -432,9 +402,7 @@ def test_routine_in_prog(f2003_parser): real :: b end subroutine my_sub end program my_prog - """ - ) - ) + """)) tables = SYMBOL_TABLES assert list(tables._symbol_tables.keys()) == ["my_prog"] table = SYMBOL_TABLES.lookup("my_prog") diff --git a/src/fparser/two/tests/test_utils.py b/src/fparser/two/tests/test_utils.py index fd05a0d26..8af10a207 100644 --- a/src/fparser/two/tests/test_utils.py +++ b/src/fparser/two/tests/test_utils.py @@ -41,7 +41,6 @@ from fparser.api import get_reader from fparser.two import Fortran2003, utils - # test BlockBase diff --git a/src/fparser/two/tests/utils/test_base.py b/src/fparser/two/tests/utils/test_base.py index 4f521dcaa..91b07c696 100644 --- a/src/fparser/two/tests/utils/test_base.py +++ b/src/fparser/two/tests/utils/test_base.py @@ -39,7 +39,6 @@ from fparser.two import Fortran2003 from fparser.two.utils import walk - TEST_CODE = ( "program hello\n" " implicit none\n" diff --git a/src/fparser/two/tests/utils/test_blockbase.py b/src/fparser/two/tests/utils/test_blockbase.py index 17e88e674..7dc8fecd1 100644 --- a/src/fparser/two/tests/utils/test_blockbase.py +++ b/src/fparser/two/tests/utils/test_blockbase.py @@ -105,17 +105,14 @@ def test_strict_order_invalid_code(f2003_create, strict_order): expected. """ subclasses = [F2003.Specification_Part, F2003.Execution_Part] - reader = get_reader( - """ + reader = get_reader(""" program main i = 2 integer :: i end program main - """ - ) + """) - expected = remove_indentation( - """([ + expected = remove_indentation("""([ Program_Stmt('PROGRAM', Name('main')), Execution_Part( Assignment_Stmt(Name('i'), '=', @@ -129,8 +126,7 @@ def test_strict_order_invalid_code(f2003_create, strict_order): (Entity_Decl(Name('i'), None, None, None),)))), End_Program_Stmt('PROGRAM', Name('main')) ],) - """ - ) + """) result = BlockBase.match( F2003.Program_Stmt, @@ -149,19 +145,16 @@ def test_strict_order_invalid_code(f2003_create, strict_order): def test_strict_order_valid_code(f2003_create): """Tests that the strict_order keyword allows repeated types.""" subclasses = [F2003.Specification_Part, F2003.Execution_Part] - reader = get_reader( - """ + reader = get_reader(""" program main integer :: i real :: rho i = 2 rho = i * 3.14 end program main - """ - ) + """) - expected = remove_indentation( - """([ + expected = remove_indentation("""([ Program_Stmt('PROGRAM', Name('main')), Specification_Part( Type_Declaration_Stmt( @@ -181,8 +174,7 @@ def test_strict_order_valid_code(f2003_create): Real_Literal_Constant('3.14', None)))), End_Program_Stmt('PROGRAM', Name('main')) ],) - """ - ) + """) result = BlockBase.match( F2003.Program_Stmt, subclasses, @@ -232,13 +224,11 @@ def test_label_do_nomatch(f2003_create): statement. """ subclasses = [F2003.Assignment_Stmt, F2003.Continue_Stmt] - reader = get_reader( - """ + reader = get_reader(""" do 100 i-10 j = 10 100 continue - """ - ) + """) result = BlockBase.match( F2003.Label_Do_Stmt, subclasses, @@ -282,8 +272,7 @@ def test_syntax_error_nested_symbol_table(): declaration to trigger a syntax error. """ - reader = get_reader( - """ + reader = get_reader(""" module my_mod contains FUNCTION dot_v_mod_2d( ) @@ -292,8 +281,7 @@ def test_syntax_error_nested_symbol_table(): dot_v_mod_2d = 0.0_wp END FUNCTION dot_v_mod_2d end module my_mod -""" - ) +""") result = F2003.Module.match(reader) # There should be no match and, as a result, there should be no # symbol-table entries. diff --git a/src/fparser/two/utils.py b/src/fparser/two/utils.py index 44e98e066..7a179d2e5 100644 --- a/src/fparser/two/utils.py +++ b/src/fparser/two/utils.py @@ -64,6 +64,7 @@ # DAMAGE. """Base classes and exception handling for Fortran parser.""" + # Original author: Pearu Peterson # First version created: Oct 2006