Skip to content

Commit

Permalink
Capture warnings in JSON tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tovrstra committed Jun 7, 2024
1 parent 4437bbf commit c7deb0f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions iodata/test/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ def test_ghost(tmpdir):
def test_qcschema_input(filename, explicit_basis, lot, obasis_name, run_type, geometry):
with as_file(files("iodata.test.data").joinpath(filename)) as qcschema_input:
try:
mol = load_one(str(qcschema_input))
with pytest.warns(FileFormatWarning):
mol = load_one(str(qcschema_input))
assert mol.lot == lot
if obasis_name:
assert mol.obasis_name == obasis_name
Expand All @@ -290,7 +291,10 @@ def test_qcschema_input(filename, explicit_basis, lot, obasis_name, run_type, ge
@pytest.mark.parametrize(("filename", "unparsed_dict", "location"), PASSTHROUGH_INPUT_FILES)
def test_passthrough_qcschema_input(filename, unparsed_dict, location):
"""Test qcschema_molecule parsing for passthrough of unparsed keys."""
with as_file(files("iodata.test.data").joinpath(filename)) as qcschema_input:
with (
as_file(files("iodata.test.data").joinpath(filename)) as qcschema_input,
pytest.warns(FileFormatWarning),
):
mol = load_one(str(qcschema_input))

assert mol.extra[location]["unparsed"] == unparsed_dict
Expand All @@ -311,7 +315,8 @@ def test_inout_qcschema_input(tmpdir, filename, nwarn):
"""Test that loading and dumping qcschema_molecule files retains all data."""
with as_file(files("iodata.test.data").joinpath(filename)) as qcschema_input:
if nwarn == 0:
mol = load_one(str(qcschema_input))
with pytest.warns(FileFormatWarning):
mol = load_one(str(qcschema_input))
else:
with pytest.warns(FileFormatWarning) as record:
mol = load_one(str(qcschema_input))
Expand Down Expand Up @@ -349,7 +354,8 @@ def test_inout_qcschema_input(tmpdir, filename, nwarn):
def test_qcschema_output(filename, lot, obasis_name, run_type, nwarn):
with as_file(files("iodata.test.data").joinpath(filename)) as qcschema_output:
if nwarn == 0:
mol = load_one(str(qcschema_output))
with pytest.warns(FileFormatWarning):
mol = load_one(str(qcschema_output))
else:
with pytest.warns(FileFormatWarning) as record:
mol = load_one(str(qcschema_output))
Expand Down Expand Up @@ -389,7 +395,8 @@ def test_bad_qcschema_files(filename, error):
def test_inout_qcschema_output(tmpdir, filename):
"""Test that loading and dumping qcschema_molecule files retains all data."""
with as_file(files("iodata.test.data").joinpath(filename)) as qcschema_input:
mol = load_one(str(qcschema_input))
with pytest.warns(FileFormatWarning):
mol = load_one(str(qcschema_input))
mol1 = json.loads(qcschema_input.read_bytes())

fn_tmp = os.path.join(tmpdir, "test_input_mol.json")
Expand Down

0 comments on commit c7deb0f

Please sign in to comment.