3838
3939from .conftest import requires_api_key
4040
41+ try :
42+ import mpcontribs .client as contribs_client
43+ except ImportError :
44+ contribs_client = None
45+
4146
4247@pytest .fixture ()
4348def mpr ():
@@ -210,22 +215,21 @@ def test_get_entries_in_chemsys(self, mpr):
210215 for e in gibbs_entries :
211216 assert isinstance (e , GibbsComputedStructureEntry )
212217
213- @pytest .mark .skip (reason = "SSL issues" )
218+ @pytest .mark .skipif (
219+ contribs_client is None ,
220+ reason = "`pip install mpcontribs-client` to use pourbaix functionality." ,
221+ )
214222 def test_get_pourbaix_entries (self , mpr ):
215- # test input chemsys as a list of elements
216- pbx_entries = mpr .get_pourbaix_entries (["Fe" , "Cr" ])
217- for pbx_entry in pbx_entries :
218- assert isinstance (pbx_entry , PourbaixEntry )
219-
220- # test input chemsys as a string
221- pbx_entries = mpr .get_pourbaix_entries ("Fe-Cr" )
222- for pbx_entry in pbx_entries :
223- assert isinstance (pbx_entry , PourbaixEntry )
224-
225- # test use_gibbs kwarg
226- pbx_entries = mpr .get_pourbaix_entries ("Li-O" , use_gibbs = 300 )
227- for pbx_entry in pbx_entries :
228- assert isinstance (pbx_entry , PourbaixEntry )
223+ # test input chemsys as a list of elements, chemsys, wiith and without kwargs
224+ for chemsys , kwargs in [
225+ [["Fe" , "Cr" ], {}],
226+ ["Fe-Cr" , {}],
227+ ["Li-O" , {"use_gibbs" : 300 }],
228+ ]:
229+ pbx_entries = mpr .get_pourbaix_entries (chemsys , ** kwargs )
230+ assert all (
231+ isinstance (pbx_entry , PourbaixEntry ) for pbx_entry in pbx_entries
232+ )
229233
230234 # test solid_compat kwarg
231235 with pytest .raises (ValueError , match = "Solid compatibility can only be" ):
@@ -237,7 +241,7 @@ def test_get_pourbaix_entries(self, mpr):
237241 assert not any (e for e in pbx_entries if "Na" in e .composition )
238242
239243 # Ensure entries are pourbaix compatible
240- PourbaixDiagram (pbx_entries )
244+ _ = PourbaixDiagram (pbx_entries )
241245
242246 # TODO - old tests copied from pymatgen with specific energy values. Update or delete
243247 # fe_two_plus = [e for e in pbx_entries if e.entry_id == "ion-0"][0]
@@ -251,7 +255,10 @@ def test_get_pourbaix_entries(self, mpr):
251255 # so4_two_minus = pbx_entries[9]
252256 # self.assertAlmostEqual(so4_two_minus.energy, 0.301511, places=3)
253257
254- @pytest .mark .skip (reason = "SSL issues" )
258+ @pytest .mark .skipif (
259+ contribs_client is None ,
260+ reason = "`pip install mpcontribs-client` to use pourbaix functionality." ,
261+ )
255262 def test_get_ion_entries (self , mpr ):
256263 entries = mpr .get_entries_in_chemsys ("Ti-O-H" )
257264 pd = PhaseDiagram (entries )
@@ -262,7 +269,7 @@ def test_get_ion_entries(self, mpr):
262269 bi_v_entry_data = mpr .get_ion_reference_data_for_chemsys ("Bi-V" )
263270 bi_data = mpr .get_ion_reference_data_for_chemsys ("Bi" )
264271 v_data = mpr .get_ion_reference_data_for_chemsys ("V" )
265- assert len (bi_v_entry_data ) == len (bi_data ) + v_data
272+ assert len (bi_v_entry_data ) == len (bi_data + v_data )
266273
267274 # test an incomplete phase diagram
268275 entries = mpr .get_entries_in_chemsys ("Ti-O" )
@@ -296,7 +303,9 @@ def test_get_ion_entries(self, mpr):
296303 # the ref solid is Na2SO4, ground state mp-4770
297304 # the rf factor correction is necessary to make sure the composition
298305 # of the reference solid is normalized to a single formula unit
299- ref_solid_entry = [e for e in ion_ref_entries if e .entry_id == "mp-4770" ][0 ]
306+ ref_solid_entry = next (
307+ e for e in ion_ref_entries if e .entry_id .startswith ("mp-4770" )
308+ )
300309 rf = ref_solid_entry .composition .get_reduced_composition_and_factor ()[1 ]
301310 solid_energy = ion_ref_pd .get_form_energy (ref_solid_entry ) / rf
302311
@@ -380,6 +389,8 @@ def test_get_default_api_key_endpoint(self, monkeypatch: pytest.MonkeyPatch):
380389 assert MPRester ().endpoint == self .default_endpoint
381390
382391 monkeypatch .delenv ("MP_API_KEY" , raising = False )
392+ monkeypatch .delenv ("PMG_MAPI_KEY" , raising = False )
393+ monkeypatch .setitem (SETTINGS , "PMG_MAPI_KEY" , None )
383394 with pytest .raises (MPRestError , match = "No API key found in request" ):
384395 MPRester ().get_structure_by_material_id ("mp-149" )
385396
@@ -405,6 +416,10 @@ def test_get_cohesive_energy_per_atom_utility(self):
405416 composition , toten_per_atom , atomic_energies
406417 ) == pytest .approx (by_hand_e_coh )
407418
419+ @pytest .mark .skipif (
420+ contribs_client is None ,
421+ reason = "`pip install mpcontribs-client` to use cohesive energy functionality." ,
422+ )
408423 def test_get_atom_references (self , mpr ):
409424 ae = mpr .get_atom_reference_data (funcs = ("PBE" ,))
410425 assert list (ae ) == ["PBE" ]
@@ -418,6 +433,10 @@ def test_get_atom_references(self, mpr):
418433 isinstance (v , float ) for entries in ae .values () for v in entries .values ()
419434 )
420435
436+ @pytest .mark .skipif (
437+ contribs_client is None ,
438+ reason = "`pip install mpcontribs-client` to use cohesive energy functionality." ,
439+ )
421440 def test_get_cohesive_energy (self ):
422441 ref_e_coh = {
423442 "atom" : {
0 commit comments