Skip to content

Commit af91060

Browse files
committed
Add tests for legacy mode
1 parent 73bcd9b commit af91060

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

tests/test_jsonld.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from rdflib import Dataset
23

34
import pyld.jsonld as jsonld
45

@@ -952,6 +953,52 @@ def test_double_and_float_values(self):
952953
)
953954
result = jsonld.to_rdf(input, {"format": "application/n-quads"})
954955
assert result == expected
956+
957+
def test_legacy_mode(self):
958+
"""
959+
legacyMode should return the PyLD 3.x RDF.js-like dataset dict.
960+
"""
961+
input = {
962+
"@context": {"xsd": "http://www.w3.org/2001/XMLSchema#"},
963+
"@graph": [
964+
{"@id": "ex:1", "ex:p": {"@type": "xsd:double", "@value": "45"}}
965+
],
966+
}
967+
expected = {
968+
"@default": [
969+
{
970+
"subject": {"type": "IRI", "value": "ex:1"},
971+
"predicate": {"type": "IRI", "value": "ex:p"},
972+
"object": {
973+
"type": "literal",
974+
"value": "4.5E1",
975+
"datatype": "http://www.w3.org/2001/XMLSchema#double",
976+
},
977+
}
978+
]
979+
}
980+
981+
assert isinstance(jsonld.to_rdf(input), Dataset)
982+
assert jsonld.to_rdf(input, {"legacyMode": True}) == expected
983+
984+
def test_format_takes_precedence_over_legacy_mode(self):
985+
"""
986+
N-Quads format output should still be returned when legacyMode is true.
987+
"""
988+
input = {
989+
"@context": {"xsd": "http://www.w3.org/2001/XMLSchema#"},
990+
"@graph": [
991+
{"@id": "ex:1", "ex:p": {"@type": "xsd:double", "@value": "45"}}
992+
],
993+
}
994+
995+
assert jsonld.to_rdf(
996+
input,
997+
{"format": "application/n-quads", "legacyMode": True},
998+
) == (
999+
'<ex:1> <ex:p> "4.5E1"'
1000+
"^^<http://www.w3.org/2001/XMLSchema#double> .\n\n"
1001+
)
9551002

9561003
def test_large_integer_to_rdf_double_conversion_processing_mode(self):
9571004
"""

0 commit comments

Comments
 (0)