From 8d201d19a406d2e71c2f1dd441ec37d26aaceaff Mon Sep 17 00:00:00 2001 From: Matteo Giantomassi Date: Fri, 9 Aug 2024 19:06:22 +0200 Subject: [PATCH] Disable test for Structure.from_cod --- abipy/core/testing.py | 17 +++++++++++++++++ abipy/core/tests/test_structure.py | 8 +++++--- abipy/electrons/effmass_analyzer.py | 2 +- abipy/electrons/tests/test_ebands.py | 9 +++++---- abipy/ml/aseml.py | 2 ++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/abipy/core/testing.py b/abipy/core/testing.py index 56596fe4b..c0c41a95b 100644 --- a/abipy/core/testing.py +++ b/abipy/core/testing.py @@ -343,6 +343,23 @@ def test_mprester(): #raise unittest.SkipTest("MPRester tests have been disabled") return True + def is_url_reachable(url: str) -> bool: + """check if a URL is reachable:""" + import requests + try: + # Send a HEAD request to the URL + response = requests.head(url, timeout=5) + + # Check if the response status code is 200 (OK) + if response.status_code == 200: + return True + else: + return False + except requests.exceptions.RequestException as e: + # Handle any request exceptions (e.g., connection errors) + #print(f"Error: {e}") + return False + @staticmethod def has_matplotlib(version: Optional[str] = None, op: str = ">=") -> bool: return has_matplotlib(version=version, op=op) diff --git a/abipy/core/tests/test_structure.py b/abipy/core/tests/test_structure.py index e908e87bf..4a03934ef 100644 --- a/abipy/core/tests/test_structure.py +++ b/abipy/core/tests/test_structure.py @@ -222,9 +222,11 @@ def test_utils(self): d = llzo.abiget_spginfo(tolsym=0.001) assert d["spg_number"] == 142 - mgb2_cod = Structure.from_cod_id(1526507, primitive=True) - assert mgb2_cod.formula == "Mg1 B2" - assert mgb2_cod.spget_lattice_type() == "hexagonal" + # Temporarily disables ad webserver is down. + #if self.is_url_reachable("www.crystallography.net"): + # mgb2_cod = Structure.from_cod_id(1526507, primitive=True) + # assert mgb2_cod.formula == "Mg1 B2" + # assert mgb2_cod.spget_lattice_type() == "hexagonal" mgb2 = abidata.structure_from_ucell("MgB2") if self.has_ase(): diff --git a/abipy/electrons/effmass_analyzer.py b/abipy/electrons/effmass_analyzer.py index b3d2da678..f6810209d 100644 --- a/abipy/electrons/effmass_analyzer.py +++ b/abipy/electrons/effmass_analyzer.py @@ -294,7 +294,7 @@ def plot_all_segments(self, ax=None, colormap="viridis", fontsize=8, **kwargs) - pad += 10 #title = "k: %s, spin: %s, nband: %d" % (repr(self.efm_kpoint), self.spin, segment.nb) - set_grid_legend(ax, fontsize, ylabel='Energy (eV)', title=title) + set_grid_legend(ax, fontsize, ylabel='Energy (eV)') #, title=title) return fig diff --git a/abipy/electrons/tests/test_ebands.py b/abipy/electrons/tests/test_ebands.py index 1d347108e..5334f35ec 100644 --- a/abipy/electrons/tests/test_ebands.py +++ b/abipy/electrons/tests/test_ebands.py @@ -283,13 +283,14 @@ def test_silicon_ebands(self): with self.assertRaises(NotImplementedError): si_ebands_kmesh.get_edos(method="tetrahedron") - si_edos = si_ebands_kmesh.get_edos(step=0.1, width=0.2) + edos_kwargs = dict(step=0.1, width=0.2) + si_edos = si_ebands_kmesh.get_edos(**edos_kwargs) repr(si_edos); str(si_edos) assert ElectronDos.as_edos(si_edos, {}) is si_edos assert si_edos == si_edos and not (si_edos != si_edos) - edos_samevals = ElectronDos.as_edos(si_ebands_kmesh, {}) - assert ElectronDos.as_edos(si_ebands_kmesh, {}) == si_edos - assert ElectronDos.as_edos(abidata.ref_file("si_scf_GSR.nc"), {}) == si_edos + edos_samevals = ElectronDos.as_edos(si_ebands_kmesh, edos_kwargs) + assert ElectronDos.as_edos(si_ebands_kmesh, edos_kwargs=edos_kwargs) == si_edos + assert ElectronDos.as_edos(abidata.ref_file("si_scf_GSR.nc"), edos_kwargs=edos_kwargs) == si_edos with self.assertRaises(TypeError): ElectronDos.as_edos({}, {}) diff --git a/abipy/ml/aseml.py b/abipy/ml/aseml.py index 1e9ef9475..4d6ca2717 100644 --- a/abipy/ml/aseml.py +++ b/abipy/ml/aseml.py @@ -1482,7 +1482,9 @@ def __init__(self, name: str, dftd3_args=None, **kwargs): if ":" in name: self.nn_type, last = name.split(":") if last.endswith(".yaml") or last.endswith(".yml"): + print("Reading Calculator kwargs from file:", last) self.calc_kwargs = yaml_safe_load_path(last) + print("calc_kwargs:", self.calc_kwargs) else: self.model_name = last