|
1 | 1 | import pytest |
| 2 | +from rdflib import Dataset |
2 | 3 |
|
3 | 4 | import pyld.jsonld as jsonld |
4 | 5 |
|
@@ -952,6 +953,52 @@ def test_double_and_float_values(self): |
952 | 953 | ) |
953 | 954 | result = jsonld.to_rdf(input, {"format": "application/n-quads"}) |
954 | 955 | 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 | + ) |
955 | 1002 |
|
956 | 1003 | def test_large_integer_to_rdf_double_conversion_processing_mode(self): |
957 | 1004 | """ |
|
0 commit comments