From d7b5ad02e8f2bd189c99f8d5c5458ad2fe8e054c Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 23 Apr 2024 17:00:35 +1000 Subject: [PATCH] tests: add object serializer test for dangling folders - Ensure they are deleted on init if ephemeral - Ensure they are _not_ deleted on init if _not_ ephemeral --- tests/test_object_serializer_disk.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_object_serializer_disk.py b/tests/test_object_serializer_disk.py index 125534c500..84c6e876fc 100644 --- a/tests/test_object_serializer_disk.py +++ b/tests/test_object_serializer_disk.py @@ -99,6 +99,20 @@ def test_obj_serializer_ephemeral_writes_to_tempdir(tmp_path: Path): assert not Path(tmp_path, obj_1_name).exists() +def test_obj_serializer_ephemeral_deletes_dangling_tempdirs_on_init(tmp_path: Path): + tempdir = tmp_path / "tmpdir" + tempdir.mkdir() + ObjectSerializerDisk[MockDataclass](tmp_path, ephemeral=True) + assert not tempdir.exists() + + +def test_obj_serializer_does_not_delete_tempdirs_on_init(tmp_path: Path): + tempdir = tmp_path / "tmpdir" + tempdir.mkdir() + ObjectSerializerDisk[MockDataclass](tmp_path, ephemeral=False) + assert tempdir.exists() + + def test_obj_serializer_disk_different_types(tmp_path: Path): obj_serializer_1 = ObjectSerializerDisk[MockDataclass](tmp_path) obj_1 = MockDataclass(foo="bar")