Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
python-version: ['3.10', '3.11', '3.12', '3.13']
resolution: ['highest']
# Include a job with minimum supported aiida-version,
# achieved via uv's resolution strategy, see:
Expand All @@ -26,25 +26,6 @@ jobs:
resolution: 'lowest-direct'
fail-fast: false

services:
postgres:
image: postgres:10
env:
POSTGRES_DB: test_aiida
POSTGRES_PASSWORD: ''
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
rabbitmq:
image: rabbitmq:latest
ports:
- 5672:5672

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
41 changes: 11 additions & 30 deletions aiida_test_cache/archive_cache/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def monkeypatch_hash_objects(
monkeypatch: pytest.MonkeyPatch, node_class: type[Node], hash_objects_func: ty.Callable
) -> None:
"""
Monkeypatch the _get_objects_to_hash method in aiida-core for the given node class
Monkeypatch the get_objects_to_hash method in aiida-core for the given node class

:param monkeypatch: monkeypatch fixture of pytest
:param node_class: Node class to monkeypatch
:param hash_objects_func: function, which should be called instead of the
`_get_objects_to_hash` method
`get_objects_to_hash` method

.. note::

Expand All @@ -46,44 +46,25 @@ def monkeypatch_hash_objects(
monkeypatched on the Nodes, i.e. the _CLS_NODE_CACHING attribute

"""
try:
monkeypatch.setattr(node_class, "_get_objects_to_hash", hash_objects_func)
except AttributeError:
node_caching_class = node_class._CLS_NODE_CACHING

class MockNodeCaching(node_caching_class): #type: ignore
"""
NodeCaching subclass with stripped down _get_objects_to_hash method
"""

# Compatibility with aiida-core < 2.6
# In https://github.com/aiidateam/aiida-core/pull/6323
def _get_objects_to_hash(self):
return self.get_objects_to_hash()

def get_objects_to_hash(self):
return hash_objects_func(self)
class MockNodeCaching(node_class._CLS_NODE_CACHING): # type: ignore[misc,name-defined]
"""
NodeCaching subclass with stripped down get_objects_to_hash method
"""

# Compatibility with aiida-core < 2.6
# https://github.com/aiidateam/aiida-core/pull/6347
def compute_hash(self):
try:
return super().compute_hash()
except AttributeError:
return super().get_hash()
def get_objects_to_hash(self):
return hash_objects_func(self)

monkeypatch.setattr(node_class, "_CLS_NODE_CACHING", MockNodeCaching)
monkeypatch.setattr(node_class, "_CLS_NODE_CACHING", MockNodeCaching)


def get_node_from_hash_objects_caller(caller: ty.Any) -> Node:
"""
Get the actual node instance from the class calling the
_get_objects_to_hash method
get_objects_to_hash method

:param caller: object holding _get_objects_to_hash
:param caller: object holding get_objects_to_hash
"""
#Case for AiiDA 2.0: The class holding the _get_objects_to_hash method
#is the NodeCaching class not the actual node
return caller._node #type: ignore[no-any-return]


Expand Down
2 changes: 1 addition & 1 deletion aiida_test_cache/mock_code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
)

# ensure aiida's pytest plugin is loaded, which we rely on
pytest_plugins = ['aiida.manage.tests.pytest_fixtures']
pytest_plugins = ['aiida.tools.pytest_fixtures']
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ keywords = [
urls = {Homepage = "https://aiida-testing.readthedocs.io/"}
requires-python = ">=3.9"
dependencies = [
"aiida-core>=2.1,<3",
"aiida-core>=2.6,<3",
"pytest>=7.0",
"voluptuous~=0.12",
]
Expand Down
30 changes: 18 additions & 12 deletions tests/archive_cache/test_archive_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _check_diff_workchain(res, node, should_have_used_cache=True):
assert diffjob.base.caching.is_valid_cache

calc_hash = diffjob.base.caching.get_hash()
assert calc_hash == EXPECTED_HASH, f'Hash mismatch. hashed objects: {diffjob.base.caching._get_objects_to_hash()}'
assert calc_hash == EXPECTED_HASH, f'Hash mismatch. hashed objects: {diffjob.base.caching.get_objects_to_hash()}'

#Make sure that the cache was used if it should have been
if should_have_used_cache:
Expand All @@ -81,7 +81,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
Expand Down Expand Up @@ -112,7 +114,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')
Expand All @@ -126,32 +128,34 @@ 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):
"""test if mock of _get_objects_to_hash works for Code and Calcs"""
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(
label='diff',
data_dir_abspath=CWD / 'calc_data',
entry_point=CALC_ENTRY_POINT,
ignore_paths=('_aiidasubmit.sh', 'file*')
)
objs = mock_code.base.caching._get_objects_to_hash()
objs = mock_code.base.caching.get_objects_to_hash()
assert objs == [mock_code.base.attributes.get(key='input_plugin')]


@pytest.mark.parametrize(
"archive_path", [CWD / "caches/test_workchain.tar.gz", "test_workchain.tar.gz"]
'archive_path', [CWD / 'caches/test_workchain.tar.gz', 'test_workchain.tar.gz']
)
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', default_calc_job_plugin=CALC_ENTRY_POINT
)
diff_code.store()
inputs['diff']['code'] = diff_code
with enable_archive_cache(archive_path, calculation_class=CalculationFactory(CALC_ENTRY_POINT)):
Expand All @@ -161,7 +165,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
):
"""
Expand All @@ -170,7 +174,9 @@ 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', default_calc_job_plugin=CALC_ENTRY_POINT
)
diff_code.store()
inputs['diff']['code'] = diff_code

Expand Down