From fd0109b232c151cafd0b135d54afe5e8b2a3f07f Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Sat, 7 Oct 2023 11:39:05 -0700 Subject: [PATCH] test ValidationError on Atomate2Settings with invalid VASP_CMD and BANDGAP_TOL --- tests/common/test_settings.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/common/test_settings.py b/tests/common/test_settings.py index a80e195377..004adbdacc 100644 --- a/tests/common/test_settings.py +++ b/tests/common/test_settings.py @@ -1,4 +1,5 @@ import pytest +from pydantic import ValidationError def test_empty_and_invalid_config_file(clean_dir): @@ -24,3 +25,24 @@ def test_empty_and_invalid_config_file(clean_dir): with pytest.raises(SyntaxError, match="atomate2 config file at"): Atomate2Settings() + + # test error if the file exists and contains invalid settings + with open(config_file_path, "w") as file: + file.write("VASP_CMD: 42") + + with pytest.raises( + ValidationError, + match="1 validation error for Atomate2Settings\nVASP_CMD\n " + "Input should be a valid string ", + ): + Atomate2Settings() + + with open(config_file_path, "w") as file: + file.write("BANDGAP_TOL: invalid") + + with pytest.raises( + ValidationError, + match="1 validation error for Atomate2Settings\nBANDGAP_TOL\n " + "Input should be a valid number", + ): + Atomate2Settings()