Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix "DeprecationWarning: invalid escape sequence '\s'" #286

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading