|
16 | 16 | from pymatgen.electronic_structure.dos import CompleteDos
|
17 | 17 | from pymatgen.entries.compatibility import MaterialsProject2020Compatibility
|
18 | 18 | from pymatgen.entries.computed_entries import ComputedEntry
|
19 |
| -from pymatgen.ext.matproj import MP_LOG_FILE, MPRestError, _MPResterBasic |
20 |
| -from pymatgen.ext.matproj_legacy import TaskType, _MPResterLegacy |
| 19 | +from pymatgen.ext.matproj import MP_LOG_FILE, _MPResterBasic |
| 20 | +from pymatgen.ext.matproj_legacy import MPRestError, TaskType, _MPResterLegacy |
21 | 21 | from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine
|
22 | 22 | from pymatgen.phonon.dos import CompletePhononDos
|
23 | 23 | from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
|
24 | 24 | from pytest import approx
|
25 | 25 | from ruamel.yaml import YAML
|
26 | 26 |
|
| 27 | +PMG_MAPI_KEY = SETTINGS.get("PMG_MAPI_KEY", "") |
| 28 | +if (10 < len(PMG_MAPI_KEY) <= 20) and "PMG_MAPI_KEY" in SETTINGS: |
| 29 | + MP_URL = "https://legacy.materialsproject.org" |
| 30 | +elif len(PMG_MAPI_KEY) > 20: |
| 31 | + MP_URL = "https://api.materialsproject.org" |
| 32 | +else: |
| 33 | + MP_URL = "https://materialsproject.org" |
27 | 34 | try:
|
28 |
| - skip_mprester_tests = requests.get("https://materialsproject.org", timeout=600).status_code != 200 |
| 35 | + skip_mprester_tests = requests.get(MP_URL, timeout=600).status_code != 200 |
29 | 36 |
|
30 | 37 | except (ModuleNotFoundError, ImportError, requests.exceptions.ConnectionError):
|
31 | 38 | # Skip all MPRester tests if some downstream problem on the website, mp-api or whatever.
|
32 | 39 | skip_mprester_tests = True
|
33 | 40 |
|
34 |
| -PMG_MAPI_KEY = SETTINGS.get("PMG_MAPI_KEY", "") |
35 |
| - |
36 | 41 |
|
37 | 42 | @pytest.mark.skipif(
|
38 | 43 | skip_mprester_tests or (not 10 < len(PMG_MAPI_KEY) <= 20),
|
@@ -513,8 +518,8 @@ def test_api_key_is_none(self):
|
513 | 518 | skip_mprester_tests or (not len(PMG_MAPI_KEY) > 20),
|
514 | 519 | reason="PMG_MAPI_KEY environment variable not set or MP API is down.",
|
515 | 520 | )
|
516 |
| -class TestMPResterNewBasic: |
517 |
| - def setup(self): |
| 521 | +class TestMPResterNewBasic(PymatgenTest): |
| 522 | + def setUp(self): |
518 | 523 | self.rester = _MPResterBasic()
|
519 | 524 |
|
520 | 525 | def test_get_summary(self):
|
@@ -679,11 +684,12 @@ def test_get_entry_by_material_id(self):
|
679 | 684 | # assert isinstance(bs_unif, BandStructure)
|
680 | 685 | # assert not isinstance(bs_unif, BandStructureSymmLine)
|
681 | 686 | #
|
682 |
| - # def test_get_phonon_data_by_material_id(self): |
683 |
| - # bs = self.rester.get_phonon_bandstructure_by_material_id("mp-661") |
684 |
| - # assert isinstance(bs, PhononBandStructureSymmLine) |
685 |
| - # dos = self.rester.get_phonon_dos_by_material_id("mp-661") |
686 |
| - # assert isinstance(dos, CompletePhononDos) |
| 687 | + def test_get_phonon_data_by_material_id(self): |
| 688 | + bs = self.rester.get_phonon_bandstructure_by_material_id("mp-661") |
| 689 | + assert isinstance(bs, PhononBandStructureSymmLine) |
| 690 | + dos = self.rester.get_phonon_dos_by_material_id("mp-661") |
| 691 | + assert isinstance(dos, CompletePhononDos) |
| 692 | + |
687 | 693 | # ddb_str = self.rester.get_phonon_ddb_by_material_id("mp-661")
|
688 | 694 | # assert isinstance(ddb_str, str)
|
689 | 695 |
|
|
0 commit comments