mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-31 07:57:35 +03:00 
			
		
		
		
	Update test_displacy.py
This commit is contained in:
		
							parent
							
								
									4bd2688eac
								
							
						
					
					
						commit
						886e5966c0
					
				|  | @ -50,20 +50,6 @@ def test_displacy_spans(en_vocab): | ||||||
|     assert html.startswith("<div") |     assert html.startswith("<div") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 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("TEST<div") |  | ||||||
|     assert html.endswith("/div>TEST") |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def test_displacy_raises_for_wrong_type(en_vocab): | def test_displacy_raises_for_wrong_type(en_vocab): | ||||||
|     with pytest.raises(ValueError): |     with pytest.raises(ValueError): | ||||||
|         displacy.render("hello world") |         displacy.render("hello world") | ||||||
|  | @ -86,3 +72,18 @@ def test_displacy_rtl(): | ||||||
|     html = displacy.render(doc, page=True, style="ent") |     html = displacy.render(doc, page=True, style="ent") | ||||||
|     assert "direction: rtl" in html |     assert "direction: rtl" in html | ||||||
|     assert 'lang="{}"'.format(nlp.lang) 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("TEST<div") | ||||||
|  |     assert html.endswith("/div>TEST") | ||||||
|  |      # Restore | ||||||
|  |     displacy.set_render_wrapper(lambda html: html) | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user