File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ """Test examples."""
2+ import datetime
13import os
4+ from typing import cast
25
36from pytest import CaptureFixture
47from 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+
394428def test_subscoped_id () -> None :
395429 ldr = Loader ({})
396430 ctx = {
You can’t perform that action at this time.
0 commit comments