Skip to content

Commit de162d5

Browse files
author
Jason
committed
2 parents d5fb390 + 9976131 commit de162d5

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

mp_api/client/core/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,14 @@ def new_getattr(self, attr) -> str:
803803
f"{self.__class__.__name__!r} object has no attribute {attr!r}"
804804
)
805805

806+
def new_dict(self, *args, **kwargs):
807+
d = super(data_model, self).dict(*args, **kwargs)
808+
return jsanitize(d)
809+
806810
data_model.__repr__ = new_repr
807811
data_model.__str__ = new_str
808812
data_model.__getattr__ = new_getattr
813+
data_model.dict = new_dict
809814

810815
return data_model, set_fields, unset_fields
811816

mp_api/client/core/utils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def validate_ids(id_list: List[str]):
1919
Returns:
2020
id_list: Returns original ID list if everything is formatted correctly.
2121
"""
22-
pattern = "(mp|mvc|mol)-.*"
22+
pattern = "(mp|mvc|mol|mpcule)-.*"
2323

2424
for entry in id_list:
2525
if re.match(pattern, entry) is None:
@@ -43,9 +43,7 @@ def api_sanitize(
4343
fields_to_leave: list of strings for model fields as "model__name__.field"
4444
"""
4545
models = [
46-
model
47-
for model in get_flat_models_from_model(pydantic_model)
48-
if issubclass(model, BaseModel)
46+
model for model in get_flat_models_from_model(pydantic_model) if issubclass(model, BaseModel)
4947
] # type: List[Type[BaseModel]]
5048

5149
fields_to_leave = fields_to_leave or []
@@ -94,9 +92,7 @@ def validate_monty(cls, v):
9492
errors.append("@class")
9593

9694
if len(errors) > 0:
97-
raise ValueError(
98-
"Missing Monty seriailzation fields in dictionary: {errors}"
99-
)
95+
raise ValueError("Missing Monty seriailzation fields in dictionary: {errors}")
10096

10197
return v
10298
else:

tests/molecules/test_summary.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,26 @@
66

77
from mp_api.client.routes.molecules.summary import MoleculesSummaryRester
88

9-
excluded_params = [
10-
"sort_fields",
11-
"chunk_size",
12-
"num_chunks",
13-
"all_fields",
14-
"fields",
15-
"has_solvent",
16-
"exclude_elements",
17-
# Below: currently timing out
18-
"nelements",
19-
"has_props",
20-
]
9+
excluded_params = ["sort_fields", "chunk_size", "num_chunks", "all_fields", "fields", "exclude_elements"]
2110

2211
alt_name = {"formula": "formula_alphabetical", "molecule_ids": "molecule_id"}
2312

2413
custom_field_tests = {
25-
"molecule_ids": ["9f153b9f3caa3124fb404b42e4cf82c8-C2H4-0-1"],
14+
"molecule_ids": ["351ef090ebd90b661a4e1205756f6957-C1Mg1N2O1S1-m2-1"],
2615
"formula": "C2 H4",
2716
"chemsys": "C-H",
28-
"elements": ["C", "H"],
17+
"elements": ["P"],
2918
"has_solvent": "DIELECTRIC=18,500;N=1,415;ALPHA=0,000;BETA=0,735;GAMMA=20,200;PHI=0,000;PSI=0,000",
3019
"has_level_of_theory": "wB97X-V/def2-TZVPPD/SMD",
3120
"has_lot_solvent": "wB97X-V/def2-TZVPPD/SMD(SOLVENT=THF)",
3221
"nelements": 2,
22+
"charge": 1,
23+
"spin_multiplicity": 1,
3324
"has_props": [HasProps.orbitals],
3425
} # type: dict
3526

3627

37-
@pytest.mark.skipif(
38-
os.environ.get("MP_API_KEY", None) is None, reason="No API key found."
39-
)
28+
@pytest.mark.skipif(os.environ.get("MP_API_KEY", None) is None, reason="No API key found.")
4029
def test_client():
4130
search_method = MoleculesSummaryRester().search
4231

@@ -49,6 +38,7 @@ def test_client():
4938
if param not in excluded_params:
5039
param_type = entry[1].__args__[0]
5140
q = None
41+
5242
print(param)
5343

5444
if param in custom_field_tests:

0 commit comments

Comments
 (0)