Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pythainlp/spell/wanchanberta_thai_grammarly.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ def align_word_ids(texts: str) -> list[int]:
if word_idx is None:
label_ids.append(-100)
else:
try:
label_ids.append(2)
except Exception:
label_ids.append(-100)
label_ids.append(2)

return label_ids

Expand Down
3 changes: 3 additions & 0 deletions tests/noauto_onnx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

# Names of module to be tested
test_packages: list[str] = [
"tests.noauto_onnx.testn_spell_onnx",
"tests.noauto_onnx.testn_tag_onnx",
"tests.noauto_onnx.testn_tokenize_onnx",
"tests.noauto_onnx.testn_transliterate_onnx",
]


Expand Down
41 changes: 41 additions & 0 deletions tests/noauto_onnx/testn_spell_onnx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0

# Tests for spell correction functions that require ONNX Runtime
# These tests are NOT run in automated CI workflows due to:
# - Large dependencies (onnxruntime)
# - Platform-specific compatibility issues
# - Version constraints

import unittest


class SpellONNXTestCaseN(unittest.TestCase):
"""Tests for ONNX-based spell correction (requires onnxruntime)"""

def test_words_spelling_correction_returns_list(self):
from pythainlp.spell.words_spelling_correction import (
get_words_spell_suggestion,
)

result = get_words_spell_suggestion("สวัสดี")
self.assertIsInstance(result, list)

def test_words_spelling_correction_nonempty_input(self):
from pythainlp.spell.words_spelling_correction import (
get_words_spell_suggestion,
)

result = get_words_spell_suggestion("กาารเขียน")
self.assertIsInstance(result, list)
self.assertGreater(len(result), 0)

def test_words_spelling_correction_items_are_strings(self):
from pythainlp.spell.words_spelling_correction import (
get_words_spell_suggestion,
)

result = get_words_spell_suggestion("กาารเขียน")
for item in result:
self.assertIsInstance(item, str)
53 changes: 53 additions & 0 deletions tests/noauto_onnx/testn_tag_onnx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0

# Tests for POS tagging functions that require ONNX Runtime
# These tests are NOT run in automated CI workflows due to:
# - Large dependencies (onnxruntime)
# - Platform-specific compatibility issues
# - Version constraints

import unittest


class TagONNXTestCaseN(unittest.TestCase):
"""Tests for ONNX-based POS tagging (requires onnxruntime)"""

def test_pos_tag_wangchanberta_onnx_returns_list(self):
from pythainlp.tag import pos_tag

result = pos_tag(
["แมว", "กิน", "ปลา"],
engine="wangchanberta_onnx",
)
self.assertIsInstance(result, list)
self.assertGreater(len(result), 0)

def test_pos_tag_wangchanberta_onnx_length_matches(self):
from pythainlp.tag import pos_tag

tokens = ["แมว", "กิน", "ปลา"]
result = pos_tag(tokens, engine="wangchanberta_onnx")
self.assertEqual(len(result), len(tokens))

def test_pos_tag_wangchanberta_onnx_tuple_pairs(self):
from pythainlp.tag import pos_tag

result = pos_tag(
["แมว", "กิน", "ปลา"],
engine="wangchanberta_onnx",
)
for item in result:
self.assertIsInstance(item, tuple)
self.assertEqual(len(item), 2)
word, tag = item
self.assertIsInstance(word, str)
self.assertIsInstance(tag, str)

def test_pos_tag_wangchanberta_onnx_empty_list(self):
from pythainlp.tag import pos_tag

result = pos_tag([], engine="wangchanberta_onnx")
self.assertIsInstance(result, list)
self.assertEqual(len(result), 0)
37 changes: 0 additions & 37 deletions tests/noauto_onnx/testn_tokenize_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,40 +79,3 @@ def test_sefr_cut(self):
sefr_cut.segment("ฉันรักภาษาไทยเพราะฉันเป็นคนไทย", engine="tnhc"),
)


class TransliterateONNXTestCaseN(unittest.TestCase):
"""Tests for ONNX-based transliteration (requires onnxruntime)"""

def test_thai2rom_onnx(self):
from pythainlp.transliterate.thai2rom_onnx import romanize

