Skip to content

Move tltk tests from noauto to extra tier - #1253

Merged
bact merged 16 commits into
devfrom
copilot/increase-test-coverage
Feb 1, 2026
Merged

Move tltk tests from noauto to extra tier#1253
bact merged 16 commits into
devfrom
copilot/increase-test-coverage

Conversation

Copilot AI commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

What do these changes do

Moves tltk test cases from noauto to extra tier. tltk v1.10 installs cleanly as pure Python wheel without Cython compilation.

What was wrong

tltk tests were in noauto due to historical compilation issues. Testing confirmed v1.10 no longer requires compilation and works correctly on Python 3.12.3 with dependencies (gensim, nltk, scikit-learn, sklearn-crfsuite, pandas).

How this fixes it

Moved 6 test classes to extra (with X suffix per conventions):

  • Tokenization: SentTokenizeTLTKTestCaseX, SubwordTokenizeTLTKTestCaseX, SyllableTokenizeTLTKTestCaseX, WordTokenizeTLTKTestCaseX
  • Spell checking: SpellTLTKTestCaseX
  • POS tagging/NER: TagTLTKTestCaseX

Removed from noauto:

  • All 6 tltk test classes
  • tltk imports
  • "compilation issues (tltk)" comments

noauto now contains only tests with actual issues: TensorFlow (~500MB), PyTorch (~800MB), transformers (~1GB), phunspell (Cython).

Your checklist for this pull request

  • Passed code styles and structures
  • Passed code linting checks and unit test
Original prompt

Repeat the process in #1248 again, to increase the test coverage.

Identify individual test cases in tests.noauto if there is any test case that we can move safely to "core", "compact", or "extra".

Try to run each of the "noauto" test cases on ubuntu-latest with Python 3.13:

  1. if the test case requires no additional dependencies, move it to "core"
  2. if the test case can be successfully run using "pip install pythainlp[compact]" dependencies, move it to "compact"
  3. if the test case can be successfully run using "pip install pythainlp[compact,extra]" dependencies, move it to "extra"
    3.1 in the case that few additional dependencies (on top of [compact,extra]) can make the test case successfully run, and those few additional dependencies are relatively small, consider to grow the "extra" list of dependencies in pyproject.toml; be conservative on this initially.
  4. otherwise, keep that test case in "noauto"

Gradually work on this one by one.
If any test case is too difficult to fix, skip it to next one, and deal with it later.

The goal is to increase test coverage i.e. reduce the size of "noauto".

See https://github.com/PyThaiNLP/pythainlp/blob/dev/tests/README.md for guidance and naming convention.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI assigned Copilot and bact Feb 1, 2026
@bact bact added the tests Unit test, code coverage, test case label Feb 1, 2026
Copilot AI and others added 4 commits February 1, 2026 21:39
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
@bact bact added the refactoring a technical improvement which does not add any new features or change existing features. label Feb 1, 2026
Copilot AI changed the title [WIP] Update test coverage by moving test cases from noauto Increase test coverage by extracting core-compatible tests from noauto Feb 1, 2026
Copilot AI requested a review from bact February 1, 2026 21:50
Copilot AI and others added 2 commits February 1, 2026 21:58
- Created tests/test_helpers.py with reusable test helper functions
- Added assert_segment_handles_none_and_empty() for segment function testing
- Added assert_subword_tokenize_basic() for common subword tokenize tests
- Updated noauto, extra, compact, and core test files to use helpers
- Removed ~40+ lines of duplicated test code across multiple files

Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Updated test_tcc and test_tcc_p to use assert_segment_handles_none_and_empty
- Removed 4 more lines of duplicated test code
- All 18 core tokenize tests pass

Co-authored-by: bact <128572+bact@users.noreply.github.com>
@bact
bact requested a review from Copilot February 1, 2026 22:02
Copilot AI changed the title Increase test coverage by extracting core-compatible tests from noauto Reduce test code duplication with reusable helper functions Feb 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR successfully reduces duplicated test code by introducing a reusable test helper module (tests/test_helpers.py) with common assertion functions. The helpers are applied across multiple test suites (noauto, extra, compact, and core) to replace repetitive None/empty string test patterns.

