def test_deserialize_span_groups_compat(
    en_tokenizer, spans_bytes, doc_text, expected_spangroups, expected_warning
):
    """Test backwards-compatibility of `SpanGroups` deserialization.
    This uses serializations (bytes) from a prior version of spaCy (before 3.3.1).

    spans_bytes (bytes): Serialized `SpanGroups` object.
    doc_text (str): Doc text.
    expected_spangroups (dict):
        Dict mapping every expected (after deserialization) `SpanGroups` key
        to a SpanGroup's "args", where a SpanGroup's args are given as a dict:
          {"name": span_group.name,
           "spans": [(span0.start, span0.end), ...]}
    expected_warning (bool): Whether a warning is to be expected from .from_bytes()
        --i.e. if more than 1 SpanGroup has the same .name within the `SpanGroups`.
    """
    doc = en_tokenizer(doc_text)

    if expected_warning:
        with pytest.warns(UserWarning):
            doc.spans.from_bytes(spans_bytes)
    else:
        # TODO: explicitly check for lack of a warning
        doc.spans.from_bytes(spans_bytes)

    assert doc.spans.keys() == expected_spangroups.keys()
    for name, spangroup_args in expected_spangroups.items():
        assert doc.spans[name].name == spangroup_args["name"]
        spans = [Span(doc, start, end) for start, end in spangroup_args["spans"]]
        assert list(doc.spans[name]) == spans
Test backwards-compatibility of `SpanGroups` deserialization.
    This uses serializations (bytes) from a prior version of spaCy (before 3.3.1).

    spans_bytes (bytes): Serialized `SpanGroups` object.
    doc_text (str): Doc text.
    expected_spangroups (dict):
        Dict mapping every expected (after deserialization) `SpanGroups` key
        to a SpanGroup's "args", where a SpanGroup's args are given as a dict:
          {"name": span_group.name,
           "spans": [(span0.start, span0.end), ...]}
    expected_warning (bool): Whether a warning is to be expected from .from_bytes()
        --i.e. if more than 1 SpanGroup has the same .name within the `SpanGroups`.
    
spacy/tests/serialize/test_serialize_span_groups.py