11# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
22# SPDX-License-Identifier: CC0-1.0
33
4- name : PyPI Unit test
4+ # Check that the package can be installed from PyPI and run tests
5+
6+ name : Test package installed from PyPI
57
68on :
79 schedule :
1315 runs-on : ubuntu-latest
1416 strategy :
1517 matrix :
16- python-version : ["3.12"]
18+ # Ideally, this is the minimum supported version, as in requires-python in pyproject.toml
19+ python-version : ["3.9"]
1720
1821 steps :
1922 - uses : actions/checkout@v6
@@ -30,17 +33,20 @@ jobs:
3033 python -m nltk.downloader omw-1.4
3134 - name : Test
3235 run : |
33- mkdir pythainlp_test
36+ set -euo pipefail
37+ mkdir -p pythainlp_test
3438 cd pythainlp_test
39+ # Download sdist from PyPI (the binary distribution does not contain tests)
3540 pip download --no-binary=:all: --no-dependencies pythainlp
36- file="find . -name *.tar.gz"
37- file=$(eval "$file")
38- tar -xvzf $file --one-top-level
39- second="/"
40- path=${file//.tar.gz/$second}
41- cd $path
42- ls
43- cd tests
44- mkdir tests
45- mv data tests/
46- python -m unittest discover
41+ archive=$(ls -1 *.tar.gz | head -n1)
42+ echo "Found archive: $archive"
43+ # Determine top-level folder inside archive, extract and cd into it
44+ topdir=$(tar -tf "$archive" | head -n1 | cut -f1 -d"/")
45+ tar -xzf "$archive"
46+ cd "$topdir"
47+ ls -la
48+ # If test data is at package root and a tests dir exists, move it into tests
49+ if [ -d data ] && [ -d tests ]; then
50+ mv data tests/
51+ fi
52+ python -m unittest discover -v
0 commit comments