Add test for #1757: Comparison against None

This commit is contained in:
Matthew Honnibal 2018-01-15 15:54:25 +01:00
parent b904d81e9a
commit 4b09616b58
2 changed files with 23 additions and 0 deletions

View File

@ -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

View File

@ -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