Skip to content

Commit

Permalink
Fix molecules summary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed Jun 9, 2023
1 parent 3e514cf commit 9976131
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
10 changes: 3 additions & 7 deletions mp_api/client/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def validate_ids(id_list: List[str]):
Returns:
id_list: Returns original ID list if everything is formatted correctly.
"""
pattern = "(mp|mvc|mol)-.*"
pattern = "(mp|mvc|mol|mpcule)-.*"

for entry in id_list:
if re.match(pattern, entry) is None:
Expand All @@ -43,9 +43,7 @@ def api_sanitize(
fields_to_leave: list of strings for model fields as "model__name__.field"
"""
models = [
model
for model in get_flat_models_from_model(pydantic_model)
if issubclass(model, BaseModel)
model for model in get_flat_models_from_model(pydantic_model) if issubclass(model, BaseModel)
] # type: List[Type[BaseModel]]

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

if len(errors) > 0:
raise ValueError(
"Missing Monty seriailzation fields in dictionary: {errors}"
)
raise ValueError("Missing Monty seriailzation fields in dictionary: {errors}")

return v
else:
Expand Down
24 changes: 7 additions & 17 deletions tests/molecules/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,26 @@

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

excluded_params = [
"sort_fields",
"chunk_size",
"num_chunks",
"all_fields",
"fields",
"has_solvent",
"exclude_elements",
# Below: currently timing out
"nelements",
"has_props",
]
excluded_params = ["sort_fields", "chunk_size", "num_chunks", "all_fields", "fields", "exclude_elements"]

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

custom_field_tests = {
"molecule_ids": ["9f153b9f3caa3124fb404b42e4cf82c8-C2H4-0-1"],
"molecule_ids": ["351ef090ebd90b661a4e1205756f6957-C1Mg1N2O1S1-m2-1"],
"formula": "C2 H4",
"chemsys": "C-H",
"elements": ["C", "H"],
"elements": ["P"],
"has_solvent": "DIELECTRIC=18,500;N=1,415;ALPHA=0,000;BETA=0,735;GAMMA=20,200;PHI=0,000;PSI=0,000",
"has_level_of_theory": "wB97X-V/def2-TZVPPD/SMD",
"has_lot_solvent": "wB97X-V/def2-TZVPPD/SMD(SOLVENT=THF)",
"nelements": 2,
"charge": 1,
"spin_multiplicity": 1,
"has_props": [HasProps.orbitals],
} # type: dict


@pytest.mark.skipif(
os.environ.get("MP_API_KEY", None) is None, reason="No API key found."
)
@pytest.mark.skipif(os.environ.get("MP_API_KEY", None) is None, reason="No API key found.")
def test_client():
search_method = MoleculesSummaryRester().search

Expand All @@ -49,6 +38,7 @@ def test_client():
if param not in excluded_params:
param_type = entry[1].__args__[0]
q = None

print(param)

if param in custom_field_tests:
Expand Down

0 comments on commit 9976131

Please sign in to comment.