Skip to content

Commit

Permalink
updated/fixed gmxfatal message matching
Browse files Browse the repository at this point in the history
- can now recognize newer gromacs messages
- added quick tests for the three fail modes of GromacsCommand
  • Loading branch information
orbeckst committed Jun 16, 2024
1 parent e08659d commit 7936831
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
13 changes: 7 additions & 6 deletions gromacs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,13 @@ class GromacsCommand(Command):
command_name = None
driver = None
doc_pattern = r""".*?(?P<DOCS>DESCRIPTION.*)"""
gmxfatal_pattern = r"""----+\n # ---- decorator line
\s*Program\s+(?P<program_name>\w+), # Program name,
\s+VERSION\s+(?P<version>[\w.]+)\s*\n # VERSION 4.0.5
(?P<message>.*?)\n # full message, multiple lines
\s* # empty line (?)
----+\n # ---- decorator line
# gmxfatal_pattern is used with re.X | re.DOTALL so no need to match \n
gmxfatal_pattern = r"""----+\s* # ---- decorator line
\s*Program:?\s+(?P<program_name>[^,]+),\s* # Program[:] gmx grompp
\s+(VERSION|version)\s+(?P<version>[^\s]+)\s* # VERSION 4.0.5, version 2023.1-macports
(?P<message>.*?) # full message, multiple lines
\s* # empty line (?)
----+ # ---- decorator line
"""
# matches gmx_fatal() output
# -------------------------------------------------------
Expand Down
22 changes: 22 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,25 @@ def test_help_long(self, command, capsys):
captured = capsys.readouterr()
assert command.command_name in captured.out
assert gromacs.core.Command.__call__.__doc__ in captured.out


class TestGromacsCommand:
def test_check_failure_raise(self):
assert gromacs.grompp.failuremode == "raise"
with pytest.raises(gromacs.GromacsError,
match="Gromacs tool failed.*\nCommand invocation:.*grompp"):
gromacs.grompp()

def test_check_failure_warn(self):
grompp = gromacs.tools.Grompp(failure="warn")
assert grompp.failuremode == "warn"
with pytest.warns(gromacs.GromacsFailureWarning,
match="Error code"):
rc, stout, stderr = grompp()
assert rc == 1

def test_check_failure_none(self):
grompp = gromacs.tools.Grompp(failure=None)
assert grompp.failuremode == None
rc, stout, stderr = grompp()
assert rc == 1

0 comments on commit 7936831

Please sign in to comment.