forked from pearu/f2py
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #415 from stfc/165_namelist_error
Fix namelist r552 matching error (closes #165)
- Loading branch information
Showing
4 changed files
with
127 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/fparser/two/tests/fortran2003/test_namelist_stmt_r552.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright (c) 2023 Science and Technology Facilities Council. | ||
|
||
# All rights reserved. | ||
|
||
# Modifications made as part of the fparser project are distributed | ||
# under the following license: | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are | ||
# met: | ||
|
||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
|
||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
|
||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
"""Test Fortran 2003 rule R552 : This file tests the support for the | ||
NAMELIST statement. | ||
""" | ||
import pytest | ||
|
||
from fparser.two.Fortran2003 import Namelist_Stmt | ||
from fparser.two.utils import NoMatchError | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"code", | ||
[ | ||
"", | ||
"namelost", | ||
"namelist", | ||
"namelist x", | ||
"namelist x/", | ||
"namelist /x", | ||
"namelist /x/ y /", | ||
], | ||
) | ||
def test_match_errors(code): | ||
"""Test that the match method returns None when the supplied code is | ||
invalid. Also check that this results in a NoMatchError for an | ||
instance of the class. | ||
""" | ||
assert not Namelist_Stmt.match(code) | ||
with pytest.raises(NoMatchError): | ||
_ = Namelist_Stmt(code) | ||
|
||
|
||
def test_simple(): | ||
"""Test that a namelist with a single name and list is matched and | ||
that the tostr() method outputs the resultant code as | ||
expected. Also check that the namelist keyword matching is case | ||
insensitive and that leading and trailing spaces are supported. | ||
""" | ||
result = Namelist_Stmt(" NamelisT /x/ a ") | ||
assert isinstance(result, Namelist_Stmt) | ||
assert result.tostr() == "NAMELIST /x/ a" | ||
|
||
|
||
def test_multi(): | ||
"""Test that multiple names and lists are matched, with and without a | ||
comma separator and that the tostr() method outputs the resultant | ||
code as expected. | ||
""" | ||
result = Namelist_Stmt("namelist /x/ a, /y/ b,c /z/ d") | ||
assert isinstance(result, Namelist_Stmt) | ||
assert result.tostr() == "NAMELIST /x/ a, /y/ b, c, /z/ d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters