Skip to content

Commit

Permalink
Revert
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Feb 6, 2024
1 parent 3d06f5d commit 5a1b105
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
52 changes: 25 additions & 27 deletions openff/toolkit/_tests/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import copy
import itertools
import os
import re
from tempfile import NamedTemporaryFile

import numpy as np
Expand Down Expand Up @@ -900,33 +899,31 @@ def test_create_forcefield_from_file(self, force_field):
assert force_field.aromaticity_model == "OEAroModel_MDL"

def test_load_bad_string(self):
# This exception is a multi-line string, and `.*` by default doesn't
# consider newlines, so need to copmile with re.DOTALL flag
with pytest.raises(
IOError,
match=re.compile(
"Source '1234' could not be read.*"
"openforcefield.*"
"SMIRNOFFParseError.*"
"syntax error",
flags=re.DOTALL,
),
):
with pytest.raises(IOError) as exception_info:
ForceField("1234")

# This may need to be updated if the `openforcefields` package changes name;
# searching through `site-packages/` and other paths is probably unrelaiable
for match in [
"Source '1234' could not be read",
"SMIRNOFFParseError",
"syntax error",
"openforcefields",
]:
assert match in str(exception_info.value)

def test_load_bad_bytes(self):
with pytest.raises(
IOError,
match=re.compile(
"Source 'b'the holy grail.*"
"could not be read.*"
"SMIRNOFFParseError.*"
"syntax error.*",
flags=re.DOTALL,
),
) as exception_info:
with pytest.raises(IOError) as exception_info:
ForceField(b"the holy grail of computational chemistry")

for match in [
"Source 'b'the holy grail",
"could not be read",
"SMIRNOFFParseError",
"syntax error",
]:
assert match in str(exception_info.value)

# See note in test_load_bad_string
assert "openforcefields" not in str(exception_info.value)

Expand All @@ -936,12 +933,13 @@ def test_load_filelike_object(self):

def test_load_bad_filelike_object(self):
with open(get_data_file_path("test_forcefields/mangled.offxml")) as f:
with pytest.raises(
IOError,
match="while trying to parse source as an object",
):
with pytest.raises(IOError) as exception_info:
ForceField(f)

assert "while trying to parse source as an object" in str(
exception_info.value
)

def test_create_forcefield_from_xml_string(self):
forcefield = ForceField(xml_simple_ff)
assert len(forcefield._parameter_handlers["Bonds"]._parameters) == 3
Expand Down
9 changes: 3 additions & 6 deletions openff/toolkit/typing/engines/smirnoff/forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,9 @@ def parse_sources(self, sources, allow_cosmetic_attributes=True):
# TODO: If a non-first source fails here, the force field might be partially modified
for source in sources:
smirnoff_data = self.parse_smirnoff_from_source(source)
try:
self._load_smirnoff_data(
smirnoff_data, allow_cosmetic_attributes=allow_cosmetic_attributes
)
except Exception as error:
raise TypeError(f"{smirnoff_data=}\n{source=}\n{sources=}\n") from error
self._load_smirnoff_data(
smirnoff_data, allow_cosmetic_attributes=allow_cosmetic_attributes
)

def _to_smirnoff_data(self, discard_cosmetic_attributes=False) -> dict:
"""
Expand Down

0 comments on commit 5a1b105

Please sign in to comment.