MCPcopy
hub / github.com/explosion/spaCy / test_issue4528

Function test_issue4528

spacy/tests/serialize/test_serialize_docbin.py:18–30  ·  view source on GitHub ↗

Test that user_data is correctly serialized in DocBin.

(en_vocab)

Source from the content-addressed store, hash-verified

16
17@pytest.mark.issue(4528)
18def test_issue4528(en_vocab):
19 """Test that user_data is correctly serialized in DocBin."""
20 doc = Doc(en_vocab, words=["hello", "world"])
21 doc.user_data["foo"] = "bar"
22 # This is how extension attribute values are stored in the user data
23 doc.user_data[("._.", "foo", None, None)] = "bar"
24 doc_bin = DocBin(store_user_data=True)
25 doc_bin.add(doc)
26 doc_bin_bytes = doc_bin.to_bytes()
27 new_doc_bin = DocBin(store_user_data=True).from_bytes(doc_bin_bytes)
28 new_doc = list(new_doc_bin.get_docs(en_vocab))[0]
29 assert new_doc.user_data["foo"] == "bar"
30 assert new_doc.user_data[("._.", "foo", None, None)] == "bar"
31
32
33@pytest.mark.issue(5141)

Callers

nothing calls this directly

Calls 5

addMethod · 0.95
to_bytesMethod · 0.95
DocBinClass · 0.90
get_docsMethod · 0.80
from_bytesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…