Skip to content

Commit

Permalink
added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ardila committed Apr 26, 2021
1 parent fbf9bdb commit c4815d3
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
from nucleus import DatasetItem
from nucleus import utils

import io


class TestNonSerializableObject:
def weird_function():
print("can't touch this. Dun dun dun dun.")


def test_serialize():

test_items = [
DatasetItem("fake_url1", "fake_id1"),
DatasetItem(
"fake_url2",
"fake_id2",
metadata={
"ok": "field",
"bad": TestNonSerializableObject(),
},
),
]

with io.StringIO() as in_memory_filelike:
with pytest.raises(ValueError) as error:
utils.serialize_and_write(
test_items,
in_memory_filelike,
)
assert "DatasetItem" in str(error.value)
assert "fake_id2" in str(error.value)
assert "fake_id1" not in str(error.value)

test_items[1].metadata["bad"] = "fixed"

utils.serialize_and_write(test_items, in_memory_filelike)

0 comments on commit c4815d3

Please sign in to comment.