mirror of https://github.com/explosion/spaCy.git
Add test for #1757: Comparison against None
This commit is contained in:
parent
b904d81e9a
commit
4b09616b58
|
@ -40,6 +40,11 @@ cdef class Lexeme:
|
|||
assert self.c.orth == orth
|
||||
|
||||
def __richcmp__(self, other, int op):
|
||||
if other is None:
|
||||
if op == 0 or op == 1 or op == 2:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
if isinstance(other, Lexeme):
|
||||
a = self.orth
|
||||
b = other.orth
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
'''Test comparison against None doesn't cause segfault'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from ...tokens import Doc
|
||||
from ...vocab import Vocab
|
||||
|
||||
def test_issue1757():
|
||||
doc = Doc(Vocab(), words=['a', 'b', 'c'])
|
||||
assert not doc[0] < None
|
||||
assert not doc[0] == None
|
||||
assert doc[0] >= None
|
||||
span = doc[:2]
|
||||
assert not span < None
|
||||
assert not span == None
|
||||
assert span >= None
|
||||
lex = vocab['a']
|
||||
assert not lex == None
|
||||
assert not lex < None
|
Loading…
Reference in New Issue