Changes:

  • Created tests/test_helpers.py with three helper functions for common test patterns
  • Refactored 16 test classes across 4 test modules to use the new helpers, removing 57 lines of duplicated code
  • Added new test cases for error handling in paragraph_tokenize and NER, and expanded numeric data format testing

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/test_helpers.py New helper module with 3 functions: assert_segment_handles_none_and_empty, assert_subword_tokenize_handles_none_and_empty, and assert_subword_tokenize_basic
tests/noauto/testn_tokenize.py Replaced duplicated test code in 8 test classes with helper function calls
tests/extra/testx_tokenize.py Replaced duplicated test code in 2 test classes with helper function calls
tests/compact/testc_tokenize.py Replaced duplicated test code in 1 test class with helper function calls
tests/core/test_tokenize.py Replaced duplicated test code in 6 functions with helper calls, added new tests for join_broken_num parameter and paragraph_tokenize error handling, expanded numeric test coverage to longest engine
tests/core/test_tag.py Added new test for NER error handling
tests/data/text-misspelled-r0.05-seed1.txt Regenerated misspelled test data file (appears auto-generated)

Comment thread tests/core/test_tokenize.py
Comment thread tests/core/test_tokenize.py
Comment thread tests/core/test_tokenize.py
Comment thread tests/core/test_tokenize.py
Comment thread tests/core/test_tag.py
Comment thread tests/core/test_tag.py
Comment thread tests/test_helpers.py Outdated
Comment on lines +70 to +75
subword_tokenize("สวัสดิีดาวอังคาร", engine=engine), list
)

