Skip to content

Commit d55e615

Browse files
authored
Merge pull request #1290 from PyThaiNLP/copilot/refactor-noauto-test-suites
Reorganize noauto test suite by dependency groups to resolve conflicts
2 parents 31a7010 + 0cf1aa1 commit d55e615

17 files changed

Lines changed: 850 additions & 233 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ See PR for prompt and details.
3434
- Make package zip-safe #1212
3535
- Ensure thread-safety for tokenizers #1213
3636
- Add Thai-NNER integration with top-level entity filtering #1221
37+
- Reorganize noauto test suite by dependency groups (torch, tensorflow, onnx, cython, network) #935
3738
- Improved documentation; code cleanup; more tests
3839

3940
## Version 5.1.2 -> 5.2.0

pyproject.toml

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ dependencies = [
6868

6969
[project.optional-dependencies]
7070

71-
# Development and testing dependencies
71+
## 1) Development ########################################
72+
7273
dev = [
7374
"black>=25.11.0",
7475
"build>=1.0.0",
@@ -79,14 +80,13 @@ dev = [
7980
"tox>=4.30.3",
8081
]
8182

82-
# Documentation dependencies
8383
docs = [
8484
"Sphinx>=6.2",
8585
"sphinx-copybutton>=0.5.2",
8686
"sphinx-rtd-theme>=3.1.0",
8787
]
8888

89-
# Below are dependencies for optional features
89+
## 2) Feature sets #######################################
9090

9191
abbreviation = ["khamyo>=0.2.0"]
9292

@@ -166,9 +166,13 @@ wtp = ["transformers>=4.22.1", "wtpsplit>=1.0.1"]
166166

167167
wunsen = ["wunsen>=0.0.3"]
168168

169-
# Below are defined groups of CI testing dependencies
169+
## 3) Testing ############################################
170+
171+
# Below are dependency groups for each defined test suites
170172

171-
# Compact dependencies - safe small set of optional dependencies
173+
# Compact dependencies - for tests.compact modules
174+
# Safe small set of optional dependencies
175+
# for common tasks like tokenization and tagging.
172176
compact = [
173177
"nlpo3>=1.4.0",
174178
"numpy>=1.26.0",
@@ -178,7 +182,6 @@ compact = [
178182
]
179183

180184
# Extra dependencies - for tests.extra modules
181-
# Note: Some packages excluded due to Python 3.13 compatibility issues
182185
extra = [
183186
"bpemb>=0.3.2",
184187
"budoux>=0.7.0",
@@ -190,6 +193,46 @@ extra = [
190193
"tltk>=1.10",
191194
]
192195

196+
# Noauto test dependencies - for tests.noauto_* modules
197+
# These are further grouped by dependency framework to avoid conflicts
198+
199+
# PyTorch-based dependencies - for tests.noauto_torch
200+
noauto-torch = [
201+
"attacut>=1.0.6",
202+
"numpy>=1.26.0",
203+
"sentencepiece>=0.1.91",
204+
"thai-nner>=0.3",
205+
"tltk>=1.10",
206+
"torch>=1.13.1",
207+
"transformers>=4.22.1",
208+
"wtpsplit>=1.0.1",
209+
]
210+
211+
# TensorFlow-based dependencies - for tests.noauto_tensorflow
212+
noauto-tensorflow = [
213+
"deepcut>=0.7.0",
214+
"numpy>=1.26.0",
215+
]
216+
217+
# ONNX Runtime-based dependencies - for tests.noauto_onnx
218+
noauto-onnx = [
219+
"numpy>=1.26.0",
220+
"onnxruntime>=1.10.0",
221+
"oskut>=1.3",
222+
"sefr_cut>=1.1",
223+
]
224+
225+
# Cython-based dependencies - for tests.noauto_cython
226+
noauto-cython = [
227+
"phunspell>=0.1.6",
228+
]
229+
230+
# Network-dependent tests - for tests.noauto_network
231+
# These tests require network access but minimal dependencies
232+
noauto-network = [
233+
"huggingface-hub>=0.16.0",
234+
]
235+
193236
# Full dependencies - pinned where available
194237
full = [
195238
"attacut==1.0.6",

tests/README.md

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,88 @@ The CI/CD test workflow is at
7474

7575
## Noauto tests (testn_*.py)
7676

77-
- These dependencies might include huge libraries like `tensorflow`.
78-
- Due to dependency complexities, these functionalities may not be tested
79-
in the CI/CD pipeline.
80-
- In the future, we might create a separate
81-
step or workflow to run this test suite.
82-
It will be triggered manually.
83-
We may also need to group test cases by
84-
a non-conflicting set of dependencies.
77+
The noauto (no-automated) test suite contains tests for functionalities
78+
that require heavy dependencies which are not feasible to run in automated
79+
CI/CD pipelines. These tests are organized into specialized suites based
80+
on their dependency requirements.
81+
82+
### Why separate noauto test suites?
83+
84+
Different ML/AI frameworks often have conflicting version requirements for
85+
their dependencies. For example:
86+
- PyTorch and TensorFlow may require different versions of numpy or protobuf
87+
- Large frameworks take significant time to install (~1-3 GB each)
88+
- Some packages require Cython compilation or system libraries
89+
90+
By separating tests by dependency group, we can:
91+
- Test each framework independently without conflicts
92+
- Optimize CI/CD resources by running only relevant test groups
93+
- Make it easier for developers to test specific functionality
94+
95+
### Noauto test suites
96+
97+
#### Umbrella suite: tests.noauto
98+
99+
- Run `unittest tests.noauto`
100+
- Includes all modular noauto test suites
101+
- Use this for comprehensive testing when all dependencies are available
85102
- Test case class suffix: `TestCaseN`
86103

104+
#### Modular suites by dependency:
105+
106+
**PyTorch-based: tests.noauto_torch**
107+
108+
- Run `unittest tests.noauto_torch`
109+
- Need dependencies from `pip install "pythainlp[noauto-torch]"`
110+
- Tests requiring PyTorch and its ecosystem:
111+
- torch, transformers (PyTorch backend)
112+
- attacut, thai-nner, wtpsplit, tltk
113+
- Tests: spell correction (wanchanberta), NER/POS tagging (transformers-based),
114+
tokenization (attacut), subword tokenization (phayathai, wangchanberta),
115+
sentence tokenization (wtp)
116+
- Dependencies: ~2-3 GB
117+
- Test case class suffix: `TestCaseN`
118+
119+
**TensorFlow-based: tests.noauto_tensorflow**
120+
121+
- Run `unittest tests.noauto_tensorflow`
122+
- Need dependencies from `pip install "pythainlp[noauto-tensorflow]"`
123+
- Tests requiring TensorFlow:
124+
- deepcut tokenizer
125+
- Dependencies: ~1-2 GB
126+
- Note: May conflict with PyTorch dependencies
127+
- Test case class suffix: `TestCaseN`
128+
129+
**ONNX Runtime-based: tests.noauto_onnx**
130+
131+
- Run `unittest tests.noauto_onnx`
132+
- Need dependencies from `pip install "pythainlp[noauto-onnx]"`
133+
- Tests requiring ONNX Runtime:
134+
- oskut, sefr_cut tokenizers
135+
- Dependencies: ~200-500 MB
136+
- Test case class suffix: `TestCaseN`
137+
138+
**Cython-compiled: tests.noauto_cython**
139+
140+
- Run `unittest tests.noauto_cython`
141+
- Need dependencies from `pip install "pythainlp[noauto-cython]"`
142+
- Tests requiring Cython-compiled packages:
143+
- phunspell spell checker
144+
- Requires: Cython, C compiler, system libraries (hunspell)
145+
- Platform-specific build requirements
146+
- Test case class suffix: `TestCaseN`
147+
148+
**Network-dependent: tests.noauto_network**
149+
150+
- Run `unittest tests.noauto_network`
151+
- Need dependencies from `pip install "pythainlp[noauto-network]"`
152+
- Tests requiring network access:
153+
- HuggingFace Hub model downloads
154+
- External API calls
155+
- Requires: Internet connection, may involve large downloads
156+
- Test case class suffix: `TestCaseN`
157+
158+
87159
## Robustness tests (test_robustness.py)
88160

89161
A comprehensive test suite within core tests that tests edge cases important

tests/noauto/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,28 @@
1111
1212
These tests are NOT run in automated CI workflows but are kept for
1313
manual testing and future re-enabling when dependencies improve.
14+
15+
This test suite serves as an umbrella that includes all specialized
16+
noauto test suites:
17+
- noauto_torch: PyTorch and transformers-based tests
18+
- noauto_tensorflow: TensorFlow-based tests
19+
- noauto_onnx: ONNX Runtime-based tests
20+
- noauto_cython: Cython-compiled package tests
21+
- noauto_network: Network-dependent tests
22+
23+
For targeted testing, use the specific test suites instead of this umbrella.
1424
"""
1525

1626
from unittest import TestLoader, TestSuite
1727

1828
# Names of module to be tested
1929
# Note: These tests are NOT included in automated CI runs
2030
test_packages: list[str] = [
21-
"tests.noauto.testn_spell",
22-
"tests.noauto.testn_tag",
23-
"tests.noauto.testn_tokenize",
31+
"tests.noauto_torch",
32+
"tests.noauto_tensorflow",
33+
"tests.noauto_onnx",
34+
"tests.noauto_cython",
35+
"tests.noauto_network",
2436
]
2537

2638

@@ -29,6 +41,14 @@ def load_tests(
2941
) -> TestSuite:
3042
"""Load test protocol
3143
See: https://docs.python.org/3/library/unittest.html#id1
44+
45+
This loads all modular test suites.
46+
For targeted testing, use specific test suites directly:
47+
- unittest tests.noauto_torch
48+
- unittest tests.noauto_tensorflow
49+
- unittest tests.noauto_onnx
50+
- unittest tests.noauto_cython
51+
- unittest tests.noauto_network
3252
"""
3353
suite = TestSuite()
3454
for test_package in test_packages:

0 commit comments

Comments
 (0)