result = romanize("สวัสดี")
self.assertIsInstance(result, str)
self.assertGreater(len(result), 0)


class TagONNXTestCaseN(unittest.TestCase):
"""Tests for ONNX-based POS tagging (requires onnxruntime)"""

def test_pos_tag_wangchanberta_onnx(self):
from pythainlp.tag import pos_tag

result = pos_tag(
["แมว", "กิน", "ปลา"],
engine="wangchanberta_onnx"
)
self.assertIsInstance(result, list)
self.assertGreater(len(result), 0)
self.assertEqual(len(result), 3)


class SpellONNXTestCaseN(unittest.TestCase):
"""Tests for ONNX-based spell correction (requires onnxruntime)"""

def test_words_spelling_correction(self):
from pythainlp.spell.words_spelling_correction import (
get_words_spell_suggestion,
)

result = get_words_spell_suggestion("สวัสดี")
self.assertIsInstance(result, list)
41 changes: 41 additions & 0 deletions tests/noauto_onnx/testn_transliterate_onnx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0

# Tests for transliteration functions that require ONNX Runtime
# These tests are NOT run in automated CI workflows due to:
# - Large dependencies (onnxruntime)
# - Platform-specific compatibility issues
# - Version constraints

import unittest


class TransliterateONNXTestCaseN(unittest.TestCase):
"""Tests for ONNX-based transliteration (requires onnxruntime)"""

def test_thai2rom_onnx_returns_string(self):
from pythainlp.transliterate.thai2rom_onnx import romanize

result = romanize("สวัสดี")
self.assertIsInstance(result, str)
self.assertGreater(len(result), 0)

def test_thai2rom_onnx_empty_string(self):
from pythainlp.transliterate.thai2rom_onnx import romanize

result = romanize("")
self.assertIsInstance(result, str)

def test_thai2rom_onnx_ascii_passthrough(self):
from pythainlp.transliterate.thai2rom_onnx import romanize

result = romanize("hello")
self.assertIsInstance(result, str)

def test_thai2rom_onnx_mixed_text(self):
from pythainlp.transliterate.thai2rom_onnx import romanize

result = romanize("ภาษาไทย")
self.assertIsInstance(result, str)
self.assertGreater(len(result), 0)
4 changes: 4 additions & 0 deletions tests/noauto_torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@

# Names of module to be tested
test_packages: list[str] = [
"tests.noauto_torch.testn_augment_torch",
"tests.noauto_torch.testn_lm_torch",
"tests.noauto_torch.testn_parse_torch",
"tests.noauto_torch.testn_spell_torch",
"tests.noauto_torch.testn_summarize_torch",
"tests.noauto_torch.testn_tag_torch",
"tests.noauto_torch.testn_tokenize_torch",
"tests.noauto_torch.testn_transliterate_torch",
]


Expand Down
75 changes: 75 additions & 0 deletions tests/noauto_torch/testn_augment_torch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0

# Tests for augmentation functions that require transformers
# These tests are NOT run in automated CI workflows due to:
# - Large dependencies (torch, transformers)
# - Python 3.13+ compatibility issues

import unittest


class AugmentTestCaseN(unittest.TestCase):
"""Tests for augmentation functions (requires transformers)"""

def test_augment_wangchanberta_returns_list(self):
from pythainlp.augment.lm import Thai2transformersAug

augmenter = Thai2transformersAug()
result = augmenter.augment("แมวกิน<mask>")
self.assertIsInstance(result, list)
self.assertGreater(len(result), 0)

def test_augment_wangchanberta_items_are_strings(self):
from pythainlp.augment.lm import Thai2transformersAug

augmenter = Thai2transformersAug()
result = augmenter.augment("แมวกิน<mask>")
for item in result:
self.assertIsInstance(item, str)

def test_augment_wangchanberta_generate_returns_list(self):
from pythainlp.augment.lm import Thai2transformersAug

augmenter = Thai2transformersAug()
result = augmenter.generate("แมวกิน<mask>", num_replace_tokens=1)
self.assertIsInstance(result, list)

def test_augment_phayathaibert_returns_list(self):
from pythainlp.augment.lm import ThaiTextAugmenter

