Skip to content

Commit becced0

Browse files
committed
Move extras to testx
1 parent 0d3540c commit becced0

15 files changed

+88
-62
lines changed

pythainlp/spell/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"correct",
1212
"correct_sent",
1313
"spell",
14-
"spell_sent",
14+
"SENT_TOKS",
1515
]
1616

1717
from pythainlp.spell.pn import NorvigSpellChecker
1818

1919
DEFAULT_SPELL_CHECKER = NorvigSpellChecker()
2020

2121
# these imports are placed here to avoid circular imports
22-
from pythainlp.spell.core import correct, correct_sent, spell, spell_sent
22+
from pythainlp.spell.core import correct, correct_sent, spell, SENT_TOKS

pythainlp/spell/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def correct(word: str, engine: str = "pn") -> str:
129129
return text_correct
130130

131131

132-
def spell_sent(list_words: List[str], engine: str = "pn") -> List[List[str]]:
132+
def SENT_TOKS(list_words: List[str], engine: str = "pn") -> List[List[str]]:
133133
"""
134134
Provides a list of possible correct spellings of sentence
135135
@@ -188,4 +188,4 @@ def correct_sent(list_words: List[str], engine: str = "pn") -> List[str]:
188188
correct_sent(["เด็","อินอร์เน็ต","แรง"],engine='symspellpy')
189189
# output: ['เด็ก', 'อินเทอร์เน็ต', 'แรง']
190190
"""
191-
return spell_sent(list_words, engine=engine)[0]
191+
return SENT_TOKS(list_words, engine=engine)[0]

tests/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111
from unittest import TestLoader, TestSuite, TextTestRunner
1212

1313

14-
def load_tests(loader: TestLoader, tests, pattern) -> TestSuite:
14+
test_packages = [
15+
"tests.test_spell.TestSpellPackage",
16+
"tests.test_tokenize.TestTokenizePackage",
17+
"tests.test_util.TestUtilPackage",
18+
]
19+
20+
def load_tests(loader: TestLoader, tests, pattern: str) -> TestSuite:
21+
"""A function to load tests."""
1522
suite = TestSuite()
16-
tests = loader.loadTestsFromName("tests.test_util.TestUtilPackage")
17-
suite.addTests(tests)
18-
tests = loader.loadTestsFromName("tests.test_tokenize.TestTokenizePackage")
19-
suite.addTests(tests)
23+
for test_package in test_packages:
24+
tests = loader.loadTestsFromName(test_package)
25+
suite.addTests(tests)
2026
return suite

tests/test_spell.py

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
correct_sent,
1111
spell,
1212
spell_sent,
13-
symspellpy,
1413
)
1514

15+
SENT_TOKS = ["เด็", "อินอร์เน็ต", "แรง"]
1616

1717
class TestSpellPackage(unittest.TestCase):
1818
def test_spell(self):
@@ -27,30 +27,6 @@ def test_spell(self):
2727
self.assertIsInstance(result, list)
2828
self.assertGreater(len(result), 0)
2929

30-
result = spell("เน้ร", engine="phunspell")
31-
self.assertIsInstance(result, list)
32-
self.assertGreater(len(result), 0)
33-
34-
result = spell("เกสมร์", engine="phunspell")
35-
self.assertIsInstance(result, list)
36-
self.assertGreater(len(result), 0)
37-
38-
result = spell("เน้ร", engine="symspellpy")
39-
self.assertIsInstance(result, list)
40-
self.assertGreater(len(result), 0)
41-
42-
result = spell("เกสมร์", engine="symspellpy")
43-
self.assertIsInstance(result, list)
44-
self.assertGreater(len(result), 0)
45-
46-
result = spell("เน้ร", engine="tltk")
47-
self.assertIsInstance(result, list)
48-
self.assertGreater(len(result), 0)
49-
50-
result = spell("เดก", engine="tltk")
51-
self.assertIsInstance(result, list)
52-
self.assertGreater(len(result), 0)
53-
5430
def test_word_correct(self):
5531
self.assertEqual(correct(None), "")
5632
self.assertEqual(correct(""), "")
@@ -63,18 +39,6 @@ def test_word_correct(self):
6339
self.assertIsInstance(result, str)
6440
self.assertNotEqual(result, "")
6541

66-
result = correct("ทดสอง", engine="phunspell")
67-
self.assertIsInstance(result, str)
68-
self.assertNotEqual(result, "")
69-
70-
result = correct("ทดสอง", engine="symspellpy")
71-
self.assertIsInstance(result, str)
72-
self.assertNotEqual(result, "")
73-
74-
result = correct("ทดสอง", engine="wanchanberta_thai_grammarly")
75-
self.assertIsInstance(result, str)
76-
self.assertNotEqual(result, "")
77-
7842
def test_norvig_spell_checker(self):
7943
checker = NorvigSpellChecker(dict_filter=None)
8044
self.assertTrue(len(checker.dictionary()) > 0)
@@ -124,21 +88,10 @@ def test_norvig_spell_checker(self):
12488
checker = NorvigSpellChecker(custom_dict=user_dict)
12589

