From 42e13496566060c1b1dfbb8d4163e0e26319bd32 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Thu, 6 Feb 2025 19:01:03 +0000 Subject: [PATCH 01/18] Tests: Support sqlite aiida fixtures when available --- tests/conftest.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index edea9b80..3f50c98a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,9 +8,17 @@ import numpy as np import pytest +from aiida import __version__ as aiida_version from aiida import engine, orm, plugins - -pytest_plugins = ["aiida.manage.tests.pytest_fixtures"] +from packaging.version import Version + +# Load aiida's pytest fixtures +# For aiida-core>=2.6 we load new fixtures which use sqlite backend. +if Version(aiida_version) >= Version("2.6.0"): + aiida_core_fixtures = "aiida.tools.pytest_fixtures" +else: + aiida_core_fixtures = "aiida.manage.tests.pytest_fixtures" +pytest_plugins = [aiida_core_fixtures] @pytest.fixture From ed222667d29608080c5654c1f25a2c4ee36f0c8b Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Thu, 6 Feb 2025 19:22:38 +0000 Subject: [PATCH 02/18] Use aiida_code_installed fixture --- tests/conftest.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3f50c98a..16f6e00d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,10 +15,19 @@ # Load aiida's pytest fixtures # For aiida-core>=2.6 we load new fixtures which use sqlite backend. if Version(aiida_version) >= Version("2.6.0"): - aiida_core_fixtures = "aiida.tools.pytest_fixtures" + pytest_plugins = ["aiida.tools.pytest_fixtures"] + else: - aiida_core_fixtures = "aiida.manage.tests.pytest_fixtures" -pytest_plugins = [aiida_core_fixtures] + pytest_plugins = ["aiida.manage.tests.pytest_fixtures"] + + @pytest.fixture + def aiida_code_installed(aiida_local_code_factory): + def _code(filepath_executable, default_calc_job_plugin): + return aiida_local_code_factory( + executable=filepath_executable, entry_point=default_calc_job_plugin + ) + + return _code @pytest.fixture @@ -278,9 +287,11 @@ def folder_data_object(): @pytest.fixture -def aiida_local_code_bash(aiida_local_code_factory): - """Return a `Code` configured for the bash executable.""" - return aiida_local_code_factory(executable="bash", entry_point="bash") +def aiida_local_code_bash(aiida_code_installed): + """Return `InstalledCode` configured for bash executable.""" + return aiida_code_installed( + filepath_executable="/bin/bash", default_calc_job_plugin="bash" + ) @pytest.fixture From c61796acc4af67c5d5ba899c26297574907e1b16 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Thu, 6 Feb 2025 19:23:24 +0000 Subject: [PATCH 03/18] Add packaging to dev dependencies --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index cda371c0..86c002e6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,6 +42,7 @@ zip_safe = False [options.extras_require] dev = bumpver>=2023.1129 + packaging>=22.0 pgtest~=1.3 pre-commit>=3.5 pytest~=8.3.0 From 6785bc0d65cdb454e48a5775f134aa3e82efefe8 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Thu, 6 Feb 2025 19:27:00 +0000 Subject: [PATCH 04/18] Remove superfluous chdir --- tests/test_viewers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_viewers.py b/tests/test_viewers.py index adfb176f..dca76fe1 100644 --- a/tests/test_viewers.py +++ b/tests/test_viewers.py @@ -107,8 +107,6 @@ def test_structure_data_viewer_storage(monkeypatch, tmp_path, structure_data_obj -1.6859999895095825, -1.6859999895095825, -0.6669999957084656, 1, ] # fmt: on - # Avoid producing temporary files from povray in the repo - monkeypatch.chdir(tmp_path) v._render_structure() # Make sure we don't polute current working dir with tempfiles From e87b49542bbeac807b5c6d1221c959b58cccd783 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 13:40:04 +0100 Subject: [PATCH 05/18] Limit ipython version --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 29410aec..967cdbb3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = spglib>=1.14,<3 vapory~=0.1.2 pandas~=2.1 - ipython>=7.33 + ipython>=7.33,<9.0 python_requires = >=3.9 include_package_data = True zip_safe = False From 61f9bbe007eaf74e9adb368222004701560e188d Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 14:05:29 +0100 Subject: [PATCH 06/18] check_call --- aiidalab_widgets_base/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiidalab_widgets_base/export.py b/aiidalab_widgets_base/export.py index 753a15a0..363110b7 100644 --- a/aiidalab_widgets_base/export.py +++ b/aiidalab_widgets_base/export.py @@ -27,7 +27,7 @@ def export_aiida_subgraph(self, change=None): # pylint: disable=unused-argument from IPython.display import Javascript, display fname = os.path.join(tempfile.mkdtemp(), "export.aiida") - subprocess.call( + subprocess.check_call( ["verdi", "archive", "create", fname, "-N", str(self.process.pk)] ) with open(fname, "rb") as fobj: From 147efdffc946f34c508edf58d7ac3379e53371fd Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 14:23:42 +0100 Subject: [PATCH 07/18] check_output --- aiidalab_widgets_base/export.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aiidalab_widgets_base/export.py b/aiidalab_widgets_base/export.py index 363110b7..795bb48a 100644 --- a/aiidalab_widgets_base/export.py +++ b/aiidalab_widgets_base/export.py @@ -27,8 +27,9 @@ def export_aiida_subgraph(self, change=None): # pylint: disable=unused-argument from IPython.display import Javascript, display fname = os.path.join(tempfile.mkdtemp(), "export.aiida") - subprocess.check_call( - ["verdi", "archive", "create", fname, "-N", str(self.process.pk)] + subprocess.check_output( + ["verdi", "archive", "create", fname, "-N", str(self.process.pk)], + stderr=subprocess.STDOUT, ) with open(fname, "rb") as fobj: b64 = base64.b64encode(fobj.read()) From e83cf20f32ee94fb75efefeeb5a1436d2dc4dc91 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 14:36:20 +0100 Subject: [PATCH 08/18] Get command output --- .github/workflows/ci.yml | 2 +- aiidalab_widgets_base/export.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cfba6e2..be53ac26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -128,7 +128,7 @@ jobs: run: uv pip install --compile --system -e .[dev,smiles,optimade,eln] aiida-core==${{ matrix.aiida-core-version }} - name: Run pytest - run: pytest -v tests --cov=aiidalab_widgets_base + run: pytest -s tests --cov=aiidalab_widgets_base - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5 diff --git a/aiidalab_widgets_base/export.py b/aiidalab_widgets_base/export.py index 795bb48a..040519b8 100644 --- a/aiidalab_widgets_base/export.py +++ b/aiidalab_widgets_base/export.py @@ -27,10 +27,15 @@ def export_aiida_subgraph(self, change=None): # pylint: disable=unused-argument from IPython.display import Javascript, display fname = os.path.join(tempfile.mkdtemp(), "export.aiida") - subprocess.check_output( - ["verdi", "archive", "create", fname, "-N", str(self.process.pk)], - stderr=subprocess.STDOUT, - ) + try: + subprocess.check_output( + ["verdi", "archive", "create", fname, "-N", str(self.process.pk)], + stderr=subprocess.STDOUT, + ) + except subprocess.CalledProcessError as e: + print(e) + print(e.output) + raise with open(fname, "rb") as fobj: b64 = base64.b64encode(fobj.read()) payload = b64.decode() From 281b981bcf212188ca91e6bdd9c0ce3f01242b2f Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 15:00:42 +0100 Subject: [PATCH 09/18] Test with aiida 2.7.0rc0 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be53ac26..0f7c8514 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,7 +90,7 @@ jobs: matrix: python-version: ['3.9', '3.11'] # Test on the latest and oldest supported version - aiida-core-version: [2.2.2, 2.6.3] + aiida-core-version: [2.2.2, 2.7.0rc0] fail-fast: false runs-on: ubuntu-24.04 From 7c8c697cdec19736985df90dd0e61d3d6ef216eb Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 16:10:27 +0100 Subject: [PATCH 10/18] Fix pw_code fixture --- tests/conftest.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 16f6e00d..1848cb0e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -358,9 +358,11 @@ def get(self): @pytest.fixture -def pw_code(aiida_local_code_factory): +def pw_code(aiida_code_installed): """Return a `Code` configured for the pw.x executable.""" - return aiida_local_code_factory( - label="pw", executable="bash", entry_point="quantumespresso.pw" + return aiida_code_installed( + label="pw", + filepath_executable="/bin/bash", + default_calc_job_plugin="quantumespresso.pw", ) From 571f0061d562c0a7f66d0c57c03d72399176e265 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 16:13:09 +0100 Subject: [PATCH 11/18] Require 2.7.0rc0 for sqlite fixtures --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1848cb0e..d3786ae7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,8 +13,8 @@ from packaging.version import Version # Load aiida's pytest fixtures -# For aiida-core>=2.6 we load new fixtures which use sqlite backend. -if Version(aiida_version) >= Version("2.6.0"): +# For aiida-core>=2.7 we load new fixtures which use sqlite backend. +if Version(aiida_version) >= Version("2.7.0rc0"): pytest_plugins = ["aiida.tools.pytest_fixtures"] else: From 7cfd1ebc004b0fe3dbe8bc7e25bf1e75507a43b6 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 16:14:16 +0100 Subject: [PATCH 12/18] -v --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f7c8514..972d2077 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -128,7 +128,7 @@ jobs: run: uv pip install --compile --system -e .[dev,smiles,optimade,eln] aiida-core==${{ matrix.aiida-core-version }} - name: Run pytest - run: pytest -s tests --cov=aiidalab_widgets_base + run: pytest -v tests --cov=aiidalab_widgets_base - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5 From 2df6167c6a74db710c8fd903fbc323d05596c948 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 16:17:25 +0100 Subject: [PATCH 13/18] fix --- tests/conftest.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d3786ae7..cbdaa573 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,9 +22,11 @@ @pytest.fixture def aiida_code_installed(aiida_local_code_factory): - def _code(filepath_executable, default_calc_job_plugin): + def _code(filepath_executable, default_calc_job_plugin, label=None): return aiida_local_code_factory( - executable=filepath_executable, entry_point=default_calc_job_plugin + executable=filepath_executable, + entry_point=default_calc_job_plugin, + label=label, ) return _code From 2fcc0f47fc5a66a082548f11acb4f83ab5e431b8 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 16:17:29 +0100 Subject: [PATCH 14/18] Revert "Require 2.7.0rc0 for sqlite fixtures" This reverts commit 571f0061d562c0a7f66d0c57c03d72399176e265. --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index cbdaa573..a025c3f5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,8 +13,8 @@ from packaging.version import Version # Load aiida's pytest fixtures -# For aiida-core>=2.7 we load new fixtures which use sqlite backend. -if Version(aiida_version) >= Version("2.7.0rc0"): +# For aiida-core>=2.6 we load new fixtures which use sqlite backend. +if Version(aiida_version) >= Version("2.6.0"): pytest_plugins = ["aiida.tools.pytest_fixtures"] else: From 368aaaa2d249b00833003d19da4696406a081136 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 6 May 2025 17:21:30 +0100 Subject: [PATCH 15/18] Fix daemon_client fixtures --- tests/conftest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index a025c3f5..5d3724d3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,6 +17,27 @@ if Version(aiida_version) >= Version("2.6.0"): pytest_plugins = ["aiida.tools.pytest_fixtures"] + @pytest.fixture(scope="session") + def aiida_profile(aiida_config, aiida_profile_factory, config_sqlite_dos): + """Create and load a profile with ``core.psql_dos`` as a storage backend and RabbitMQ as the broker. + + This overrides the ``aiida_profile`` fixture provided by ``aiida-core`` which runs with ``core.sqlite_dos`` and + without broker. However, tests in this package make use of the daemon which requires a broker and the tests should + be run against the main storage backend, which is ``core.sqlite_dos``. + """ + broker = "core.rabbitmq" + + storage = "core.sqlite_dos" + config = config_sqlite_dos() + + with aiida_profile_factory( + aiida_config, + storage_backend=storage, + storage_config=config, + broker_backend=broker, + ) as profile: + yield profile + else: pytest_plugins = ["aiida.manage.tests.pytest_fixtures"] From b78fe2ef47c1dd12cae0f72cd5f8b7068dc14a70 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Thu, 5 Jun 2025 00:19:37 +0100 Subject: [PATCH 16/18] Run tests from aiida-core fork --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 972d2077..3fef23db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,7 +125,8 @@ jobs: # Ideally, these would be fixed, but vapory is largely unmaintained, # so here we simply keep the pip behaviour with the --compile flag. # See https://github.com/astral-sh/uv/issues/1928#issuecomment-1968857514 - run: uv pip install --compile --system -e .[dev,smiles,optimade,eln] aiida-core==${{ matrix.aiida-core-version }} + run: | + uv pip install --compile --system -e .[dev,smiles,optimade,eln] aiida-core@git+https://github.com/danielhollas/aiida-core@fix-legacy-fixtures-minimal - name: Run pytest run: pytest -v tests --cov=aiidalab_widgets_base From 240c4a56c420cce70d78b54c867fcd2082067b9e Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 24 Jun 2025 17:41:55 +0100 Subject: [PATCH 17/18] Unit tests with 2.7.0 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 950c5d7e..98e2ecbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,7 +89,7 @@ jobs: matrix: python-version: ['3.9', '3.11'] # Test on the latest and oldest supported version - aiida-core-version: [2.2.2, 2.7.0rc0] + aiida-core-version: [2.2.2, 2.7.0] fail-fast: false runs-on: ubuntu-24.04 From 9fe8ef57db8cf03b5072b719637c6d6992dc5bb0 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 24 Jun 2025 17:43:20 +0100 Subject: [PATCH 18/18] Revert hotpatch --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98e2ecbf..4bb7f992 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,7 +124,7 @@ jobs: # Ideally, these would be fixed, but vapory is largely unmaintained, # so here we simply keep the pip behaviour with the --compile flag. # See https://github.com/astral-sh/uv/issues/1928#issuecomment-1968857514 - run: uv pip install --compile -e .[dev,smiles,optimade,eln] aiida-core@git+https://github.com/danielhollas/aiida-core@fix-legacy-fixtures-minimal + run: uv pip install --compile -e .[dev,smiles,optimade,eln] aiida-core==${{ matrix.aiida-core-version }} - name: Run pytest run: pytest -v tests --cov=aiidalab_widgets_base