# Should not produce standalone vowels
test_case.assertNotIn(
"า", subword_tokenize("สวัสดีดาวอังคาร", engine=engine)

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test data used on lines 70 and 75 is inconsistent. Line 70 uses "สวัสดิีดาวอังคาร" (with double vowel ิี) while line 75 uses "สวัสดีดาวอังคาร" (correct spelling).

Looking at tests/core/test_tokenize.py, the pattern shows that different engines intentionally use different test strings - "สวัสดิีดาวอังคาร" is used specifically for the etcc engine (line 350), while "สวัสดีดาวอังคาร" is used for tcc, tcc_p engines (lines 340-346, 352).

Since this helper function is meant to work with any engine, it should use consistent test data. Consider using the correctly spelled "สวัสดีดาวอังคาร" on both lines 70 and 75 to ensure consistent behavior across all engines that use this helper.

Copilot uses AI. Check for mistakes.
@@ -1 +1 @@
ผมไม่ชอบกินผัก ดังนั้นผมจึงมะกจะเลือปทานอาหารท่่มีเนืัอสัตว์เป็นส่วนใหญ่ อย่างไรก็ตาม ผมก็รู้ว่าการทานผักมีประโยชน์ต่อสุขภาพ ดังนั้นฟมจึงพยายามทานผักบ้างในบางมื้อ ดต่ผมก็ยังคงเลือกทานผักที่ผมชอบเท่านั่น อย่างเช่น ถั่วฝักยาว หรือ ถั่วฝักยาว ฐึ่บผมคิดวรามัรก็เปฺนผักืี่อร่อยและมีประโยชา์ด้วย No newline at end of file
ผมไม่ชอบกินผัก ดังนั้นผมจึงมักจะะลือกทานอาหารที่สีเนื้อสัตว์ัป็นส่วนวหญ่ อย่างไรก็ตาม ผมก็รู้ว่าการทานผักมีกระโยชน์ต่อสุขภาพ ดังนั่นผมจึงพยายามทานผักบ้างในบางมื้อ แต่ผมก็ยังคงเลือกทานผักที่ผมชอบัท่านุ้น อย่างเช่น ถั่วฝักย่ว หรือ ถ้่วฝักยาว ซั่งผมคิดใ่ามุนก็เป็นผักที่อร่อยและมีประโยชน์ด้วย No newline at end of file

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data file change appears unrelated to the PR's stated purpose of reducing test code duplication. The file tests/data/text-misspelled-r0.05-seed1.txt is generated by the misspell CLI tool (see tests/core/test_cli.py line 64), and the content changes look like a regeneration with different random seed output.

If this file regeneration is intentional and related to this PR, it should be mentioned in the PR description. If not, consider removing this change from the PR to keep the scope focused on the test helper refactoring.

Copilot uses AI. Check for mistakes.
@bact

bact commented Feb 1, 2026

Copy link
Copy Markdown
Member

@copilot address suggestions in this thread #1253 (review)

Skip suggestions about PR scope / separating PR. It is fine. Keep changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

@@ -1 +1 @@
ผมไม่ชอบกินผัก ดังนั้นผมจึงมะกจะเลือปทานอาหารท่่มีเนืัอสัตว์เป็นส่วนใหญ่ อย่างไรก็ตาม ผมก็รู้ว่าการทานผักมีประโยชน์ต่อสุขภาพ ดังนั้นฟมจึงพยายามทานผักบ้างในบางมื้อ ดต่ผมก็ยังคงเลือกทานผักที่ผมชอบเท่านั่น อย่างเช่น ถั่วฝักยาว หรือ ถั่วฝักยาว ฐึ่บผมคิดวรามัรก็เปฺนผักืี่อร่อยและมีประโยชา์ด้วย No newline at end of file
ผมไม่ชอบกินผัก ดังนั้นผมจึงมักจะะลือกทานอาหารที่สีเนื้อสัตว์ัป็นส่วนวหญ่ อย่างไรก็ตาม ผมก็รู้ว่าการทานผักมีกระโยชน์ต่อสุขภาพ ดังนั่นผมจึงพยายามทานผักบ้างในบางมื้อ แต่ผมก็ยังคงเลือกทานผักที่ผมชอบัท่านุ้น อย่างเช่น ถั่วฝักย่ว หรือ ถ้่วฝักยาว ซั่งผมคิดใ่ามุนก็เป็นผักที่อร่อยและมีประโยชน์ด้วย No newline at end of file

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data file change appears unrelated to the PR's stated purpose of "reducing test code duplication with reusable helper functions." The PR description does not mention any changes to test data files. This change should either be explained in the PR description or removed if it was included accidentally.

Copilot uses AI. Check for mistakes.
Comment thread tests/test_helpers.py Outdated
Comment on lines +15 to +24
"""
Test that a segment function properly handles None and empty string inputs.

Args:
test_case: The unittest.TestCase instance (typically 'self')
segment_func: The segment function to test (e.g., attacut.segment)

Example:
assert_segment_handles_none_and_empty(self, attacut.segment)
"""

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring formatting could be improved by using proper reStructuredText or Google-style docstring format consistently. Consider using a consistent format such as: :param test_case: Description and :param segment_func: Description or the Google-style format with proper indentation for Args section.

Copilot uses AI. Check for mistakes.
Comment thread tests/extra/testx_tokenize.py Outdated
@@ -52,8 +53,7 @@ def test_sent_tokenize_thaisum(self):

class SubwordTokenizeSSGTestCase(unittest.TestCase):

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test class name should follow the naming convention with "TestCaseX" suffix instead of "TestCase" according to the PyThaiNLP test organization guidelines. This ensures consistency across all test tiers where extra tests use the X suffix.

Copilot generated this review using guidance from repository custom instructions.
Comment thread tests/core/test_tag.py
Comment on lines +96 to +97


Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are unnecessary blank lines after the test_NER_error_handling method. According to Python coding conventions and the project's guidelines for tidy code, there should be only one blank line between methods within a class.

Copilot generated this review using guidance from repository custom instructions.
Comment thread tests/extra/testx_tokenize.py Outdated
…d formatting

- Fix test class naming in extra tests: Add X suffix (TestCaseX) per PyThaiNLP conventions
- Fix inconsistent Thai test string: Use correctly spelled "สวัสดีดาวอังคาร" consistently
- Remove extra blank lines in test_tag.py after test_NER_error_handling
- Revert unrelated change to tests/data/text-misspelled-r0.05-seed1.txt

Co-authored-by: bact <128572+bact@users.noreply.github.com>

Copilot AI commented Feb 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address suggestions in this thread #1253 (review)

Skip suggestions about PR scope / separating PR. It is fine. Keep changes....

Addressed in commit 3a981fe:

  • Fixed test class naming: Added X suffix to extra test classes (SentTokenizeThaiSumTestCaseX, SubwordTokenizeSSGTestCaseX, WordTokenizeNERCutTestCaseX, WordTokenizeBudouxTestCaseX)
  • Fixed Thai string consistency: Changed "สวัสดิีดาวอังคาร" (double vowel) to "สวัสดีดาวอังคาร" (correct spelling) in test_helpers.py line 70
  • Removed extra blank lines in test_tag.py
  • Reverted unrelated test data file change

@bact

bact commented Feb 1, 2026

Copy link
Copy Markdown
Member

@copilot address comments on code docstring

- Convert Google-style docstrings to Sphinx/reStructuredText format
- Use :param type name: description format consistently
- Add proper :Example: sections with :: syntax
- Match project's docstring style used in main codebase

Co-authored-by: bact <128572+bact@users.noreply.github.com>

Copilot AI commented Feb 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address comments on code docstring

Updated in commit 3f9487c:

  • Converted docstrings from Google-style to Sphinx/reStructuredText format
  • Using :param type name: description format for parameters
  • Added proper :Example: sections with :: syntax
  • Now matches the docstring style used in the main codebase (pythainlp/tokenize/core.py)

@bact
bact marked this pull request as ready for review February 1, 2026 22:41
@bact

bact commented Feb 1, 2026

Copy link
Copy Markdown
Member

@copilot check if tltk still has compilation issue

Copilot AI commented Feb 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot check if tltk still has compilation issue

tltk no longer has compilation issues on Python 3.12.3:

Test Results:

  • ✓ Installation: pip install tltk succeeds (v1.10, requires: gensim, nltk, scikit-learn, sklearn-crfsuite, pandas)
  • ✓ Import: Works without errors
  • ✓ Tokenization: tltk.segment(), tltk.syllable_tokenize(), and subword_tokenize(engine="tltk") all work correctly
  • ✓ Spell checking: spell(engine="tltk") works
  • ✓ POS tagging: pos_tag(engine="tltk") works

The package now installs cleanly as a pure Python wheel without any Cython compilation. The "compilation issues" comments in noauto tests appear to be outdated - tltk can potentially be moved out of noauto if desired.

Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot AI changed the title Reduce test code duplication with reusable helper functions Move tltk tests from noauto to extra tier Feb 1, 2026
@sonarqubecloud

sonarqubecloud Bot commented Feb 1, 2026

Copy link
Copy Markdown

@bact
bact requested a review from Copilot February 1, 2026 23:28
@bact
bact merged commit 55168fe into dev Feb 1, 2026
27 of 37 checks passed
@bact
bact deleted the copilot/increase-test-coverage branch February 1, 2026 23:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread pyproject.toml
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of Python 3.14 classifier is premature. Python 3.14 is scheduled for release in October 2026, but it's currently February 2026. Adding this classifier before the Python version is officially released could cause issues with package distribution platforms and tools that validate classifiers. This change also appears unrelated to the stated purpose of the PR (moving tltk tests from noauto to extra tier). Consider removing this classifier until Python 3.14 is actually released.

Copilot uses AI. Check for mistakes.
Comment thread tests/core/test_tag.py
Comment on lines +92 to 97
def test_NER_error_handling(self):
# Test error handling for invalid engine/corpus combination
with self.assertRaises(ValueError):
NER(engine="thainer", corpus="cat")


Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test duplicates an existing test in tests/noauto/testn_tag.py (lines 22-24). While it's reasonable to test error handling in core tests since it doesn't require external dependencies, consider whether both tests are necessary. If the intent is to have the error validation test in core (which makes sense), the duplicate in noauto should be removed to avoid redundancy.

Suggested change
def test_NER_error_handling(self):
# Test error handling for invalid engine/corpus combination
with self.assertRaises(ValueError):
NER(engine="thainer", corpus="cat")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring a technical improvement which does not add any new features or change existing features. tests Unit test, code coverage, test case

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants