@@ -27,26 +27,26 @@ def test_malformed_input():
2727
2828
2929def test_build_in_get ():
30- di = ld_dict ([{"name" : [{"@value" : "Manu Sporny" }],
31- "homepage" : [{"@id" : "http://manu.sporny.org/" }],
32- "foo" : [{"foobar" : "bar" , "barfoo" : "foo" }]}])
33- assert di ["name" ] == "Manu Sporny"
34- assert di ["homepage" ] == "http://manu.sporny.org/"
35- assert di ["foo" ].data_dict == ld_dict ([{"foobar" : "bar" , "barfoo" : "foo" }]).data_dict
30+ di = ld_dict ([{"http://xmlns.com/foaf/0.1/name" : [{"@value" : "Manu Sporny" }],
31+ "http://xmlns.com/foaf/0.1/homepage" : [{"@id" : "http://manu.sporny.org/" }],
32+ "http://xmlns.com/foaf/0.1/foo" : [{"http://xmlns.com/foaf/0.1/foobar" : [{"@value" : "bar" }],
33+ "http://xmlns.com/foaf/0.1/barfoo" : [{"@value" : "foo" }]}]}],
34+ context = [{"xmlns" : "http://xmlns.com/foaf/0.1/" }])
35+ assert di ["xmlns:name" ] == ["Manu Sporny" ]
36+ assert di ["xmlns:homepage" ] == ["http://manu.sporny.org/" ]
37+ assert di ["xmlns:foo" ] == [{"xmlns:foobar" : ["bar" ], "xmlns:barfoo" : ["foo" ]}]
3638 with pytest .raises (KeyError ):
3739 di ["bar" ]
3840
3941 di = ld_dict ([{"http://xmlns.com/foaf/0.1/name" : [{"@value" : "Manu Sporny" }]}],
4042 context = [{"xmlns" : "http://xmlns.com/foaf/0.1/" }])
41- assert di ["xmlns:name" ] == "Manu Sporny"
43+ assert di ["xmlns:name" ] == [ "Manu Sporny" ]
4244
43- # FIXME: fixing #433 would fix this
44- # get -> list to python -> create empty list -> to fill dicts -> expand them -> no expansion method for dicts
4545 di = ld_dict ([{"http://xmlns.com/foaf/0.1/name" : [{"@value" : "foo" }],
4646 "http://xmlns.com/foaf/0.1/foo" : [{"http://xmlns.com/foaf/0.1/barfoo" : [{"@id" : "foo" }],
4747 "http://xmlns.com/foaf/0.1/fooba" : [{"@value" : "ba" }]},
4848 {"http://xmlns.com/foaf/0.1/barfoo" : [{"@id" : "foo" }],
49- "http://xmlns.com/foaf/0.1/fooba" : [{"@value" : "ba" }]}]}],
49+ "http://xmlns.com/foaf/0.1/fooba" : [{"@value" : "ba" }]}]}],
5050 context = [{"xmlns" : "http://xmlns.com/foaf/0.1/" }])
5151 assert isinstance (di ["http://xmlns.com/foaf/0.1/foo" ], ld_list )
5252
@@ -131,7 +131,7 @@ def test_build_in_set():
131131 }]
132132 }]
133133 }
134- assert isinstance (di ["schema:result" ]["schema:error" ]["schema:name" ], ld_list )
134+ assert isinstance (di ["schema:result" ][0 ][ "schema:error" ][ 0 ]["schema:name" ], ld_list )
135135
136136 # FIXME: fixing #433 would fix this (setting nested python dicts)
137137 di = ld_dict ([{}], context = [{"schema" : "https://schema.org/" }])
@@ -165,6 +165,7 @@ def test_build_in_contains():
165165 assert "http://xmlns.com/foaf/0.1/name" in di and "xmlns:homepage" in di
166166 assert "xmlns:foo" not in di and "homepage" not in di and "foo" not in di
167167
168+
168169def test_build_in_comparison ():
169170 di = ld_dict ([{}], context = {"schema" : "https://schema.org/" })
170171 assert di != 1 and di != [] and di != ""
@@ -183,10 +184,12 @@ def test_build_in_comparison():
183184 assert di == {"schema:Person" : [{"schema:name" : "foo" }, {"schema:name" : "bar" }]}
184185 assert di != {"schema:name" : "foo" }
185186
187+
186188def test_get ():
187- di = ld_dict ([{"https://schema.org/name" : [{"@value" : "Manu Sporny" }]}], context = [{"schema" : "https://schema.org/" }])
188- assert di .get ("https://schema.org/name" ) == "Manu Sporny"
189- assert di .get ("schema:name" ) == "Manu Sporny"
189+ di = ld_dict ([{"https://schema.org/name" : [{"@value" : "Manu Sporny" }]}],
190+ context = [{"schema" : "https://schema.org/" }])
191+ assert di .get ("https://schema.org/name" ) == ["Manu Sporny" ]
192+ assert di .get ("schema:name" ) == ["Manu Sporny" ]
190193 assert di .get ("bar" , None ) is None
191194 with pytest .raises (KeyError ):
192195 di .get ("bar" )
@@ -240,7 +243,8 @@ def test_compact_keys():
240243 "http://xmlns.com/foaf/0.1/homepage" : {"@id" : "http://manu.sporny.org/" }})
241244 assert {* di .compact_keys ()} == {"http://xmlns.com/foaf/0.1/name" , "homepage" }
242245
243- di = ld_dict ([{}], context = [{"xmls" : "http://xmlns.com/foaf/0.1/" , "homepage" : "http://xmlns.com/foaf/0.1/homepage" }])
246+ di = ld_dict ([{}],
247+ context = [{"xmls" : "http://xmlns.com/foaf/0.1/" , "homepage" : "http://xmlns.com/foaf/0.1/homepage" }])
244248 di .update ({"http://xmlns.com/foaf/0.1/name" : "Manu Sporny" ,
245249 "http://xmlns.com/foaf/0.1/homepage" : {"@id" : "http://manu.sporny.org/" }})
246250 assert {* di .compact_keys ()} == {"xmls:name" , "homepage" }
@@ -251,11 +255,11 @@ def test_items():
251255 inner_di = ld_dict ([{}], parent = di , key = "http://xmlns.com/foaf/0.1/foo" )
252256 inner_di .update ({"xmlns:foobar" : "bar" , "http://xmlns.com/foaf/0.1/barfoo" : {"@id" : "foo" }})
253257 di .update ({"http://xmlns.com/foaf/0.1/name" : "foo" , "xmlns:homepage" : {"@id" : "bar" }, "xmlns:foo" : inner_di })
254- assert [* di .items ()][0 :2 ] == [("http://xmlns.com/foaf/0.1/name" , "foo" ),
255- ("http://xmlns.com/foaf/0.1/homepage" , "bar" )]
258+ assert [* di .items ()][0 :2 ] == [("http://xmlns.com/foaf/0.1/name" , [ "foo" ] ),
259+ ("http://xmlns.com/foaf/0.1/homepage" , [ "bar" ] )]
256260 assert [* di .items ()][2 ][0 ] == "http://xmlns.com/foaf/0.1/foo"
257- assert [* di .items ()][2 ][1 ]. data_dict == {"http://xmlns.com/foaf/0.1/foobar" : [{"@value" : "bar" }],
258- "http://xmlns.com/foaf/0.1/barfoo" : [{"@id" : "foo" }]}
261+ assert [* di .items ()][2 ][1 ][ 0 ] == {"http://xmlns.com/foaf/0.1/foobar" : [{"@value" : "bar" }],
262+ "http://xmlns.com/foaf/0.1/barfoo" : [{"@id" : "foo" }]}
259263
260264
261265def test_ref ():
@@ -273,14 +277,14 @@ def test_to_python():
273277 inner_di = ld_dict ([{}], parent = di )
274278 inner_di .update ({"xmlns:foobar" : "bar" , "http://xmlns.com/foaf/0.1/barfoo" : {"@id" : "foo" }})
275279 di .update ({"http://xmlns.com/foaf/0.1/name" : "foo" , "xmlns:homepage" : {"@id" : "bar" }, "xmlns:foo" : inner_di })
276- assert di .to_python () == {"xmlns:name" : "foo" , "xmlns:homepage" : "bar" ,
277- "xmlns:foo" : {"xmlns:foobar" : "bar" , "xmlns:barfoo" : "foo" } }
280+ assert di .to_python () == {"xmlns:name" : [ "foo" ] , "xmlns:homepage" : [ "bar" ] ,
281+ "xmlns:foo" : [ {"xmlns:foobar" : [ "bar" ] , "xmlns:barfoo" : [ "foo" ]}] }
278282 di .update ({"http://spam.eggs/eggs" : {
279283 "@value" : "2022-02-22T00:00:00" , "@type" : "https://schema.org/DateTime"
280284 }})
281- assert di .to_python () == {"xmlns:name" : "foo" , "xmlns:homepage" : "bar" ,
282- "xmlns:foo" : {"xmlns:foobar" : "bar" , "xmlns:barfoo" : "foo" } ,
283- "http://spam.eggs/eggs" : "2022-02-22T00:00:00" }
285+ assert di .to_python () == {"xmlns:name" : [ "foo" ] , "xmlns:homepage" : [ "bar" ] ,
286+ "xmlns:foo" : [ {"xmlns:foobar" : [ "bar" ] , "xmlns:barfoo" : [ "foo" ]}] ,
287+ "http://spam.eggs/eggs" : [ "2022-02-22T00:00:00" ] }
284288
285289
286290def test_from_dict ():
@@ -326,13 +330,15 @@ def test_from_dict():
326330 assert di .full_context == 2 * [{"schema" : "https://schema.org/" }]
327331 assert di .context == [] and di .key == "schema:error" and di .index is None
328332
329- di = ld_dict .from_dict ({"@context" : [{"schema" : "https://schema.org/" }], "@type" : "schema:Thing" , "xmlns:name" : "fo" },
333+ di = ld_dict .from_dict ({"@context" : [{"schema" : "https://schema.org/" }],
334+ "@type" : "schema:Thing" , "xmlns:name" : "fo" },
330335 context = [{"schema" : "https://schema.org/" , "xmlns" : "http://xmlns.com/foaf/0.1/" }])
331- assert di ["http://xmlns.com/foaf/0.1/name" ] == di ["xmlns:name" ] == "fo"
336+ assert di ["http://xmlns.com/foaf/0.1/name" ] == di ["xmlns:name" ] == [ "fo" ]
332337 assert di .context == [{"schema" : "https://schema.org/" },
333338 {"schema" : "https://schema.org/" , "xmlns" : "http://xmlns.com/foaf/0.1/" }]
334339
335- outer_di = ld_dict .from_dict ({"@context" : [{"schema" : "https://schema.org/" }], "@type" : "schema:Thing" , "@id" : "foo" })
340+ outer_di = ld_dict .from_dict ({"@context" : [{"schema" : "https://schema.org/" }],
341+ "@type" : "schema:Thing" , "@id" : "foo" })
336342 di = ld_dict .from_dict ({"@context" : {"schema" : "https://schema.org/" }, "@type" : "schema:Action" ,
337343 "schema:name" : "foo" },
338344 parent = outer_di , key = "schema:result" )
@@ -342,7 +348,7 @@ def test_from_dict():
342348
343349 di = ld_dict .from_dict ({"@context" : {"schema" : "https://schema.org/" }, "@type" : "schema:Thing" , "xmlns:name" : "fo" },
344350 context = {"xmlns" : "http://xmlns.com/foaf/0.1/" })
345- assert di ["http://xmlns.com/foaf/0.1/name" ] == di ["xmlns:name" ] == "fo"
351+ assert di ["http://xmlns.com/foaf/0.1/name" ] == di ["xmlns:name" ] == [ "fo" ]
346352 assert di .context == [{"schema" : "https://schema.org/" }, {"xmlns" : "http://xmlns.com/foaf/0.1/" }]
347353
348354
0 commit comments