Skip to content

Commit

Permalink
add tests for parsing #error statements
Browse files Browse the repository at this point in the history
  • Loading branch information
fgrunewald committed Aug 6, 2023
1 parent 46ec6ed commit ed65822
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions polyply/tests/test_top_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,54 @@ def test_skip_directives(lines):
"gen-pairs":'no',
"fudgeLJ":1.0,
"fudgeQQ":1.0}
@staticmethod
@pytest.mark.parametrize('lines', (
"""
#define GMXERROR
#ifdef GMXERROR
#error "This will raise an error."
#endif
""",
"""
#error This will raise an error
""",
))
def test_error_parsing(lines):
"""
Test that the #error pragma raises an error.
"""
new_lines = textwrap.dedent(lines)
new_lines = new_lines.splitlines()
force_field = vermouth.forcefield.ForceField(name='test_ff')
top = Topology(force_field, name="test")
with pytest.raises(NotImplementedError):
polyply.src.top_parser.read_topology(new_lines, top)

@staticmethod
@pytest.mark.parametrize('lines', (
"""
#define NOERROR
#ifdef GMXERROR
#error "This will raise an error."
#endif
""",
"""
#define NOERROR
#ifndef NOERROR
#error This will raise an error.
#endif
""",
))
def test_error_skipped(lines):
"""
Test that the #error pragma is skipped when not defined.
"""
new_lines = textwrap.dedent(lines)
new_lines = new_lines.splitlines()
force_field = vermouth.forcefield.ForceField(name='test_ff')
top = Topology(force_field, name="test")
polyply.src.top_parser.read_topology(new_lines, top)
assert top.defines == {'NOERROR': True}

def test_consistency():
"""
Expand Down

0 comments on commit ed65822

Please sign in to comment.