Files
slic/tests/test_utils_picklio.py
T
tligui_y c8678e3445
Run CI Tests / test (push) Successful in 30s
Add tests/test_utils_picklio.py
2025-07-25 15:25:13 +02:00

35 lines
882 B
Python

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)