augmenter = ThaiTextAugmenter()
result = augmenter.augment("แมวกิน<mask>")
self.assertIsInstance(result, list)
self.assertGreater(len(result), 0)

def test_augment_phayathaibert_items_are_strings(self):
from pythainlp.augment.lm import ThaiTextAugmenter

augmenter = ThaiTextAugmenter()
result = augmenter.augment("แมวกิน<mask>")
for item in result:
self.assertIsInstance(item, str)

def test_augment_phayathaibert_num_augs_respected(self):
from pythainlp.augment.lm import ThaiTextAugmenter

augmenter = ThaiTextAugmenter()
result = augmenter.augment("แมวกิน<mask>", num_augs=2)
self.assertEqual(len(result), 2)

def test_augment_phayathaibert_exceeds_limit_raises(self):
from pythainlp.augment.lm import ThaiTextAugmenter

augmenter = ThaiTextAugmenter()
with self.assertRaises(ValueError):
augmenter.augment("แมวกิน<mask>", num_augs=10)

def test_augment_phayathaibert_adds_mask_if_missing(self):
from pythainlp.augment.lm import ThaiTextAugmenter

augmenter = ThaiTextAugmenter()
result = augmenter.augment("แมวกิน", num_augs=1)
self.assertIsInstance(result, list)
self.assertEqual(len(result), 1)
34 changes: 34 additions & 0 deletions tests/noauto_torch/testn_parse_torch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0

# Tests for parsing functions that require torch and transformers
# These tests are NOT run in automated CI workflows due to:
# - Large dependencies (torch, transformers)
# - Python 3.13+ compatibility issues

import unittest


class ParseTestCaseN(unittest.TestCase):
"""Tests for parsing functions (requires torch and transformers)"""

def test_dependency_parsing_returns_list(self):
from pythainlp.parse import dependency_parsing

result = dependency_parsing("แมวกินปลา")
self.assertIsInstance(result, list)
self.assertGreater(len(result), 0)

def test_dependency_parsing_result_structure(self):
from pythainlp.parse import dependency_parsing

result = dependency_parsing("แมวกินปลา")
for item in result:
self.assertIsInstance(item, dict)

def test_dependency_parsing_empty_string(self):
from pythainlp.parse import dependency_parsing

result = dependency_parsing("")
self.assertIsInstance(result, list)
47 changes: 47 additions & 0 deletions tests/noauto_torch/testn_summarize_torch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0

# Tests for summarization functions that require transformers
# These tests are NOT run in automated CI workflows due to:
# - Large dependencies (torch, transformers)
# - Python 3.13+ compatibility issues

import unittest


class SummarizeTestCaseN(unittest.TestCase):
"""Tests for summarization functions (requires transformers)"""

def test_summarize_keybert_returns_list(self):
from pythainlp.summarize.keybert import KeyBERT

text = "แมวเป็นสัตว์เลี้ยงที่น่ารัก แมวชอบกินปลา แมวชอบนอนหลับ"
keybert = KeyBERT()
result = keybert.extract_keywords(text, max_keywords=2)
self.assertIsInstance(result, list)

def test_summarize_keybert_max_keywords_respected(self):
from pythainlp.summarize.keybert import KeyBERT

text = "แมวเป็นสัตว์เลี้ยงที่น่ารัก แมวชอบกินปลา แมวชอบนอนหลับ"
keybert = KeyBERT()
result = keybert.extract_keywords(text, max_keywords=2)
self.assertLessEqual(len(result), 2)

def test_summarize_mt5_returns_list(self):
from pythainlp.summarize.mt5 import mT5Summarizer

text = "แมวเป็นสัตว์เลี้ยงที่น่ารัก แมวชอบกินปลา แมวชอบนอนหลับ"
summarizer = mT5Summarizer()
result = summarizer.summarize(text)
self.assertIsInstance(result, list)

def test_summarize_mt5_result_items_are_strings(self):
from pythainlp.summarize.mt5 import mT5Summarizer

text = "แมวเป็นสัตว์เลี้ยงที่น่ารัก แมวชอบกินปลา แมวชอบนอนหลับ"
summarizer = mT5Summarizer()
result = summarizer.summarize(text)
for item in result:
self.assertIsInstance(item, str)
Loading
Loading