Skip to content

Commit 49d107b

Browse files
committed
add test
1 parent c1a1fc8 commit 49d107b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

schema_salad/tests/test_examples.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
"""Test examples."""
2+
import datetime
13
import os
4+
from typing import cast
25

36
from pytest import CaptureFixture
47
from ruamel.yaml.comments import CommentedMap, CommentedSeq
@@ -391,6 +394,37 @@ def test_scoped_id() -> None:
391394
g.serialize(destination=stdout(), format="n3")
392395

393396

397+
def test_rdf_datetime() -> None:
398+
"""Affirm that datetime objects can be serialized in makerdf()."""
399+
ldr = Loader({})
400+
ctx: ContextType = {
401+
"id": "@id",
402+
"location": {"@id": "@id", "@type": "@id"},
403+
"bar": "http://example.com/bar",
404+
"ex": "http://example.com/",
405+
}
406+
ldr.add_context(ctx)
407+
408+
ra: CommentedMap = cast(
409+
CommentedMap,
410+
ldr.resolve_all(
411+
cmap(
412+
{
413+
"id": "foo",
414+
"bar": {"id": "baz"},
415+
}
416+
),
417+
"http://example.com",
418+
)[0],
419+
)
420+
ra["s:dateCreated"] = datetime.datetime(2020, 10, 8)
421+
422+
g = makerdf(None, ra, ctx)
423+
g.serialize(destination=stdout(), format="n3")
424+
g2 = makerdf(None, CommentedSeq([ra]), ctx)
425+
g2.serialize(destination=stdout(), format="n3")
426+
427+
394428
def test_subscoped_id() -> None:
395429
ldr = Loader({})
396430
ctx = {

0 commit comments

Comments
 (0)