Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edcae5e

Browse files
committed
Run tests via a reuseable custom Action. Let requirements.test.txt define Pytest version etc. (remove repeated installation).
1 parent 677bce0 commit edcae5e

File tree

2 files changed

+86
-19
lines changed

2 files changed

+86
-19
lines changed

.github/actions/test/action.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name:
2+
Test
3+
4+
description:
5+
Run pytest, and run the doctest runner (shapefile.py as a script).
6+
7+
inputs:
8+
python_version:
9+
required: false
10+
default: "3.13"
11+
description: 'The Python version to run the tests on. '
12+
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
# The Repo is required to already be checked out, e.g. by the calling workflow
18+
- uses: LizardByte/setup-python-action@master
19+
with:
20+
python-version: ${{ inputs.python_version }}
21+
22+
- name: Doctests
23+
run: python shapefile.py
24+
25+
- name: Install test dependencies.
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r requirements.test.txt
29+
30+
- name: Pytest
31+
run: |
32+
pytest
33+
34+
- name: Show versions.
35+
shell: ${{ inputs.shell }}
36+
working-directory: '.\sDNA\sdna_vs2008\tests\pytest'
37+
run: |
38+
python --version
39+
python -c "import numpy; print(numpy.__version__)"
40+
python -m pytest --version
41+
42+
43+
# - name: Run debug_test.py directly.
44+
# shell: cmd
45+
# working-directory: '.\sDNA\sdna_vs2008\tests'
46+
# # run: python -u debug_test.py
47+
# run: set "sdnadll=c:\Program Files (x86)\sDNA\x64\sdna_vs2008.dll" & python -u debug_test.py
48+
49+
# - name: Run diff test number 0 directly via
50+
# test_gathering_windows_command_line_tests.py, by test index
51+
# working-directory: '.\sDNA\sdna_vs2008\tests\pytest'
52+
# run: python test_gathering_windows_command_line_tests.py 0
53+
54+
- name: Run all the diff tests with Pytest.
55+
shell: ${{ inputs.shell }}
56+
working-directory: .\sDNA\sdna_vs2008\tests\pytest
57+
env:
58+
DONT_TEST_N_LINK_SUBSYSTEMS_ORDER: ${{ inputs.DONT_TEST_N_LINK_SUBSYSTEMS_ORDER }}
59+
ALLOW_NEGATIVE_FORMULA_ERROR_ON_ANY_LINK_PRESENT: ${{ inputs.ALLOW_NEGATIVE_FORMULA_ERROR_ON_ANY_LINK_PRESENT }}
60+
sdnadll: ${{ inputs.sdnadll }}
61+
sdna_bin_dir: ${{ inputs.sdna_bin_dir }}
62+
sdna_debug: ${{ inputs.sdna_debug }}
63+
run: pytest -rA
64+
# -rA shows summary of tests, one per line, even when they all pass.
65+
#
66+
# To run the same tests locally, the command is something like:
67+
# run: >
68+
# set "sdnadll=c:\Program Files (x86)\sDNA\x64\sdna_vs2008.dll" &
69+
# set "sdna_bin_dir=c:\Program Files (x86)\sDNA\bin" &
70+
# set sdna_debug=False &
71+
# set DONT_TEST_N_LINK_SUBSYSTEMS_ORDER=1 &
72+
# set ALLOW_NEGATIVE_FORMULA_ERROR_ON_ANY_LINK_PRESENT=1 &
73+
# pytest -rA

.github/workflows/build.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
1+
# This workflow will run the pre-commit hooks (including linters), and the tests with a variety of Python versions
32

43
name: build
54

@@ -16,8 +15,8 @@ jobs:
1615
- uses: actions/checkout@v4
1716
- uses: actions/setup-python@v5
1817
- uses: pre-commit/[email protected]
19-
test:
2018

19+
test:
2120
strategy:
2221
fail-fast: false
2322
matrix:
@@ -33,21 +32,16 @@ jobs:
3332
"3.12",
3433
"3.13.0a2",
3534
]
36-
37-
runs-on: ubuntu-latest
38-
container:
39-
image: python:${{ matrix.python-version }}-slim
40-
35+
os: [
36+
"ubuntu-latest",
37+
"windows-latest",
38+
"macos-latest",
39+
]
40+
runs-on: matrix.os
4141
steps:
4242
- uses: actions/checkout@v4
43-
- name: Install dependencies
44-
run: |
45-
python -m pip install --upgrade pip
46-
python -m pip install pytest
47-
if [ -f requirements.test.txt ]; then pip install -r requirements.test.txt; fi
48-
- name: Test with doctest
49-
run: |
50-
python shapefile.py
51-
- name: Test with pytest
52-
run: |
53-
pytest
43+
44+
- name: Run tests
45+
uses: ./.github/actions/test
46+
with:
47+
python_version: ${{ matrix.python_version }}

0 commit comments

Comments
 (0)