This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user