mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-07 13:44:55 +03:00
fixed unicode error in printing - added tests
This commit is contained in:
parent
4fb038a9eb
commit
8edd58492e
98
spacy/tests/print/test_print.py
Normal file
98
spacy/tests/print/test_print.py
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_doc(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the coffee store')
|
||||||
|
print(doc)
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_repr_doc(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the coffee store')
|
||||||
|
print(repr(doc))
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_doc_unicode(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the café')
|
||||||
|
print(doc)
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_repr_doc_unicode(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the café')
|
||||||
|
print(repr(doc))
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_span(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the coffee store')[-3:]
|
||||||
|
print(doc)
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_repr_span(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the coffee store')[-3:]
|
||||||
|
print(repr(doc))
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_span_unicode(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the café')[-3:]
|
||||||
|
print(doc)
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_repr_span_unicode(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the café')[-3:]
|
||||||
|
print(repr(doc))
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_token(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the coffee store')[-1]
|
||||||
|
print(doc)
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_repr_token(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the coffee store')[-1]
|
||||||
|
print(repr(doc))
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_print_token_unicode(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the café')[-1]
|
||||||
|
print(doc)
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
||||||
|
|
||||||
|
|
||||||
|
def test_repr_token_unicode(EN):
|
||||||
|
try:
|
||||||
|
doc = EN(u'I sat down for coffee at the café')[-1]
|
||||||
|
print(repr(doc))
|
||||||
|
except Exception:
|
||||||
|
pytest.fail("Printing failed")
|
|
@ -118,10 +118,10 @@ cdef class Doc:
|
||||||
return u''.join([t.string for t in self])
|
return u''.join([t.string for t in self])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u''.join([t.string for t in self])
|
return u''.join([t.string for t in self]).encode('utf-8')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return u''.join([t.string for t in self])
|
return u''.join([t.string for t in self]).encode('utf-8')
|
||||||
|
|
||||||
def similarity(self, other):
|
def similarity(self, other):
|
||||||
if self.vector_norm == 0 or other.vector_norm == 0:
|
if self.vector_norm == 0 or other.vector_norm == 0:
|
||||||
|
|
|
@ -50,7 +50,7 @@ cdef class Span:
|
||||||
text = self.text_with_ws
|
text = self.text_with_ws
|
||||||
if self[-1].whitespace_:
|
if self[-1].whitespace_:
|
||||||
text = text[:-1]
|
text = text[:-1]
|
||||||
return text
|
return text.encode('utf-8')
|
||||||
|
|
||||||
def __getitem__(self, object i):
|
def __getitem__(self, object i):
|
||||||
if isinstance(i, slice):
|
if isinstance(i, slice):
|
||||||
|
|
|
@ -41,10 +41,10 @@ cdef class Token:
|
||||||
return self.string
|
return self.string
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.string
|
return self.string.encode('utf-8')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.string
|
return self.string.encode('utf-8')
|
||||||
|
|
||||||
cpdef bint check_flag(self, attr_id_t flag_id) except -1:
|
cpdef bint check_flag(self, attr_id_t flag_id) except -1:
|
||||||
return Lexeme.c_check_flag(self.c.lex, flag_id)
|
return Lexeme.c_check_flag(self.c.lex, flag_id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user