Skip to content

refactor(tests): reorganize noauto test cases by function; fix too-broad except - #1353

Merged
bact merged 2 commits into
devfrom
copilot/organise-test-cases-by-functions
Mar 21, 2026
Merged

refactor(tests): reorganize noauto test cases by function; fix too-broad except#1353
bact merged 2 commits into
devfrom
copilot/organise-test-cases-by-functions

Conversation

Copilot AI commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

Test classes in testn_tokenize_onnx.py and testn_tokenize_torch.py covered non-tokenization functionality (transliteration, tagging, spell, parse, summarize, augment), making failures hard to trace and suite boundaries meaningless. Also fixes a dead try/except Exception in the spell module.

Test reorganization — ONNX (tests/noauto_onnx/)

Extracted from testn_tokenize_onnx.py into dedicated files:

New file Class
testn_transliterate_onnx.py TransliterateONNXTestCaseN
testn_tag_onnx.py TagONNXTestCaseN
testn_spell_onnx.py SpellONNXTestCaseN

Test reorganization — Torch (tests/noauto_torch/)

Extracted from testn_tokenize_torch.py into dedicated files:

New file Class
testn_transliterate_torch.py TransliterateTestCaseN
testn_parse_torch.py ParseTestCaseN
testn_summarize_torch.py SummarizeTestCaseN
testn_augment_torch.py AugmentTestCaseN

Both __init__.py files updated to register new modules in alphabetical order.

Increased coverage

Each new file expands the original single-assertion tests with: model-loaded key checks (<start>/<end> in vocab dicts), empty-input handling, result structure validation (tuple pairs, string items), length constraints, and ValueError on out-of-range arguments.

Bug fix — too-broad try/except

pythainlp/spell/wanchanberta_thai_grammarly.py: the except Exception block wrapping label_ids.append(2) was unreachable (list.append never raises) and silently swallowed any future logic errors in that branch.

# Before — dead except, hides future bugs
try:
    label_ids.append(2)
except Exception:
    label_ids.append(-100)

# After
label_ids.append(2)

Your checklist for this pull request

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

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

@bact bact added the tests Unit test, code coverage, test case label Mar 21, 2026
@bact bact added this to the 5.3.3 milestone Mar 21, 2026
…oad except

Move misplaced test classes out of tokenize test files:

ONNX tests (tests/noauto_onnx/):
- TransliterateONNXTestCaseN → testn_transliterate_onnx.py
- TagONNXTestCaseN          → testn_tag_onnx.py
- SpellONNXTestCaseN        → testn_spell_onnx.py

Torch tests (tests/noauto_torch/):
- TransliterateTestCaseN    → testn_transliterate_torch.py
- ParseTestCaseN            → testn_parse_torch.py
- SummarizeTestCaseN        → testn_summarize_torch.py
- AugmentTestCaseN          → testn_augment_torch.py

Each new file adds edge-case tests: model-loaded checks, empty
inputs, result structure (tuple pairs, string items), length
constraints, and ValueError on out-of-range arguments.

Update noauto_onnx/__init__.py and noauto_torch/__init__.py to
register the new modules.

Fix: remove dead try/except Exception wrapping list.append(2) in
pythainlp/spell/wanchanberta_thai_grammarly.py (too-broad catch,
unreachable except branch).

Co-authored-by: bact <128572+bact@users.noreply.github.com>
Agent-Logs-Url: https://github.com/PyThaiNLP/pythainlp/sessions/dbbd3773-7bc2-4463-a049-e17a95e2651f
Copilot AI changed the title [WIP] Organise test cases by functions and increase test coverage refactor(tests): reorganize noauto test cases by function; fix too-broad except Mar 21, 2026
Copilot AI requested a review from bact March 21, 2026 22:42
Copilot finished work on behalf of bact March 21, 2026 22:42
@sonarqubecloud

Copy link
Copy Markdown

@bact bact added this to PyThaiNLP Mar 21, 2026
@bact bact moved this to In progress in PyThaiNLP Mar 21, 2026
@bact
bact marked this pull request as ready for review March 21, 2026 22:45
@bact
bact merged commit 1b55f4f into dev Mar 21, 2026
27 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in PyThaiNLP Mar 21, 2026
@bact
bact deleted the copilot/organise-test-cases-by-functions branch March 24, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Unit test, code coverage, test case

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants