Skip to content

Commit

Permalink
fix "DeprecationWarning: invalid escape sequence '\s'" (#286)
Browse files Browse the repository at this point in the history
* fix "DeprecationWarning: invalid escape sequence '\s'"

* updated/fixed gmxfatal message matching

- can now recognize newer gromacs messages
- added quick tests for the three fail modes of GromacsCommand

* update CHANGES
  • Loading branch information
orbeckst authored Jun 17, 2024
1 parent 708cbd1 commit 1d6aa0b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
CHANGELOG for GromacsWrapper
==============================

2024-??-?? 0.9.1

* fixed reporting of failures of GromacsCommand and DeprecationWarnings for use
of \s in regular expression strings (#285)


2024-06-15 0.9.0
orbeckst, jandom, njzjz

Expand Down
15 changes: 8 additions & 7 deletions gromacs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,14 @@ class GromacsCommand(Command):

command_name = None
driver = None
doc_pattern = """.*?(?P<DOCS>DESCRIPTION.*)"""
gmxfatal_pattern = """----+\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
doc_pattern = r""".*?(?P<DOCS>DESCRIPTION.*)"""
# 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
2 changes: 1 addition & 1 deletion gromacs/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ class Release(object):
"""

gromacs_version = re.compile(
"^G[rR][oO][mM][aA][cC][sS] version:" "\s*(VERSION)?\s*(?P<version>.+)$"
r"^G[rR][oO][mM][aA][cC][sS] version:" "\s*(VERSION)?\s*(?P<version>.+)$"
)

def __init__(self):
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 or rc == 255 # almost all GMX or GMX 4.6.5

def test_check_failure_none(self):
grompp = gromacs.tools.Grompp(failure=None)
assert grompp.failuremode == None
rc, stout, stderr = grompp()
assert rc == 1 or rc == 255 # almost all GMX or GMX 4.6.5

0 comments on commit 1d6aa0b

Please sign in to comment.