From e99b3f5322906b7f086d58478401f5a859fe0705 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 23 Oct 2016 16:30:22 +0200 Subject: [PATCH] Test Issue #459: Fail to deserialize empty doc --- spacy/tests/serialize/test_serialization.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spacy/tests/serialize/test_serialization.py b/spacy/tests/serialize/test_serialization.py index 6861fedc8..a150b8cf3 100644 --- a/spacy/tests/serialize/test_serialization.py +++ b/spacy/tests/serialize/test_serialization.py @@ -2,6 +2,9 @@ from __future__ import unicode_literals import pytest from spacy.tokens import Doc +import spacy.en +from spacy.serialize.packer import Packer + def equal(doc1, doc2): # tokens @@ -84,3 +87,13 @@ def test_serialize_tokens_tags_parse_ner(EN): doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes()) equal(doc1, doc2) + + +def test_serialize_empty_doc(): + vocab = spacy.en.English.Defaults.create_vocab() + doc = Doc(vocab) + packer = Packer(vocab, {}) + b = packer.pack(doc) + assert b == b'' + loaded = Doc(vocab).from_bytes(b) + assert len(loaded) == 0