From 6b8b368a5f6ee406cdd48d59a57c709ff45de7be Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 19 Nov 2024 11:31:17 +0100 Subject: [PATCH 1/5] Support new fixtures with sqlite backend --- .github/workflows/ci.yml | 4 ++-- aiida_test_cache/mock_code/__init__.py | 20 +++++++++++++++----- pyproject.toml | 7 ++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ba64b2..46f131d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,10 +57,10 @@ jobs: - name: Run test suite env: # show timings of tests - PYTEST_ADDOPTS: "--durations=0" + PYTEST_ADDOPTS: "--durations=10" run: | aiida-mock-code || true - cd tests; pytest + pytest -s pre-commit: runs-on: ubuntu-latest diff --git a/aiida_test_cache/mock_code/__init__.py b/aiida_test_cache/mock_code/__init__.py index ee799d0..73c9d99 100644 --- a/aiida_test_cache/mock_code/__init__.py +++ b/aiida_test_cache/mock_code/__init__.py @@ -9,12 +9,22 @@ # Note: This is necessary for the sphinx doc - otherwise it does not find aiida_test_cache.mock_code.mock_code_factory __all__ = ( - "pytest_addoption", - "testing_config_action", + "mock_code_factory", "mock_regenerate_test_data", + "pytest_addoption", "testing_config", - "mock_code_factory", + "testing_config_action", ) -# ensure aiida's pytest plugin is loaded, which we rely on -pytest_plugins = ['aiida.manage.tests.pytest_fixtures'] +# Load aiida's pytest fixtures +# For aiida-core>=2.6 we load new fixtures which use sqlite backend. +# WARNING: It's not clear what happens if the user later loads +# the old fixtures as well. +from aiida import __version__ as aiida_version +from pkg_resources import parse_version + +if parse_version(aiida_version) >= parse_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] diff --git a/pyproject.toml b/pyproject.toml index 5bdfb4f..2e2f3fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,7 +76,12 @@ aiida_mock_code = "aiida_test_cache.mock_code" aiida_archive_cache = "aiida_test_cache.archive_cache" [tool.pytest.ini_options] -filterwarnings = [] +addopts = '--durations-min=3 --strict-config --strict-markers -ra' +filterwarnings = [ + 'ignore:Creating AiiDA configuration:UserWarning:aiida', + # The following deprecation warnings come from Python 3.12 stdlib modules + "ignore:datetime.datetime.:DeprecationWarning:", +] [tool.yapf] based_on_style = "pep8" From 84fd6e656b567ab8864e3da1038161f9ddf26d6a Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Mon, 2 Dec 2024 13:03:07 +0000 Subject: [PATCH 2/5] Relax aiida-core constraint --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2e2f3fe..d5c0677 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ urls = {Homepage = "https://aiida-testing.readthedocs.io/"} requires-python = ">=3.7" # Note the dependency on setuptools due to pkg_resources dependencies = [ - "aiida-core>=1.0.0,<2.6", + "aiida-core>=1.0.0,<3", "pytest>=7.0", "voluptuous~=0.12", "setuptools", From fec47b758a7e5f01b081e514e622d3930e7e6f5b Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Mon, 2 Dec 2024 13:30:22 +0000 Subject: [PATCH 3/5] Use new fixtures in test_archive_cache --- tests/archive_cache/test_archive_cache.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/archive_cache/test_archive_cache.py b/tests/archive_cache/test_archive_cache.py index 93d9264..3e90e43 100644 --- a/tests/archive_cache/test_archive_cache.py +++ b/tests/archive_cache/test_archive_cache.py @@ -79,7 +79,9 @@ def _check_diff_workchain(res, node, should_have_used_cache=True): #### tests -def test_create_node_archive(mock_code_factory, generate_diff_inputs, clear_database, tmp_path): +def test_create_node_archive( + aiida_profile_clean, mock_code_factory, generate_diff_inputs, tmp_path +): """ Basic test of the create node archive fixture functionality, runs diff workchain and creates archive, check if archive was created @@ -110,7 +112,7 @@ def test_create_node_archive(mock_code_factory, generate_diff_inputs, clear_data assert os.path.isfile(archive_path) -def test_load_node_archive(clear_database, absolute_archive_path): +def test_load_node_archive(aiida_profile_clean, absolute_archive_path): """Basic test of the load node archive fixture functionality, check if archive is loaded""" full_archive_path = absolute_archive_path('diff_workchain.tar.gz') @@ -124,7 +126,7 @@ def test_load_node_archive(clear_database, absolute_archive_path): assert n_nodes == 9 -def test_mock_hash_codes(mock_code_factory, clear_database, liberal_hash): +def test_mock_hash_codes(aiida_profile_clean, mock_code_factory, liberal_hash): """test if mock of _get_objects_to_hash works for Code and Calcs""" mock_code = mock_code_factory( @@ -144,15 +146,15 @@ def test_mock_hash_codes(mock_code_factory, clear_database, liberal_hash): ] ) def test_enable_archive_cache( - archive_path, aiida_local_code_factory, generate_diff_inputs, enable_archive_cache, - clear_database, check_diff_workchain + archive_path, aiida_profile_clean, aiida_code_installed, generate_diff_inputs, + enable_archive_cache, check_diff_workchain ): """ Basic test of the enable_archive_cache fixture """ inputs = {'diff': generate_diff_inputs()} - diff_code = aiida_local_code_factory(executable='diff', entry_point='diff') + diff_code = aiida_code_installed(filepath_executable='diff') diff_code.store() inputs['diff']['code'] = diff_code with enable_archive_cache(archive_path, calculation_class=CalculationFactory(CALC_ENTRY_POINT)): @@ -162,7 +164,7 @@ def test_enable_archive_cache( def test_enable_archive_cache_non_existent( - aiida_local_code_factory, generate_diff_inputs, enable_archive_cache, clear_database, + aiida_profile_clean, aiida_code_installed, generate_diff_inputs, enable_archive_cache, tmp_path_factory, check_diff_workchain ): """ @@ -171,7 +173,7 @@ def test_enable_archive_cache_non_existent( """ inputs = {'diff': generate_diff_inputs()} - diff_code = aiida_local_code_factory(executable='diff', entry_point='diff') + diff_code = aiida_code_installed(filepath_executable='diff') diff_code.store() inputs['diff']['code'] = diff_code From 49b0d0842f836688c655d13541c97fe873f7de7c Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Mon, 9 Dec 2024 11:55:43 +0000 Subject: [PATCH 4/5] pkg_resources.parse_version -> packaging.version.Version --- aiida_test_cache/mock_code/__init__.py | 4 ++-- pyproject.toml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/aiida_test_cache/mock_code/__init__.py b/aiida_test_cache/mock_code/__init__.py index 73c9d99..948bb63 100644 --- a/aiida_test_cache/mock_code/__init__.py +++ b/aiida_test_cache/mock_code/__init__.py @@ -21,9 +21,9 @@ # WARNING: It's not clear what happens if the user later loads # the old fixtures as well. from aiida import __version__ as aiida_version -from pkg_resources import parse_version +from packaging.version import Version -if parse_version(aiida_version) >= parse_version('2.6.0'): +if Version(aiida_version) >= Version('2.6.0'): aiida_core_fixtures = 'aiida.tools.pytest_fixtures' else: aiida_core_fixtures = 'aiida.manage.tests.pytest_fixtures' diff --git a/pyproject.toml b/pyproject.toml index 28e3850..cb684dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,7 @@ dependencies = [ "aiida-core>=1.0.0,<3", "pytest>=7.0", "voluptuous~=0.12", + "packaging>=21.0", ] [project.optional-dependencies] From abab964d42c32638007025f374197c2eb81ca792 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Mon, 9 Dec 2024 11:56:54 +0000 Subject: [PATCH 5/5] Revert CI change --- .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 4facfdd..1fb0765 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,7 @@ jobs: - name: Run test suite env: # show timings of tests - PYTEST_ADDOPTS: "--durations=10" + PYTEST_ADDOPTS: "--durations=0" run: | aiida-mock-code || true pytest --cov=aiida_test_cache tests/