From c50a36389f4ff432b455d8c697c91f84e7b90c5a Mon Sep 17 00:00:00 2001 From: Sebastian Eibl Date: Wed, 5 Feb 2025 12:48:38 +0100 Subject: [PATCH 1/3] fix faulty comparisons --- pyiron_workflow/mixin/semantics.py | 2 +- pyiron_workflow/storage.py | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/pyiron_workflow/mixin/semantics.py b/pyiron_workflow/mixin/semantics.py index 5b4358e1..0659fa75 100644 --- a/pyiron_workflow/mixin/semantics.py +++ b/pyiron_workflow/mixin/semantics.py @@ -97,7 +97,7 @@ def _set_parent(self, new_parent: ParentType | None): self._parent.remove_child(self) self._parent = new_parent self._detached_parent_path = None - if self._parent is not None and self not in self._parent.children: + if self._parent is not None: self._parent.add_child(self) @property diff --git a/pyiron_workflow/storage.py b/pyiron_workflow/storage.py index dcdb626c..9e7a93ca 100644 --- a/pyiron_workflow/storage.py +++ b/pyiron_workflow/storage.py @@ -297,22 +297,11 @@ def available_backends( """ standard_backends = {"pickle": PickleStorage} - - def yield_requested(): - if isinstance(backend, str): - yield standard_backends[backend]() - elif isinstance(backend, StorageInterface): - yield backend + backend = standard_backends.get(backend, PickleStorage)() if isinstance(backend, str) else backend if backend is not None: - yield from yield_requested() + yield backend if only_requested: return - for key, value in standard_backends.items(): - if ( - backend is None - or (isinstance(backend, str) and key != backend) - or (isinstance(backend, StorageInterface) and value != backend) - ): - yield value() + yield from (v() for v in standard_backends.values() if not isinstance(backend, v)) From 3b766a44758008dec7907d3a9ea1bb70f93bec71 Mon Sep 17 00:00:00 2001 From: Sebastian Eibl Date: Wed, 5 Feb 2025 12:52:00 +0100 Subject: [PATCH 2/3] more mypy checks --- .github/workflows/push-pull.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push-pull.yml b/.github/workflows/push-pull.yml index cc88b9a6..1d4e15dc 100644 --- a/.github/workflows/push-pull.yml +++ b/.github/workflows/push-pull.yml @@ -33,7 +33,7 @@ jobs: - name: Install mypy run: pip install mypy - name: Test - run: mypy --ignore-missing-imports ${{ github.event.repository.name }} + run: mypy --ignore-missing-imports --strict-equality ${{ github.event.repository.name }} ruff-check: runs-on: ubuntu-latest From 2373aa81544c61822e794e7895c42dc4b41d28a6 Mon Sep 17 00:00:00 2001 From: Liam Huber Date: Thu, 6 Feb 2025 09:21:27 -0800 Subject: [PATCH 3/3] Fix comparisons tests (#580) * Just use the default value for autoload We are anyhow using the default value -- i.e. "pickle" -- to handle the auto saving. As @XzzX points out, a boolean value here is just straight-up the wrong data type to provide! Signed-off-by: liamhuber * Tolerate and test for string backends * black Signed-off-by: liamhuber * Don't compare instances and classes Signed-off-by: liamhuber --------- Signed-off-by: liamhuber --- pyiron_workflow/storage.py | 14 +++++++++----- tests/unit/test_node.py | 2 +- tests/unit/test_storage.py | 27 ++++++++++++++++++--------- tests/unit/test_type_hinting.py | 3 +-- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/pyiron_workflow/storage.py b/pyiron_workflow/storage.py index 9e7a93ca..7f1b7b6f 100644 --- a/pyiron_workflow/storage.py +++ b/pyiron_workflow/storage.py @@ -297,11 +297,15 @@ def available_backends( """ standard_backends = {"pickle": PickleStorage} - backend = standard_backends.get(backend, PickleStorage)() if isinstance(backend, str) else backend - - if backend is not None: - yield backend + backend_instance = ( + standard_backends.get(backend, PickleStorage)() + if isinstance(backend, str) + else backend + ) + + if backend_instance is not None: + yield backend_instance if only_requested: return - yield from (v() for v in standard_backends.values() if not isinstance(backend, v)) + yield from (v() for k, v in standard_backends.items() if k != backend) diff --git a/tests/unit/test_node.py b/tests/unit/test_node.py index 25119400..4a34435d 100644 --- a/tests/unit/test_node.py +++ b/tests/unit/test_node.py @@ -217,7 +217,7 @@ def test_failure_recovery(self): msg="Expect a recovery file to be saved on failure", ) - reloaded = ANode(label="failing", autoload=True) + reloaded = ANode(label="failing") self.assertIs( reloaded.inputs.x.value, NOT_DATA, diff --git a/tests/unit/test_storage.py b/tests/unit/test_storage.py index 8587c4ba..0883bd3e 100644 --- a/tests/unit/test_storage.py +++ b/tests/unit/test_storage.py @@ -30,15 +30,24 @@ def test_specific_backend(self): self.assertIsInstance(backends[0], PickleStorage) def test_extra_backend(self): - my_interface = PickleStorage() - backends = list(available_backends(my_interface)) - self.assertEqual( - len(backends), 2, msg="We expect both the one we passed, and all defaults" - ) - self.assertIs(backends[0], my_interface) - self.assertIsNot( - backends[0], backends[1], msg="They should be separate instances" - ) + with self.subTest("String backend"): + backends = list(available_backends("pickle")) + print(backends) + self.assertEqual(len(backends), 1, msg="We expect only the defaults") + self.assertIsInstance(backends[0], PickleStorage) + + with self.subTest("Object backend"): + my_interface = PickleStorage() + backends = list(available_backends(my_interface)) + self.assertEqual( + len(backends), + 2, + msg="We expect both the one we passed, and all defaults", + ) + self.assertIs(backends[0], my_interface) + self.assertIsNot( + backends[0], backends[1], msg="They should be separate instances" + ) def test_exclusive_backend(self): my_interface = PickleStorage() diff --git a/tests/unit/test_type_hinting.py b/tests/unit/test_type_hinting.py index e4e3454d..d4058ef1 100644 --- a/tests/unit/test_type_hinting.py +++ b/tests/unit/test_type_hinting.py @@ -118,7 +118,7 @@ def test_hint_comparisons(self): def test_get_type_hints(self): for hint, origin in [ - (int | float, type(int| float)), + (int | float, type(int | float)), (typing.Annotated[int | float, "foo"], type(int | float)), (int, None), (typing.Annotated[int, "foo"], None), @@ -129,6 +129,5 @@ def test_get_type_hints(self): self.assertEqual(_get_type_hints(hint)[0], origin) - if __name__ == "__main__": unittest.main()