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

Capture warnings in JSON tests #326

Merged
merged 1 commit into from
Jun 7, 2024
Merged
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
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):
tovrstra marked this conversation as resolved.
Show resolved Hide resolved
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