Skip to content

Commit 438b22a

Browse files
test available properties for plotting (#782)
* test with pytest-cov * test `model_json_schema_from_atoms` * refactor into function * bump version * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * sleep longer * increase wait timeout * increase timeout --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent df96183 commit 438b22a

File tree

7 files changed

+73
-28
lines changed

7 files changed

+73
-28
lines changed

.github/workflows/test.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ jobs:
4848
- name: Pytest
4949
run: |
5050
uv run python --version
51-
uv run coverage run -m pytest -vv
52-
uv run coverage xml
53-
- name: Upload coverage reports to Codecov
54-
uses: codecov/codecov-action@v3
55-
env:
56-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
51+
uv run pytest --cov --junitxml=junit.xml -o junit_family=legacy
52+
- name: Upload coverage to Codecov
53+
uses: codecov/codecov-action@v5
54+
with:
55+
token: ${{ secrets.CODECOV_TOKEN }}
56+
- name: Upload test results to Codecov
57+
if: ${{ !cancelled() }}
58+
uses: codecov/test-results-action@v1
59+
with:
60+
token: ${{ secrets.CODECOV_TOKEN }}

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "zndraw"
3-
version = "0.5.8a1"
3+
version = "0.5.8"
44
description = "Display and Edit Molecular Structures and Trajectories in the Browser."
55
authors = [
66
{ name = "Fabian Zills", email = "[email protected]" },
@@ -63,9 +63,9 @@ skip = "*.svg,*.lock"
6363

6464
[dependency-groups]
6565
dev = [
66-
"coverage>=7.6.10",
6766
"mdanalysis>=2.8.0",
6867
"pytest>=8.3.4",
68+
"pytest-cov>=6.0.0",
6969
"rdkit2ase>=0.1.4",
7070
"tidynamics>=1.1.2",
7171
"znh5md>=0.4.4",

tests/test_analysis.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import numpy as np
12
import znsocket
23

34
from zndraw import ZnDraw
5+
from zndraw.analyse import Properties1D
46

57

68
def run_queue(vis, key, msg: dict):
@@ -11,7 +13,7 @@ def run_queue(vis, key, msg: dict):
1113
)
1214
modifier_queue.update(msg)
1315
vis.socket.emit("room:worker:run")
14-
vis.socket.sleep(7)
16+
vis.socket.sleep(10)
1517

1618

1719
def test_run_analysis_distance(server, s22_energy_forces):
@@ -68,3 +70,26 @@ def test_run_analysis_DihedralAngle(server, s22_energy_forces):
6870
fig = vis.figures["DihedralAngle"]
6971
# assert that the x-axis label is "step"
7072
assert fig.layout.xaxis.title.text == "step"
73+
74+
75+
def test_analysis_Properties1D_json_schema(s22_energy_forces):
76+
# add custom info keys
77+
for atoms in s22_energy_forces:
78+
atoms.info["custom"] = 42
79+
atoms.info["custom2"] = np.random.rand(10)
80+
atoms.info["custom3"] = np.random.rand(10, 5)
81+
atoms.calc.results["custom4"] = np.random.rand(10)
82+
atoms.arrays["arr"] = np.zeros_like(atoms.get_positions())
83+
84+
schema = Properties1D.model_json_schema_from_atoms(s22_energy_forces[0])
85+
assert set(schema["properties"]["value"]["enum"]) == {
86+
"energy",
87+
"forces",
88+
"custom",
89+
"numbers",
90+
"positions",
91+
"arr",
92+
"custom2",
93+
"custom3",
94+
"custom4",
95+
}

tests/test_geometries.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_geometry_selection_position(server):
4848
"height": 10,
4949
}
5050
vis.socket.emit("room:worker:run")
51-
vis.socket.sleep(5)
51+
vis.socket.sleep(8)
5252

5353
assert len(vis.geometries) == 1
5454
assert vis.geometries[0].position == [0, 0, 0]
@@ -66,7 +66,7 @@ def test_geometry_selection_position(server):
6666
"height": 10,
6767
}
6868
vis.socket.emit("room:worker:run")
69-
vis.socket.sleep(5)
69+
vis.socket.sleep(8)
7070

7171
assert len(vis.geometries) == 2
7272
assert vis.geometries[1].position == vis.atoms.positions[1].tolist()
@@ -85,7 +85,7 @@ def test_geometry_selection_position(server):
8585
"height": 10,
8686
}
8787
vis.socket.emit("room:worker:run")
88-
vis.socket.sleep(5)
88+
vis.socket.sleep(8)
8989

9090
assert len(vis.geometries) == 3
9191
assert (

tests/test_modifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def run_queue(vis, key, msg: dict):
1616
)
1717
modifier_queue.update(msg)
1818
vis.socket.emit("room:worker:run")
19-
vis.socket.sleep(5)
19+
vis.socket.sleep(10)
2020

2121

2222
def test_run_selection(server, s22):

uv.lock

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zndraw/analyse/__init__.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
pass
2020

2121

22+
def _get_available_properties(atoms: ase.Atoms) -> list[str]:
23+
available_properties = list(atoms.arrays.keys())
24+
available_properties += list(atoms.info.keys())
25+
if atoms.calc is not None:
26+
available_properties += list(atoms.calc.results.keys())
27+
return available_properties
28+
29+
2230
log = logging.getLogger(__name__)
2331

2432

@@ -130,10 +138,7 @@ class Properties2D(AnaylsisMethod):
130138
def model_json_schema_from_atoms(cls, atoms: ase.Atoms) -> dict:
131139
schema = cls.model_json_schema()
132140

133-
available_properties = list(atoms.arrays.keys())
134-
available_properties += list(atoms.info.keys())
135-
if atoms.calc is not None:
136-
available_properties += list(atoms.calc.results.keys()) # global ATOMS object
141+
available_properties = _get_available_properties(atoms)
137142

138143
available_properties += ["step"]
139144
schema["properties"]["x_data"]["enum"] = available_properties
@@ -195,10 +200,7 @@ class ForceCorrelation(AnaylsisMethod):
195200
def model_json_schema_from_atoms(cls, atoms: ase.Atoms) -> dict:
196201
schema = cls.model_json_schema()
197202

198-
available_properties = list(atoms.arrays.keys())
199-
available_properties += list(atoms.info.keys())
200-
if atoms.calc is not None:
201-
available_properties += list(atoms.calc.results.keys())
203+
available_properties = _get_available_properties(atoms)
202204
schema["properties"]["x_data"]["enum"] = available_properties
203205
schema["properties"]["y_data"]["enum"] = available_properties
204206

@@ -254,11 +256,7 @@ class Properties1D(AnaylsisMethod):
254256
def model_json_schema_from_atoms(cls, atoms: ase.Atoms) -> dict:
255257
schema = cls.model_json_schema()
256258

257-
available_properties = list(atoms.arrays.keys())
258-
available_properties += list(atoms.info.keys())
259-
if atoms.calc is not None:
260-
available_properties += list(atoms.calc.results.keys())
261-
log.critical(f"AVAILABLE PROPERTIES: {available_properties=}")
259+
available_properties = _get_available_properties(atoms)
262260
schema["properties"]["value"]["enum"] = available_properties
263261

264262
return schema

0 commit comments

Comments
 (0)