-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_detector_context.py
More file actions
51 lines (44 loc) · 1.65 KB
/
test_detector_context.py
File metadata and controls
51 lines (44 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Tests for DetectorContext."""
from unittest.mock import MagicMock
import pytest
from myspellchecker.core.detectors.context import DetectorContext
from myspellchecker.core.detectors.tokenized_text import TokenizedText
class TestDetectorContext:
def test_construction(self):
tokenized = TokenizedText.from_text("test text")
ctx = DetectorContext(
provider=MagicMock(),
segmenter=MagicMock(),
symspell=None,
semantic_checker=None,
config=MagicMock(),
tokenized=tokenized,
)
assert ctx.provider is not None
assert ctx.symspell is None
assert ctx.semantic_checker is None
assert len(ctx.tokenized) == 2
def test_frozen(self):
tokenized = TokenizedText.from_text("test")
ctx = DetectorContext(
provider=MagicMock(),
segmenter=MagicMock(),
symspell=None,
semantic_checker=None,
config=MagicMock(),
tokenized=tokenized,
)
with pytest.raises(AttributeError):
ctx.provider = MagicMock() # type: ignore[misc]
def test_tokenized_access(self):
tokenized = TokenizedText.from_text("ကျွန်တော် စာဖတ်တယ်")
ctx = DetectorContext(
provider=MagicMock(),
segmenter=MagicMock(),
symspell=MagicMock(),
semantic_checker=MagicMock(),
config=MagicMock(),
tokenized=tokenized,
)
assert ctx.tokenized.tokens == ["ကျွန်တော်", "စာဖတ်တယ်"]
assert ctx.tokenized[0].position == 0