33from packaging .version import parse as parse_version
44import pytest
55
6+ from mp_api .client .core .exceptions import MPRestError
7+
68
79def test_emmet_core_version_checks (monkeypatch : pytest .MonkeyPatch ):
810 ref_ver = (1 , 2 , "3rc5" )
@@ -32,7 +34,7 @@ def test_id_validation():
3234
3335 max_num_idxs = MAPIClientSettings ().MAX_LIST_LENGTH
3436
35- with pytest .raises (ValueError , match = "too long" ):
37+ with pytest .raises (MPRestError , match = "too long" ):
3638 _ = validate_ids ([f"mp-{ x } " for x in range (max_num_idxs + 1 )])
3739
3840 # For all legacy MPIDs, ensure these validate correctly
@@ -60,10 +62,10 @@ def test_api_key_validation(monkeypatch: pytest.MonkeyPatch):
6062 }
6163 monkeypatch .setattr (pymatgen .core , "SETTINGS" , non_api_key_settings )
6264
63- with pytest .raises (ValueError , match = "32 characters" ):
65+ with pytest .raises (MPRestError , match = "32 characters" ):
6466 validate_api_key ("invalid_key" )
6567
66- with pytest .raises (ValueError , match = "Please obtain a valid" ):
68+ with pytest .raises (MPRestError , match = "Please obtain a valid" ):
6769 validate_api_key ()
6870
6971 junk_api_key = "a" * 32
@@ -80,5 +82,6 @@ def test_api_key_validation(monkeypatch: pytest.MonkeyPatch):
8082 # MP API environment variable takes precedence
8183 assert validate_api_key () == junk_api_key
8284
85+ # Check that pymatgen API key is used
8386 monkeypatch .setenv ("MP_API_KEY" , "" )
8487 assert validate_api_key () == other_junk_api_key
0 commit comments