12690
def test_spell_sent(self):
127-
self.spell_sent = ["เด็", "อินอร์เน็ต", "แรง"]
128-
self.assertIsNotNone(spell_sent(self.spell_sent))
129-
self.assertIsNotNone(spell_sent(self.spell_sent, engine="pn"))
130-
self.assertIsNotNone(spell_sent(self.spell_sent, engine="phunspell"))
131-
self.assertIsNotNone(spell_sent(self.spell_sent, engine="symspellpy"))
91+
self.assertIsNotNone(spell_sent(SENT_TOKS))
92+
self.assertIsNotNone(spell_sent(SENT_TOKS, engine="pn"))
13293

13394
def test_correct_sent(self):
134-
self.spell_sent = ["เด็", "อินอร์เน็ต", "แรง"]
135-
self.assertIsNotNone(correct_sent(self.spell_sent))
136-
self.assertIsNotNone(correct_sent(self.spell_sent, engine="pn"))
137-
self.assertIsNotNone(correct_sent(self.spell_sent, engine="phunspell"))
138-
self.assertIsNotNone(
139-
correct_sent(self.spell_sent, engine="symspellpy")
140-
)
141-
self.assertIsNotNone(
142-
correct_sent(self.spell_sent, engine="wanchanberta_thai_grammarly")
143-
)
144-
self.assertIsNotNone(symspellpy.correct_sent(self.spell_sent))
95+
self.assertIsNotNone(correct_sent(SENT_TOKS))
96+
self.assertIsNotNone(correct_sent(SENT_TOKS, engine="pn"))
97+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/testx_spell.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- coding: utf-8 -*-
2+
# SPDX-FileCopyrightText: 2016-2024 PyThaiNLP Project
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import unittest
6+
7+
from pythainlp.spell import (
8+
correct,
9+
correct_sent,
10+
spell,
11+
spell_sent,
12+
symspellpy,
13+
)
14+
15+
SENT_TOKS = ["เด็", "อินอร์เน็ต", "แรง"]
16+
17+
18+
class TestSpellPackage(unittest.TestCase):
19+
def test_spell(self):
20+
result = spell("เน้ร", engine="phunspell")
21+
self.assertIsInstance(result, list)
22+
self.assertGreater(len(result), 0)
23+
24+
result = spell("เกสมร์", engine="phunspell")
25+
self.assertIsInstance(result, list)
26+
self.assertGreater(len(result), 0)
27+
28+
result = spell("เน้ร", engine="symspellpy")
29+
self.assertIsInstance(result, list)
30+
self.assertGreater(len(result), 0)
31+
32+
result = spell("เกสมร์", engine="symspellpy")
33+
self.assertIsInstance(result, list)
34+
self.assertGreater(len(result), 0)
35+
36+
result = spell("เน้ร", engine="tltk")
37+
self.assertIsInstance(result, list)
38+
self.assertGreater(len(result), 0)
39+
40+
result = spell("เดก", engine="tltk")
41+
self.assertIsInstance(result, list)
42+
self.assertGreater(len(result), 0)
43+
44+
def test_word_correct(self):
45+
result = correct("ทดสอง", engine="phunspell")
46+
self.assertIsInstance(result, str)
47+
self.assertNotEqual(result, "")
48+
49+
result = correct("ทดสอง", engine="symspellpy")
50+
self.assertIsInstance(result, str)
51+
self.assertNotEqual(result, "")
52+
53+
result = correct("ทดสอง", engine="wanchanberta_thai_grammarly")
54+
self.assertIsInstance(result, str)
55+
self.assertNotEqual(result, "")
56+
57+
def test_spell_sent(self):
58+
self.assertIsNotNone(spell_sent(SENT_TOKS, engine="phunspell"))
59+
self.assertIsNotNone(spell_sent(SENT_TOKS, engine="symspellpy"))
60+
61+
def test_correct_sent(self):
62+
self.assertIsNotNone(correct_sent(SENT_TOKS, engine="phunspell"))
63+
self.assertIsNotNone(correct_sent(SENT_TOKS, engine="symspellpy"))
64+
self.assertIsNotNone(
65+
correct_sent(SENT_TOKS, engine="wanchanberta_thai_grammarly")
66+
)
67+
self.assertIsNotNone(symspellpy.correct_sent(SENT_TOKS))
File renamed without changes.

0 commit comments

Comments
 (0)