Skip to content

Commit df0feec

Browse files
authored
Implement unit tests (#76)
* Minor change to project description * Including testing section * Errors on workflow * Increase pre-commit hooks * Consider also .github folder in pre-commit * Setting up proper dependencies between jobs * Always upload server logs * START command windows * Upload artifact with different names * New trial with windows cmd * Trying to solve vale warning * Using pythonw approach * Checking if server runs at all... * Caching tests dependencies * Trying to emulate nohup approach Windows * Typo in workflow * Typo in workflow * Trying different approach * Other trial * Try doing it all at once * Even the process for Linux/Windows * Not needed any more * Remove sklearn dep
1 parent d99afd0 commit df0feec

File tree

4 files changed

+105
-33
lines changed

4 files changed

+105
-33
lines changed

.github/workflows/ci_cd.yml

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ concurrency:
2020

2121
jobs:
2222

23-
style:
24-
name: Code style
25-
runs-on: ubuntu-latest
26-
steps:
27-
- name: PyAnsys code style checks
28-
uses: pyansys/actions/code-style@v3
29-
with:
30-
python-version: ${{ env.MAIN_PYTHON_VERSION }}
31-
3223
docs-style:
3324
name: Documentation Style Check
3425
runs-on: ubuntu-latest
@@ -38,6 +29,46 @@ jobs:
3829
with:
3930
token: ${{ secrets.GITHUB_TOKEN }}
4031

32+
docs:
33+
name: Documentation
34+
runs-on: ubuntu-latest
35+
needs: [docs-style]
36+
steps:
37+
- uses: actions/checkout@v3
38+
39+
- name: Set up Python ${{ env.MAIN_PYTHON_VERSION }}
40+
uses: actions/setup-python@v4
41+
with:
42+
python-version: ${{ env.MAIN_PYTHON_VERSION }}
43+
cache: 'pip'
44+
cache-dependency-path: 'pyproject.toml'
45+
46+
- name: Install packages for documentation build
47+
run: |
48+
sudo apt-get install xvfb pandoc
49+
pip install --upgrade build
50+
pip install .[doc]
51+
52+
- name: Build the documentation
53+
run: |
54+
xvfb-run make -C doc html
55+
56+
- name: Upload HTML documentation
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: documentation-html
60+
path: doc/_build/html
61+
retention-days: 7
62+
63+
style:
64+
name: Code style
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: PyAnsys code style checks
68+
uses: pyansys/actions/code-style@v3
69+
with:
70+
python-version: ${{ env.MAIN_PYTHON_VERSION }}
71+
4172
smoke-tests:
4273
name: Build and Smoke tests
4374
runs-on: ${{ matrix.os }}
@@ -57,40 +88,64 @@ jobs:
5788
operating-system: ${{ matrix.os }}
5889
python-version: ${{ matrix.python-version }}
5990

60-
docs:
61-
name: Documentation
62-
runs-on: ubuntu-latest
63-
needs: [docs-style]
91+
tests:
92+
name: Testing
93+
runs-on: ${{ matrix.os }}
94+
needs: [smoke-tests]
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
os: [windows-latest, ubuntu-latest]
99+
64100
steps:
65-
- uses: actions/checkout@v3
101+
- name: Checkout repository
102+
uses: actions/checkout@v3
66103

67-
- name: Set up Python ${{ env.MAIN_PYTHON_VERSION }}
104+
- name: Set up Python
68105
uses: actions/setup-python@v4
69106
with:
70107
python-version: ${{ env.MAIN_PYTHON_VERSION }}
71108
cache: 'pip'
72109
cache-dependency-path: 'pyproject.toml'
73110

74-
- name: Install packages for documentation build
111+
- name: Install ansys-dyna-core (with test requirements)
75112
run: |
76-
sudo apt-get install xvfb pandoc
77-
pip install --upgrade build
78-
pip install .[doc]
113+
pip install -e .[tests]
79114
80-
- name: Build the documentation
115+
- name: Run tests (Windows)
116+
if: runner.os == 'Windows'
81117
run: |
82-
xvfb-run make -C doc html
118+
Start-Job -ScriptBlock {cd ${{ github.workspace }}\src\ansys\dyna\core\pre\Server\;python kwserver.py >> server_output.txt}
119+
Start-Sleep -Seconds 10
120+
pytest
83121
84-
- name: Upload HTML documentation
122+
- name: Run tests (Linux)
123+
if: runner.os == 'Linux'
124+
run: |
125+
cd src/ansys/dyna/core/pre/Server
126+
python kwserver.py > server_output.txt &
127+
sleep 10
128+
cd -
129+
pytest
130+
131+
- name: Upload the server logs
132+
if: always()
85133
uses: actions/upload-artifact@v3
86134
with:
87-
name: documentation-html
88-
path: doc/_build/html
135+
name: server-logs-${{ runner.os }}
136+
path: src/ansys/dyna/core/pre/Server/server_output.txt
137+
138+
- name: Upload coverage results
139+
if: runner.os == 'Linux'
140+
uses: actions/upload-artifact@v3
141+
with:
142+
name: coverage-html
143+
path: .cov/html
89144
retention-days: 7
90145

91146
package:
92147
name: Package library
93-
needs: [docs]
148+
needs: [docs, tests]
94149
runs-on: ubuntu-latest
95150
steps:
96151
- name: Build library source and wheel artifacts
@@ -114,7 +169,7 @@ jobs:
114169
name: Upload dev documentation
115170
if: github.ref == 'refs/heads/main'
116171
runs-on: ubuntu-latest
117-
needs: [docs]
172+
needs: [package]
118173
steps:
119174
- name: Deploy the latest documentation
120175
uses: pyansys/actions/doc-deploy-dev@v3

.pre-commit-config.yaml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
files: |
22
(?x)(
3-
^src/ansys/
3+
^src/ansys/ |
4+
^.github/
45
)
56
exclude: |
67
(?x)^(
@@ -14,12 +15,18 @@ exclude: |
1415
repos:
1516

1617
- repo: https://github.com/psf/black
17-
rev: 23.1.0
18+
rev: 23.1.0 # IF VERSION CHANGES --> MODIFY "blacken-docs" MANUALLY AS WELL!!
1819
hooks:
1920
- id: black
2021
args:
2122
- --line-length=120
2223

24+
- repo: https://github.com/adamchainz/blacken-docs
25+
rev: 1.13.0
26+
hooks:
27+
- id: blacken-docs
28+
additional_dependencies: [black==23.1.0]
29+
2330
- repo: https://github.com/codespell-project/codespell
2431
rev: v2.2.2
2532
hooks:
@@ -39,4 +46,15 @@ repos:
3946
- id: isort
4047
args:
4148
- --line-length=120
42-
49+
50+
- repo: https://github.com/pre-commit/pre-commit-hooks
51+
rev: v4.4.0
52+
hooks:
53+
- id: check-merge-conflict
54+
- id: debug-statements
55+
56+
# this validates our github workflow files
57+
- repo: https://github.com/python-jsonschema/check-jsonschema
58+
rev: 0.21.0
59+
hooks:
60+
- id: check-github-workflows

doc/source/Resources/pydyna_post.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
PyDPF-post for LS-DYNA
2-
======================
1+
Using PyDPF-post for LS-DYNA
2+
============================
33

44
Operators
55
~~~~~~~~~

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
name = "ansys-dyna-core"
77
version = "0.2.dev0"
8-
description = "Python interface to LSDYNA Service"
8+
description = "Python interface to LS-DYNA Service"
99
readme = "README.rst"
1010
requires-python = ">=3.7,<4"
1111
license = {file = "LICENSE"}
@@ -41,7 +41,6 @@ tests = [
4141
"pytest-cov==4.0.0",
4242
"codecov==2.1.12",
4343
"joblib==1.2.0",
44-
"sklearn==0.0.post1",
4544
"pandas==1.5.2",
4645
"openpyxl==3.0.10",
4746
"scikit-learn==1.2.1",

0 commit comments

Comments
 (0)