Skip to content

Commit 435aba6

Browse files
authored
Merge pull request #7 from gilrrei/add_pytest
feat: introduce pytest
2 parents 0c69146 + aa525ea commit 435aba6

File tree

9 files changed

+176
-83
lines changed

9 files changed

+176
-83
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
name: Check valid YAML syntax
1919
- id: end-of-file-fixer
2020
name: Check for newline at end of file
21-
exclude: '^LICENSE$'
21+
exclude: "^LICENSE$"
2222
- id: debug-statements
2323
name: Check for debugger imports
2424
- id: trailing-whitespace
@@ -35,7 +35,7 @@ repos:
3535
hooks:
3636
- id: docformatter
3737
name: Run docformatter (formatter for docstrings)
38-
args: ["--in-place", "--config=./pyproject.toml", "-r", "src/fourc_webviewer/", "test/"]
38+
args: ["--in-place", "--config=./pyproject.toml", "-r", "src/fourc_webviewer/", "tests/"]
3939
- repo: https://github.com/econchick/interrogate
4040
rev: 1.7.0
4141
hooks:

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ dependencies = { file = ["requirements.txt"] }
1818

1919
[tool.setuptools]
2020
package-dir = { "" = "src" }
21+
22+
# External tools
23+
[tool.pytest.ini_options]
24+
testpaths = ["tests"]
25+
addopts = '-m "not gui"' # deactivate tests that require a GUI
26+
markers = ["gui: Tests that require a GUI."]

requirements.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ numpy
1111
# include fourcipp from github
1212
git+https://github.com/4C-multiphysics/fourcipp.git
1313
lnmmeshio>=5.6.3
14+
15+
# development
16+
pytest
17+
pre-commit

requirements.txt

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ attrs==25.3.0
1616
# fourcipp
1717
# jsonschema
1818
# referencing
19+
certifi==2025.4.26
20+
# via requests
21+
cfgv==3.4.0
22+
# via pre-commit
23+
charset-normalizer==3.4.2
24+
# via requests
1925
contourpy==1.3.2
2026
# via matplotlib
2127
cycler==0.12.1
@@ -24,6 +30,10 @@ deprecation==2.1.0
2430
# via
2531
# fourcipp
2632
# rapidyaml
33+
distlib==0.3.9
34+
# via virtualenv
35+
filelock==3.18.0
36+
# via virtualenv
2737
fonttools==4.57.0
2838
# via matplotlib
2939
fourcipp @ git+https://github.com/4C-multiphysics/fourcipp.git
@@ -32,8 +42,14 @@ frozenlist==1.6.0
3242
# via
3343
# aiohttp
3444
# aiosignal
45+
identify==2.6.10
46+
# via pre-commit
3547
idna==3.10
36-
# via yarl
48+
# via
49+
# requests
50+
# yarl
51+
iniconfig==2.1.0
52+
# via pytest
3753
jsonschema==4.23.0
3854
# via fourcipp
3955
jsonschema-rs==0.30.0
@@ -47,11 +63,15 @@ kiwisolver==1.4.8
4763
lnmmeshio==5.6.3
4864
# via -r requirements.in
4965
loguru==0.7.3
50-
# via fourcipp
66+
# via
67+
# fourcipp
68+
# lnmmeshio
5169
markdown-it-py==3.0.0
5270
# via rich
5371
matplotlib==3.10.1
54-
# via vtk
72+
# via
73+
# pyvista
74+
# vtk
5575
mdurl==0.1.2
5676
# via markdown-it-py
5777
meshio==5.3.5
@@ -66,6 +86,8 @@ multidict==6.4.3
6686
# yarl
6787
narwhals==1.38.0
6888
# via plotly
89+
nodeenv==1.9.1
90+
# via pre-commit
6991
numpy==2.2.5
7092
# via
7193
# -r requirements.in
@@ -75,22 +97,35 @@ numpy==2.2.5
7597
# matplotlib
7698
# meshio
7799
# pandas
100+
# pyvista
78101
packaging==25.0
79102
# via
80103
# deprecation
81104
# fourcipp
82105
# matplotlib
83106
# plotly
107+
# pooch
108+
# pytest
84109
pandas==2.2.3
85110
# via -r requirements.in
86111
pillow==11.2.1
87-
# via matplotlib
112+
# via
113+
# matplotlib
114+
# pyvista
115+
platformdirs==4.3.8
116+
# via
117+
# pooch
118+
# virtualenv
88119
plotly==6.0.1
89120
# via
90121
# -r requirements.in
91122
# trame-plotly
92-
progress==1.6
93-
# via lnmmeshio
123+
pluggy==1.6.0
124+
# via pytest
125+
pooch==1.8.2
126+
# via pyvista
127+
pre-commit==4.2.0
128+
# via -r requirements.in
94129
propcache==0.3.1
95130
# via
96131
# aiohttp
@@ -99,6 +134,8 @@ pygments==2.19.1
99134
# via rich
100135
pyparsing==3.2.3
101136
# via matplotlib
137+
pytest==8.3.5
138+
# via -r requirements.in
102139
python-dateutil==2.9.0.post0
103140
# via
104141
# matplotlib
@@ -112,12 +149,18 @@ pyvista==0.45.0
112149
pyyaml==6.0.2
113150
# via trame
114151
rapidyaml==0.9.0
152+
# via
153+
# lnmmeshio
154+
# pre-commit
155+
# trame
115156
# via fourcipp
116157
referencing==0.36.2
117158
# via
118159
# fourcipp
119160
# jsonschema
120161
# jsonschema-specifications
162+
requests==2.32.3
163+
# via pooch
121164
rich==14.0.0
122165
# via meshio
123166
rpds-py==0.24.0
@@ -131,8 +174,12 @@ ruamel-yaml-clib==0.2.12
131174
# via
132175
# fourcipp
133176
# ruamel-yaml
177+
scooby==0.10.1
178+
# via pyvista
134179
six==1.17.0
135180
# via python-dateutil
181+
tqdm==4.66.5
182+
# via lnmmeshio
136183
trame==3.9.0
137184
# via -r requirements.in
138185
trame-client==3.8.2
@@ -160,11 +207,18 @@ typing-extensions==4.13.2
160207
# via
161208
# fourcipp
162209
# python-utils
210+
# pyvista
163211
# referencing
164212
tzdata==2025.2
165213
# via pandas
214+
urllib3==2.4.0
215+
# via requests
216+
virtualenv==20.31.2
217+
# via pre-commit
166218
vtk==9.4.2
167-
# via -r requirements.in
219+
# via
220+
# -r requirements.in
221+
# pyvista
168222
wslink==2.3.3
169223
# via
170224
# trame

