From c8678e3445ff6e55ead50297e6586c9fec097108 Mon Sep 17 00:00:00 2001 From: tligui_y Date: Fri, 25 Jul 2025 15:25:13 +0200 Subject: [PATCH] Add tests/test_utils_picklio.py --- tests/test_utils_picklio.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test_utils_picklio.py diff --git a/tests/test_utils_picklio.py b/tests/test_utils_picklio.py new file mode 100644 index 000000000..4c7d9cc59 --- /dev/null +++ b/tests/test_utils_picklio.py @@ -0,0 +1,34 @@ +import pytest +import sys +import os +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +from slic.utils.picklio import * + +@pytest.mark.parametrize( + "test_obj", + [ + {"a": 1, "b": [2, 3], "c": {"world": "ok"}}, + [1, 2, 3, 4, 5], + "simple string", + 42, + 3.14159, + (True, False, None), + {"complex": [{"list": [1, 2]}, {"dict": {"x": 10}}]}, + ] +) +def test_pickle_and_unpickle(tmp_path, test_obj): + filepath = tmp_path / "file.txt" + + pickle(test_obj, filepath) + + # Check if the file has been created + assert filepath.exists() + + # Read the filed file + loaded_obj = unpickle(filepath) + + # Verify that the content is similar to the given one + to see if the files are well read by unpickle() + assert loaded_obj == test_obj + + # Remove the created file + os.remove(filepath)