Skip to content

Commit

Permalink
update assert message again and format
Browse files Browse the repository at this point in the history
  • Loading branch information
jvavrek committed Sep 20, 2023
1 parent cd2c486 commit 3040d01
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions tests/materials_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from utils import xcom_is_up


def _get_warning_messages(record):
return [str(rec.message) for rec in record]


@pytest.mark.webtest
@pytest.mark.skipif(not xcom_is_up(), reason="XCOM is down.")
class TestConvertComposition:
Expand Down Expand Up @@ -68,13 +72,15 @@ def test_materials_force():
with pytest.warns(MaterialsWarning) as record:
fetch_materials(force=True)
if not os.path.exists(materials_compendium.FNAME):
assert (
len(record) == 2
), f"Expected two MaterialsWarnings to be raised; got {record}"
assert len(record) == 2, (
"Expected two MaterialsWarnings to be raised; "
f"got {_get_warning_messages(record)}"
)
else:
assert (
len(record) == 1
), f"Expected one MaterialsWarning to be raised; got {record}"
assert len(record) == 1, (
"Expected one MaterialsWarning to be raised; "
f"got {_get_warning_messages(record)}"
)
assert os.path.exists(materials.FILENAME)


Expand Down Expand Up @@ -134,7 +140,10 @@ def test_materials_dummy_compendium_pre2022():
json.dump(data, f, indent=4)
with pytest.warns(None) as record:
materials._load_and_compile_materials()
assert len(record) == 0, f"Expected no MaterialsWarnings to be raised; got {record}"
assert len(record) == 0, (
"Expected no MaterialsWarnings to be raised; "
f"got {_get_warning_messages(record)}"
)
# remove the dummy file and point back to original
os.remove(materials_compendium.FNAME)
materials_compendium.FNAME = fname_orig
Expand Down Expand Up @@ -183,7 +192,10 @@ def test_materials_dummy_compendium_2022():
json.dump(data, f, indent=4)
with pytest.warns(None) as record:
materials._load_and_compile_materials()
assert len(record) == 0, f"Expected no MaterialsWarnings to be raised; got {record}"
assert len(record) == 0, (
"Expected no MaterialsWarnings to be raised; "
f"got {_get_warning_messages(record)}"
)
# remove siteVersion and make sure there is an error raised
del data["siteVersion"]
with open(materials_compendium.FNAME, "w") as f:
Expand Down Expand Up @@ -226,7 +238,10 @@ def test_materials_no_compendium():
os.remove(materials_compendium.FNAME)
with pytest.warns(MaterialsWarning) as record:
materials_compendium.fetch_compendium_data()
assert len(record) == 1, f"Expected one MaterialsWarning to be raised; got {record}"
assert len(record) == 1, (
"Expected one MaterialsWarning to be raised; "
f"got {_get_warning_messages(record)}"
)
# point back to original file
materials_compendium.FNAME = fname_orig

Expand Down

0 comments on commit 3040d01

Please sign in to comment.