Skip to content

Commit eb7ad80

Browse files
Copilotbact
andcommitted
Add doctest syntax checking and execution to CI workflow
Co-authored-by: bact <128572+bact@users.noreply.github.com>
1 parent 164443f commit eb7ad80

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

.github/workflows/unittest.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,58 @@ jobs:
123123
# loading tests with dependencies more than expected.
124124
# Test cases loaded is defined in __init__.py in the tests directory.
125125
# See also tests/README.md
126+
- name: Check doctest syntax
127+
if: matrix.python-version == env.PYTHON_VERSION_LATEST && matrix.os == 'ubuntu-latest'
128+
run: |
129+
echo "Checking doctest syntax in Python files..."
130+
python -c "
131+
import ast
132+
import sys
133+
from pathlib import Path
134+
135+
files_with_doctests = [
136+
'pythainlp/word_vector/core.py',
137+
'pythainlp/phayathaibert/core.py',
138+
'pythainlp/tag/tltk.py',
139+
'pythainlp/tag/named_entity.py',
140+
'pythainlp/tag/_tag_perceptron.py',
141+
'pythainlp/tag/thainer.py',
142+
'pythainlp/ulmfit/tokenizer.py',
143+
'pythainlp/ulmfit/core.py',
144+
'pythainlp/ulmfit/preprocess.py',
145+
'pythainlp/soundex/complete_soundex.py',
146+
'pythainlp/translate/tokenization_small100.py',
147+
'pythainlp/util/thai.py',
148+
'pythainlp/corpus/wordnet.py'
149+
]
150+
151+
errors = []
152+
for file in files_with_doctests:
153+
try:
154+
with open(file, 'r', encoding='utf-8') as f:
155+
ast.parse(f.read())
156+
except SyntaxError as e:
157+
errors.append(f'{file}: {e}')
158+
159+
if errors:
160+
print('Syntax errors found in doctest files:')
161+
for error in errors:
162+
print(f' - {error}')
163+
sys.exit(1)
164+
else:
165+
print(f'✓ All {len(files_with_doctests)} files with doctests have valid Python syntax')
166+
"
167+
# Only check doctest syntax on latest Python version on Ubuntu
168+
- name: Run doctests
169+
if: matrix.python-version == env.PYTHON_VERSION_LATEST && matrix.os == 'ubuntu-latest'
170+
run: |
171+
echo "Running doctests on selected modules..."
172+
python -m doctest pythainlp/tokenize/core.py -v || true
173+
python -m doctest pythainlp/util/thai.py -v || true
174+
echo "Note: Some doctests may fail due to missing optional dependencies."
175+
echo "Doctest execution completed. Check output above for any failures."
176+
# Only run doctests on latest Python version on Ubuntu
177+
# Use '|| true' to not fail the build if doctests fail due to missing deps
126178
- name: Coverage report
127179
if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION_LATEST
128180
env:

0 commit comments

Comments
 (0)