From 886e5966c074039b805438e8947a1e5b0bac7da9 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Mon, 11 Mar 2019 19:03:52 +0100 Subject: [PATCH] Update test_displacy.py --- spacy/tests/test_displacy.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/spacy/tests/test_displacy.py b/spacy/tests/test_displacy.py index 24e45bfc1..6d82bbbaa 100644 --- a/spacy/tests/test_displacy.py +++ b/spacy/tests/test_displacy.py @@ -50,20 +50,6 @@ def test_displacy_spans(en_vocab): assert html.startswith("TEST") - - def test_displacy_raises_for_wrong_type(en_vocab): with pytest.raises(ValueError): displacy.render("hello world") @@ -86,3 +72,18 @@ def test_displacy_rtl(): html = displacy.render(doc, page=True, style="ent") assert "direction: rtl" in html assert 'lang="{}"'.format(nlp.lang) in html + +def test_displacy_render_wrapper(en_vocab): + """Test that displaCy accepts custom rendering wrapper.""" + + def wrapper(html): + return "TEST" + html + "TEST" + + displacy.set_render_wrapper(wrapper) + doc = get_doc(en_vocab, words=["But", "Google", "is", "starting", "from", "behind"]) + doc.ents = [Span(doc, 1, 2, label=doc.vocab.strings["ORG"])] + html = displacy.render(doc, style="ent") + assert html.startswith("TESTTEST") + # Restore + displacy.set_render_wrapper(lambda html: html) \ No newline at end of file