Skip to content

Commit 48ddbee

Browse files
authored
Merge pull request #1360 from bact/fix-mypy-test
Fix mypy issues in tests.extra
2 parents edffd4a + f8b5bd1 commit 48ddbee

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

tests/extra/testx_translate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
class TranslateTestCaseX(unittest.TestCase):
1616
def test_translate(self):
1717
# remove("scb_1m_th-en_spm")
18-
self.assertIsNone(download_model_all())
18+
result = download_model_all()
19+
self.assertIsNone(result)
1920
self.th_en_translator = ThEnTranslator()
2021
self.assertIsNotNone(
2122
self.th_en_translator.translate(

tests/extra/testx_translate_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_prepare_text_with_exclusions_none(self):
5757
def test_prepare_text_with_exclusions_empty_list(self):
5858
"""Test with empty exclusion list"""
5959
text = "Hello world"
60-
exclude_words = []
60+
exclude_words: list[str] = []
6161
prepared, mapping = _prepare_text_with_exclusions(
6262
text, exclude_words
6363
)
@@ -93,7 +93,7 @@ def test_restore_excluded_words_multiple(self):
9393
def test_restore_excluded_words_empty_map(self):
9494
"""Test restoring with empty mapping"""
9595
translated = "Hello world"
96-
mapping = {}
96+
mapping: dict[str, str] = {}
9797
restored = _restore_excluded_words(translated, mapping)
9898

9999
# Text should be unchanged

tests/extra/testx_ulmfit.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pickle
66
import unittest
7+
from typing import cast
78

89
import fastai
910
import pandas as pd
@@ -19,7 +20,7 @@
1920
untar_data,
2021
)
2122

22-
from pythainlp.tokenize import THAI2FIT_TOKENIZER
23+
from pythainlp.tokenize import thai2fit_tokenizer
2324
from pythainlp.ulmfit import (
2425
THWIKI_LSTM,
2526
ThaiTokenizer,
@@ -53,12 +54,14 @@ class UlmfitTestCaseX(unittest.TestCase):
5354
def test_ThaiTokenizer(self):
5455
self.thai = ThaiTokenizer()
5556
self.assertIsNotNone(self.thai.tokenizer("ทดสอบการตัดคำ"))
56-
self.assertIsNone(self.thai.add_special_cases(["แมว"]))
57+
result = self.thai.add_special_cases(["แมว"])
58+
self.assertIsNone(result)
5759

5860
def test_BaseTokenizer(self):
5961
self.base = base_tokenizer(lang="th")
6062
self.assertIsNotNone(self.base.tokenizer("ทดสอบ การ ตัด คำ"))
61-
self.assertIsNone(self.base.add_special_cases(["แมว"]))
63+
result = self.base.add_special_cases(["แมว"])
64+
self.assertIsNone(result)
6265

6366
def test_load_pretrained(self):
6467
self.assertIsNotNone(THWIKI_LSTM)
@@ -179,7 +182,7 @@ def test_process_thai_dense(self):
179182
text,
180183
pre_rules=pre_rules_th,
181184
post_rules=post_rules_th,
182-
tok_func=THAI2FIT_TOKENIZER.word_tokenize,
185+
tok_func=thai2fit_tokenizer().word_tokenize,
183186
)
184187

185188
# after pre_rules_th
@@ -225,7 +228,7 @@ def test_document_vector(self):
225228
thwiki = THWIKI_LSTM
226229
# Security note: pickle.load() executes arbitrary code if file is malicious.
227230
# These corpus files come from a trusted source with MD5 verification.
228-
with open(thwiki["itos_fname"], "rb") as f:
231+
with open(cast(str, thwiki["itos_fname"]), "rb") as f:
229232
thwiki_itos = pickle.load(f)
230233
thwiki_vocab = fastai.text.transform.Vocab(thwiki_itos)
231234
tt = Tokenizer(

0 commit comments

Comments
 (0)