Skip to content

Commit

Permalink
Fix comparisons tests (#580)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Tolerate and test for string backends

* black

Signed-off-by: liamhuber <[email protected]>

* Don't compare instances and classes

Signed-off-by: liamhuber <[email protected]>

---------

Signed-off-by: liamhuber <[email protected]>
  • Loading branch information
liamhuber authored Feb 6, 2025
1 parent 3b766a4 commit 2373aa8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
14 changes: 9 additions & 5 deletions pyiron_workflow/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/unit/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 18 additions & 9 deletions tests/unit/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_type_hinting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -129,6 +129,5 @@ def test_get_type_hints(self):
self.assertEqual(_get_type_hints(hint)[0], origin)



if __name__ == "__main__":
unittest.main()

0 comments on commit 2373aa8

Please sign in to comment.