diff --git a/.aiida-test-cache-config.yml b/.aiida-test-cache-config.yml index 8510deb..091933f 100644 --- a/.aiida-test-cache-config.yml +++ b/.aiida-test-cache-config.yml @@ -10,4 +10,6 @@ archive_cache: # The test archives have version 0.8 - environment_variables_double_quotes # This option was introduced in aiida-core 2.0 - submit_script_filename # This option was introduced in aiida-core 1.2.1 (archive version 0.9) - - metadata_inputs # Added in aiida-core 2.3.0 + # metadata_inputs is now ignored automatically since AiiDA v2.6.0 + # commit 4626b11f85cd0d95a17d8f5766a90b88ddddd689 + #- metadata_inputs # Added in aiida-core 2.3.0 diff --git a/aiida_test_cache/archive_cache/_fixtures.py b/aiida_test_cache/archive_cache/_fixtures.py index 6e6e7a3..a3ce8ee 100644 --- a/aiida_test_cache/archive_cache/_fixtures.py +++ b/aiida_test_cache/archive_cache/_fixtures.py @@ -249,7 +249,7 @@ def mock_objects_to_hash_code(self): """ self = get_node_from_hash_objects_caller(self) # computer names are changed by aiida-core if imported and do not have same uuid. - return [self.base.attributes.get(key='input_plugin')] + return {'input_plugin': self.base.attributes.get(key='input_plugin')} def mock_objects_to_hash_calcjob(self): """ @@ -263,17 +263,19 @@ def mock_objects_to_hash_calcjob(self): self._hash_ignored_attributes = tuple(self._hash_ignored_attributes) + \ calcjob_ignored_attributes - objects = [{ - key: val - for key, val in self.base.attributes.items() - if key not in self._hash_ignored_attributes and key not in self._updatable_attributes - }, - { - entry.link_label: entry.node.base.caching.get_hash() - for entry in self.base.links.get_incoming( - link_type=(LinkType.INPUT_CALC, LinkType.INPUT_WORK) - ) if entry.link_label not in hash_ignored_inputs - }] + objects = { + "attributes": { + key: val + for key, val in self.base.attributes.items() if + key not in self._hash_ignored_attributes and key not in self._updatable_attributes + }, + "inputs": { + entry.link_label: entry.node.base.caching.compute_hash() + for entry in + self.base.links.get_incoming(link_type=(LinkType.INPUT_CALC, LinkType.INPUT_WORK)) + if entry.link_label not in hash_ignored_inputs + }, + } return objects def mock_objects_to_hash(self): @@ -286,13 +288,13 @@ def mock_objects_to_hash(self): self._hash_ignored_attributes = tuple(self._hash_ignored_attributes) + \ node_ignored_attributes.get(class_name, ('version',)) - objects = [ - { + objects = { + "attributes": { key: val for key, val in self.base.attributes.items() if key not in self._hash_ignored_attributes and key not in self._updatable_attributes }, - ] + } return objects monkeypatch_hash_objects(monkeypatch, AbstractCode, mock_objects_to_hash_code) diff --git a/aiida_test_cache/archive_cache/_utils.py b/aiida_test_cache/archive_cache/_utils.py index da23e14..b86ad51 100644 --- a/aiida_test_cache/archive_cache/_utils.py +++ b/aiida_test_cache/archive_cache/_utils.py @@ -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:: @@ -47,16 +47,16 @@ def monkeypatch_hash_objects( """ try: - monkeypatch.setattr(node_class, "_get_objects_to_hash", hash_objects_func) + 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 + NodeCaching subclass with stripped down get_objects_to_hash method """ - def _get_objects_to_hash(self): + def get_objects_to_hash(self): return hash_objects_func(self) monkeypatch.setattr(node_class, "_CLS_NODE_CACHING", MockNodeCaching) @@ -65,9 +65,9 @@ def _get_objects_to_hash(self): 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 diff --git a/tests/archive_cache/test_archive_cache.py b/tests/archive_cache/test_archive_cache.py index 439a277..5274923 100644 --- a/tests/archive_cache/test_archive_cache.py +++ b/tests/archive_cache/test_archive_cache.py @@ -127,7 +127,7 @@ def test_load_node_archive(aiida_profile_clean, absolute_archive_path): 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""" + """test if mock of get_objects_to_hash() works for Code and Calcs""" mock_code = mock_code_factory( label='diff', @@ -135,8 +135,8 @@ def test_mock_hash_codes(aiida_profile_clean, mock_code_factory, liberal_hash): entry_point=CALC_ENTRY_POINT, ignore_paths=('_aiidasubmit.sh', 'file*') ) - objs = mock_code.base.caching._get_objects_to_hash() - assert objs == [mock_code.base.attributes.get(key='input_plugin')] + objs = mock_code.base.caching.get_objects_to_hash() + assert objs == {'input_plugin': mock_code.base.attributes.get(key='input_plugin')} @pytest.mark.parametrize(