src/fourc_webviewer/fourc_webserver.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ class FourCWebServer:
3636
components (e.g., state, controller) along with other relevant server-only
3737
variables."""
3838

39-
def __init__(self, page_title, fourc_yaml_file):
39+
def __init__(
40+
self,
41+
fourc_yaml_file,
42+
page_title="4C Webviewer",
43+
):
4044
"""Constructor.
4145
4246
Args:
47+
fourc_yaml_file (string|Path): path to the input fourc yaml file.
4348
page_title (string): page title appearing in the browser
4449
tab.
45-
fourc_yaml_file (string|Path): path to the input fourc yaml file.
4650
"""
4751

4852
self.server = get_server()

src/fourc_webviewer/run_webserver.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""Utility to run the webserver on a defined port."""
22

33
from fourc_webviewer.fourc_webserver import FourCWebServer
4-
from fourc_webviewer_default_files import (
5-
DEFAULT_INPUT_FILE,
6-
)
4+
from fourc_webviewer_default_files import DEFAULT_INPUT_FILE
75

86
# specify server port for the app to run on
97
SERVER_PORT = 12345
@@ -13,13 +11,11 @@ def run_webviewer(fourc_yaml_file=None):
1311
"""Runs the webviewer by creating a dedicated webserver object, starting it
1412
and cleaning up afterwards."""
1513

14+
# use the default input file
1615
if fourc_yaml_file is None:
17-
fourc_yaml_file = str(DEFAULT_INPUT_FILE)
16+
fourc_yaml_file = DEFAULT_INPUT_FILE
1817

19-
# create fourc webserver object
20-
fourc_webserver = FourCWebServer(
21-
page_title="4C Webviewer", fourc_yaml_file=fourc_yaml_file
22-
)
18+
fourc_webserver = FourCWebServer(fourc_yaml_file)
2319

2420
# start the server after everything is set up
2521
fourc_webserver.server.start(port=SERVER_PORT)

test/test_pyvista.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

tests/test_fourcwebserver.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Test FourC webserver."""
2+
3+
import pytest
4+
from fourcipp.fourc_input import FourCInput
5+
6+
from fourc_webviewer.fourc_webserver import FourCWebServer
7+
from fourc_webviewer_default_files import DEFAULT_INPUT_FILE
8+
9+
10+
@pytest.fixture(name="fourc_webserver")
11+
def fixture_fourc_webserver():
12+
"""FourC webserver fixture."""
13+
return FourCWebServer(fourc_yaml_file=DEFAULT_INPUT_FILE)
14+
15+
16+
@pytest.mark.parametrize(
17+
"key, reference_value",
18+
[
19+
("render_count", {"change_selected_material": 0, "change_fourc_yaml_file": 0}),
20+
("fourc_yaml_content", FourCInput.from_4C_yaml(DEFAULT_INPUT_FILE)),
21+
("fourc_yaml_name", DEFAULT_INPUT_FILE.name),
22+
],
23+
)
24+
def test_webserver_server_variables(fourc_webserver, key, reference_value):
25+
"""Test if server variables are initialised correctly."""
26+
assert fourc_webserver._server_vars[key] == reference_value

0 commit comments

Comments
 (0)