Skip to content

Commit fcac8e2

Browse files
committed
Added unit test to test Token comparisons
1 parent 699a2d8 commit fcac8e2

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

rasa/nlu/tokenizers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def get(self, prop, default=None):
2121

2222
def __eq__(self, other):
2323
if not isinstance(other, Token):
24-
return NotImplemented
24+
raise NotImplementedError
2525
return self.text == other.text
2626

2727
def __lt__(self, other):
2828
if not isinstance(other, Token):
29-
return NotImplemented
29+
raise NotImplementedError
3030
return self.text < other.text

tests/nlu/base/test_tokenizers.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
from unittest.mock import patch
2+
3+
import pytest
4+
5+
from rasa.nlu import training_data
26
from rasa.nlu.training_data import TrainingData, Message
37
from tests.nlu import utilities
4-
from rasa.nlu import training_data
8+
9+
10+
def test_tokens_comparison():
11+
from rasa.nlu.tokenizers import Token
12+
13+
x = Token("hello", 0)
14+
y = Token("Hello", 0)
15+
16+
assert x == x
17+
assert y < x
18+
19+
with pytest.raises(NotImplementedError):
20+
assert x == 1
21+
22+
with pytest.raises(NotImplementedError):
23+
assert y < "a"
524

625

726
def test_whitespace():

0 commit comments

Comments
 (0)