2017-06-02 19:37:19 +03:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from ..util import make_tempdir
|
2017-06-02 19:40:06 +03:00
|
|
|
from ...pipeline import NeuralDependencyParser as DependencyParser
|
|
|
|
from ...pipeline import NeuralEntityRecognizer as EntityRecognizer
|
2017-06-02 19:37:19 +03:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2017-06-02 19:40:06 +03:00
|
|
|
test_parsers = [DependencyParser, EntityRecognizer]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('Parser', test_parsers)
|
|
|
|
def test_serialize_parser_roundtrip_bytes(en_vocab, Parser):
|
2017-06-02 19:37:19 +03:00
|
|
|
parser = Parser(en_vocab)
|
2017-06-02 22:42:26 +03:00
|
|
|
parser.model, _ = parser.Model(10)
|
2017-06-02 19:37:19 +03:00
|
|
|
new_parser = Parser(en_vocab)
|
2017-06-02 22:42:26 +03:00
|
|
|
new_parser.model, _ = new_parser.Model(10)
|
|
|
|
new_parser = new_parser.from_bytes(parser.to_bytes())
|
|
|
|
assert new_parser.to_bytes() == parser.to_bytes()
|
2017-06-02 19:37:19 +03:00
|
|
|
|
|
|
|
|
2017-06-02 19:40:06 +03:00
|
|
|
@pytest.mark.parametrize('Parser', test_parsers)
|
|
|
|
def test_serialize_parser_roundtrip_disk(en_vocab, Parser):
|
2017-06-02 19:37:19 +03:00
|
|
|
parser = Parser(en_vocab)
|
|
|
|
parser.model, _ = parser.Model(0)
|
|
|
|
with make_tempdir() as d:
|
|
|
|
file_path = d / 'parser'
|
|
|
|
parser.to_disk(file_path)
|
|
|
|
parser_d = Parser(en_vocab)
|
|
|
|
parser_d.model, _ = parser_d.Model(0)
|
|
|
|
parser_d = parser_d.from_disk(file_path)
|
2017-06-02 22:42:26 +03:00
|
|
|
assert parser.to_bytes(model=False) == parser_d.to_bytes(model=False)
|