Skip to content

Commit c4815d3

Browse files
committed
added unit test
1 parent fbf9bdb commit c4815d3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test_utils.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
from nucleus import DatasetItem
3+
from nucleus import utils
4+
5+
import io
6+
7+
8+
class TestNonSerializableObject:
9+
def weird_function():
10+
print("can't touch this. Dun dun dun dun.")
11+
12+
13+
def test_serialize():
14+
15+
test_items = [
16+
DatasetItem("fake_url1", "fake_id1"),
17+
DatasetItem(
18+
"fake_url2",
19+
"fake_id2",
20+
metadata={
21+
"ok": "field",
22+
"bad": TestNonSerializableObject(),
23+
},
24+
),
25+
]
26+
27+
with io.StringIO() as in_memory_filelike:
28+
with pytest.raises(ValueError) as error:
29+
utils.serialize_and_write(
30+
test_items,
31+
in_memory_filelike,
32+
)
33+
assert "DatasetItem" in str(error.value)
34+
assert "fake_id2" in str(error.value)
35+
assert "fake_id1" not in str(error.value)
36+
37+
test_items[1].metadata["bad"] = "fixed"
38+
39+
utils.serialize_and_write(test_items, in_memory_filelike)

0 commit comments

Comments
 (0)