Skip to content

Commit 4080091

Browse files
author
notactuallyfinn
committed
json_ids are now returned as ld_dicts instead of the id string
1 parent aa4284e commit 4080091

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/hermes/model/types/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
(lambda c: isinstance(c, list), {"ld_container": lambda c, **kw: ld_list(c, **kw)}),
3131

3232
# pythonize items from lists (expanded set is already handled above)
33-
(ld_container.is_json_id, {"python": lambda c, **_: c["@id"]}),
3433
(ld_container.is_typed_json_value, {"python": lambda c, **kw: ld_container.typed_ld_to_py([c], **kw)}),
3534
(ld_container.is_json_value, {"python": lambda c, **_: c["@value"]}),
3635
(ld_list.is_container, {"ld_container": lambda c, **kw: ld_list([c], **kw)}),

src/hermes/model/types/ld_dict.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,4 @@ def is_json_dict(cls, ld_value):
149149
if any(k in ld_value for k in ["@set", "@graph", "@list", "@value"]):
150150
return False
151151

152-
if ['@id'] == [*ld_value.keys()]:
153-
return False
154-
155152
return True

test/hermes_test/model/types/test_ld_container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_to_python_id_value(self, mock_context):
107107
assert cont._to_python("http://spam.eggs/ham",
108108
[{"@id": "http://spam.eggs/spam"}]) == [{"@id": "http://spam.eggs/spam"}]
109109
assert cont._to_python("http://spam.eggs/ham",
110-
{"@id": "http://spam.eggs/identifier"}) == "http://spam.eggs/identifier"
110+
{"@id": "http://spam.eggs/identifier"}) == {"@id": "http://spam.eggs/identifier"}
111111

112112
def test_to_python_basic_value(self, mock_context):
113113
cont = ld_container([{}], context=[mock_context])

test/hermes_test/model/types/test_ld_dict.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ def test_to_python():
299299
inner_di = ld_dict([{}], parent=di)
300300
inner_di.update({"xmlns:foobar": "bar", "http://xmlns.com/foaf/0.1/barfoo": {"@id": "foo"}})
301301
di.update({"http://xmlns.com/foaf/0.1/name": "foo", "xmlns:homepage": {"@id": "bar"}, "xmlns:foo": inner_di})
302-
assert di.to_python() == {"xmlns:name": ["foo"], "xmlns:homepage": ["bar"],
303-
"xmlns:foo": [{"xmlns:foobar": ["bar"], "xmlns:barfoo": ["foo"]}]}
302+
assert di.to_python() == {"xmlns:name": ["foo"], "xmlns:homepage": [{"@id": "bar"}],
303+
"xmlns:foo": [{"xmlns:foobar": ["bar"], "xmlns:barfoo": [{"@id": "foo"}]}]}
304304
di.update({"http://spam.eggs/eggs": {
305305
"@value": "2022-02-22T00:00:00", "@type": "https://schema.org/DateTime"
306306
}})
307-
assert di.to_python() == {"xmlns:name": ["foo"], "xmlns:homepage": ["bar"],
308-
"xmlns:foo": [{"xmlns:foobar": ["bar"], "xmlns:barfoo": ["foo"]}],
307+
assert di.to_python() == {"xmlns:name": ["foo"], "xmlns:homepage": [{"@id": "bar"}],
308+
"xmlns:foo": [{"xmlns:foobar": ["bar"], "xmlns:barfoo": [{"@id": "foo"}]}],
309309
"http://spam.eggs/eggs": ["2022-02-22T00:00:00"]}
310310

311311

@@ -376,13 +376,16 @@ def test_from_dict():
376376

377377
def test_is_ld_dict():
378378
assert not any(ld_dict.is_ld_dict(item) for item in [{}, {"foo": "bar"}, {"@id": "foo"}])
379-
assert not any(ld_dict.is_ld_dict(item) for item in [[{"@id": "foo"}], [{"@set": "foo"}], [{}, {}], [], [""]])
380-
assert all(ld_dict.is_ld_dict([item]) for item in [{"@id": "foo", "foobar": "bar"}, {"foo": "bar"}])
379+
assert not any(ld_dict.is_ld_dict(item) for item in [[{"@set": "foo"}], [{}, {}], [], [""]])
380+
assert all(
381+
ld_dict.is_ld_dict([item])
382+
for item in [{"@id": "foo"}, {"@id": "foo", "foobar": "bar"}, {"foo": "bar"}]
383+
)
381384

382385

383386
def test_is_json_dict():
384387
assert not any(ld_dict.is_json_dict(item) for item in [1, "", [], {""}, ld_dict([{}])])
385388
assert not any(ld_dict.is_json_dict({key: [], "foo": "bar"}) for key in ["@set", "@graph", "@list", "@value"])
386-
assert not ld_dict.is_json_dict({"@id": "foo"})
389+
assert ld_dict.is_json_dict({"@id": "foo"})
387390
assert ld_dict.is_json_dict({"@id": "foo", "foobar": "bar"})
388391
assert ld_dict.is_json_dict({"foo": "bar"})

0 commit comments

Comments
 (0)