Skip to content

Commit 56f6b2b

Browse files
committed
Add some tests
1 parent e33c6bb commit 56f6b2b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/pytest_pl_grader/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,16 @@ def get_builtins(builtin_whitelist: list[str] | None) -> dict[str, Any]:
140140
"oct",
141141
"ord",
142142
"pow",
143+
"print",
143144
"range",
144145
"repr",
145146
"round",
146147
"slice",
147148
"sorted",
148149
"str",
150+
"set",
151+
"list",
152+
"dict",
149153
"tuple",
150154
"zip",
151155
"enumerate",

tests/test_serialize.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from typing import Any
12
from typing import cast
23

34
import numpy as np
5+
import pytest
46

7+
from pytest_pl_grader.json_utils import from_json
8+
from pytest_pl_grader.json_utils import to_json
59
from pytest_pl_grader.utils import deserialize_object_unsafe
610
from pytest_pl_grader.utils import serialize_object_unsafe
711

@@ -18,3 +22,14 @@ def test_serialize_numpy_array() -> None:
1822

1923
# Check if the original and deserialized arrays are equal
2024
assert np.array_equal(arr, deserialized)
25+
26+
27+
@pytest.mark.parametrize("obj", [np.bool(True), np.int32(42), np.float64(3.14), complex(1, 2)])
28+
def test_serialize_json(obj: Any) -> None:
29+
# Serialize the object to JSON-compatible format
30+
json_compatible = to_json(obj)
31+
32+
# Deserialize back to original object
33+
deserialized = from_json(json_compatible)
34+
35+
np.testing.assert_equal(obj, deserialized)

0 commit comments

Comments
 (0)