Skip to content

Commit ade20b1

Browse files
authored
Merge pull request #675 from FAIRmat-NFDI/fix_issue_670
Adding a test for issue670
2 parents 64dea6c + a876cb1 commit ade20b1

File tree

5 files changed

+118
-52
lines changed

5 files changed

+118
-52
lines changed

dev-requirements.txt

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# This file was autogenerated by uv via the following command:
22
# uv pip compile --universal -p 3.12 --extra=dev --extra=docs --output-file=dev-requirements.txt pyproject.toml
3-
anytree==2.12.1
3+
anytree==2.13.0
44
# via pynxtools (pyproject.toml)
5-
ase==3.24.0
5+
ase==3.25.0
66
# via pynxtools (pyproject.toml)
77
babel==2.17.0
88
# via mkdocs-material
9-
backrefs==5.8
9+
backrefs==5.9
1010
# via mkdocs-material
11-
certifi==2025.1.31
11+
certifi==2025.7.14
1212
# via requests
1313
cfgv==3.4.0
1414
# via pre-commit
15-
charset-normalizer==3.4.1
15+
charset-normalizer==3.4.2
1616
# via requests
17-
click==8.1.8
17+
click==8.2.1
1818
# via
1919
# pynxtools (pyproject.toml)
2020
# click-default-group
@@ -28,13 +28,15 @@ colorama==0.4.6
2828
# mkdocs
2929
# mkdocs-material
3030
# pytest
31-
contourpy==1.3.1
31+
contourpy==1.3.3
3232
# via matplotlib
33-
coverage==7.8.0
33+
coverage==7.10.1
3434
# via pytest-cov
3535
cycler==0.12.1
3636
# via matplotlib
37-
distlib==0.3.9
37+
debugpy==1.8.15
38+
# via pynxtools (pyproject.toml)
39+
distlib==0.4.0
3840
# via virtualenv
3941
execnet==2.1.1
4042
# via pytest-xdist
@@ -44,21 +46,21 @@ flexcache==0.3
4446
# via pint
4547
flexparser==0.4
4648
# via pint
47-
fonttools==4.57.0
49+
fonttools==4.59.0
4850
# via matplotlib
4951
ghp-import==2.1.0
5052
# via mkdocs
51-
h5py==3.13.0
53+
h5py==3.14.0
5254
# via pynxtools (pyproject.toml)
5355
hjson==3.1.0
5456
# via
5557
# mkdocs-macros-plugin
5658
# super-collections
57-
identify==2.6.9
59+
identify==2.6.12
5860
# via pre-commit
5961
idna==3.10
6062
# via requests
61-
importlib-metadata==8.6.1
63+
importlib-metadata==8.7.0
6264
# via pynxtools (pyproject.toml)
6365
iniconfig==2.1.0
6466
# via pytest
@@ -69,9 +71,9 @@ jinja2==3.1.6
6971
# mkdocs-material
7072
kiwisolver==1.4.8
7173
# via matplotlib
72-
lxml==5.3.2
74+
lxml==6.0.0
7375
# via pynxtools (pyproject.toml)
74-
markdown==3.7
76+
markdown==3.8.2
7577
# via
7678
# markdown-include
7779
# mkdocs
@@ -84,7 +86,7 @@ markupsafe==3.0.2
8486
# via
8587
# jinja2
8688
# mkdocs
87-
matplotlib==3.10.1
89+
matplotlib==3.10.3
8890
# via ase
8991
mergedeep==1.3.4
9092
# via
@@ -102,15 +104,15 @@ mkdocs-get-deps==0.2.0
102104
# via mkdocs
103105
mkdocs-macros-plugin==1.3.7
104106
# via pynxtools (pyproject.toml)
105-
mkdocs-material==9.6.11
107+
mkdocs-material==9.6.16
106108
# via pynxtools (pyproject.toml)
107109
mkdocs-material-extensions==1.3.1
108110
# via
109111
# pynxtools (pyproject.toml)
110112
# mkdocs-material
111-
mypy==1.15.0
113+
mypy==1.17.0
112114
# via pynxtools (pyproject.toml)
113-
mypy-extensions==1.0.0
115+
mypy-extensions==1.1.0
114116
# via mypy
115117
nodeenv==1.9.1
116118
# via pre-commit
@@ -124,7 +126,7 @@ numpy==1.26.4
124126
# pandas
125127
# scipy
126128
# xarray
127-
packaging==24.2
129+
packaging==25.0
128130
# via
129131
# matplotlib
130132
# mkdocs
@@ -133,44 +135,49 @@ packaging==24.2
133135
# xarray
134136
paginate==0.5.7
135137
# via mkdocs-material
136-
pandas==2.2.3
138+
pandas==2.3.1
137139
# via
138140
# pynxtools (pyproject.toml)
139141
# xarray
140142
pathspec==0.12.1
141143
# via
142144
# mkdocs
143145
# mkdocs-macros-plugin
144-
pillow==11.1.0
146+
# mypy
147+
pillow==11.3.0
145148
# via matplotlib
146149
pint==0.24.4
147150
# via pynxtools (pyproject.toml)
148-
platformdirs==4.3.7
151+
platformdirs==4.3.8
149152
# via
150153
# mkdocs-get-deps
151154
# pint
152155
# virtualenv
153-
pluggy==1.5.0
154-
# via pytest
156+
pluggy==1.6.0
157+
# via
158+
# pytest
159+
# pytest-cov
155160
pre-commit==4.2.0
156161
# via pynxtools (pyproject.toml)
157-
pygments==2.19.1
158-
# via mkdocs-material
159-
pymdown-extensions==10.14.3
162+
pygments==2.19.2
163+
# via
164+
# mkdocs-material
165+
# pytest
166+
pymdown-extensions==10.16.1
160167
# via mkdocs-material
161168
pyparsing==3.2.3
162169
# via matplotlib
163-
pytest==8.3.5
170+
pytest==8.4.1
164171
# via
165172
# pynxtools (pyproject.toml)
166173
# pytest-cov
167174
# pytest-timeout
168175
# pytest-xdist
169-
pytest-cov==6.1.1
176+
pytest-cov==6.2.1
170177
# via pynxtools (pyproject.toml)
171-
pytest-timeout==2.3.1
178+
pytest-timeout==2.4.0
172179
# via pynxtools (pyproject.toml)
173-
pytest-xdist==3.6.1
180+
pytest-xdist==3.8.0
174181
# via pynxtools (pyproject.toml)
175182
python-dateutil==2.9.0.post0
176183
# via
@@ -189,33 +196,31 @@ pyyaml==6.0.2
189196
# pre-commit
190197
# pymdown-extensions
191198
# pyyaml-env-tag
192-
pyyaml-env-tag==0.1
199+
pyyaml-env-tag==1.1
193200
# via mkdocs
194-
requests==2.32.3
201+
requests==2.32.4
195202
# via mkdocs-material
196203
ruff==0.12.5
197204
# via pynxtools (pyproject.toml)
198-
scipy==1.15.2
205+
scipy==1.16.1
199206
# via ase
200207
six==1.17.0
201-
# via
202-
# anytree
203-
# python-dateutil
204-
structlog==25.2.0
208+
# via python-dateutil
209+
structlog==25.4.0
205210
# via pynxtools (pyproject.toml)
206211
super-collections==0.5.3
207212
# via mkdocs-macros-plugin
208-
termcolor==3.0.1
213+
termcolor==3.1.0
209214
# via mkdocs-macros-plugin
210215
toposort==1.10
211216
# via pynxtools (pyproject.toml)
212-
types-pytz==2025.2.0.20250326
217+
types-pytz==2025.2.0.20250516
213218
# via pynxtools (pyproject.toml)
214-
types-pyyaml==6.0.12.20250402
219+
types-pyyaml==6.0.12.20250516
215220
# via pynxtools (pyproject.toml)
216-
types-requests==2.32.0.20250328
221+
types-requests==2.32.4.20250611
217222
# via pynxtools (pyproject.toml)
218-
typing-extensions==4.13.1
223+
typing-extensions==4.14.1
219224
# via
220225
# flexcache
221226
# flexparser
@@ -227,11 +232,11 @@ urllib3==2.5.0
227232
# via
228233
# requests
229234
# types-requests
230-
virtualenv==20.30.0
235+
virtualenv==20.32.0
231236
# via pre-commit
232237
watchdog==6.0.0
233238
# via mkdocs
234-
xarray==2025.3.1
239+
xarray==2025.7.1
235240
# via pynxtools (pyproject.toml)
236-
zipp==3.21.0
241+
zipp==3.23.0
237242
# via importlib-metadata

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ dev = [
6363
"types-pytz",
6464
"types-requests",
6565
"pre-commit",
66+
"debugpy",
6667
]
6768
convert = [
6869
"pynxtools[apm,ellips,em,igor,mpes,raman,spm,xps,xrd]",
@@ -136,7 +137,7 @@ select = [
136137
"PL", # pylint
137138
"UP", # pyupgrade
138139
# "F401", # remove unused import
139-
"I001", # sort imports
140+
"I001", # sort imports
140141
# "NPY201", # reactivate when np>2.0 is used
141142
]
142143
ignore = [

src/pynxtools/dataconverter/helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,11 @@ def is_valid_data_field(
742742
"""
743743

744744
accepted_types = NEXUS_TO_PYTHON_DATA_TYPES[nxdl_type]
745-
# Do not count the dict as it represents a link value
745+
746+
if isinstance(value, dict) and set(value.keys()) == {"compress", "strength"}:
747+
value = value["compress"]
748+
749+
# Do not count other dicts as they represent a link value
746750
if not isinstance(value, dict) and not is_valid_data_type(value, accepted_types):
747751
# try to convert string to bool
748752
if accepted_types[0] is bool and isinstance(value, str):

src/pynxtools/dataconverter/validation.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818
#
19+
DEBUG_VALIDATION = False
1920
import copy
2021
import re
2122
from collections import defaultdict
@@ -24,6 +25,8 @@
2425
from operator import getitem
2526
from typing import Any, Literal, Optional, Union
2627

28+
if DEBUG_VALIDATION:
29+
import debugpy # will connect to debugger if in debug mode
2730
import h5py
2831
import lxml.etree as ET
2932
import numpy as np
@@ -44,6 +47,11 @@
4447
from pynxtools.definitions.dev_tools.utils.nxdl_utils import get_nx_namefit
4548
from pynxtools.units import NXUnitSet, ureg
4649

50+
if DEBUG_VALIDATION:
51+
debugpy.debug_this_thread()
52+
# set break points like this
53+
# debugpy.breakpoint()
54+
4755

4856
def validate_hdf_group_against(appdef: str, data: h5py.Group):
4957
"""
@@ -599,8 +607,10 @@ def handle_field(node: NexusNode, keys: Mapping[str, Any], prev_path: str):
599607
for variant in variants:
600608
variant_path = f"{prev_path}/{variant}"
601609

602-
if isinstance(keys[variant], Mapping) and not all(
603-
k.startswith("@") for k in keys[variant]
610+
if (
611+
isinstance(keys[variant], Mapping)
612+
and not all(k.startswith("@") for k in keys[variant])
613+
and not list(keys[variant].keys()) == ["compress", "strength"]
604614
):
605615
# A field should not have a dict of keys that are _not_ all attributes,
606616
# i.e. no sub-fields or sub-groups.
@@ -811,7 +821,7 @@ def is_documented(key: str, tree: NexusNode) -> bool:
811821
# Collection found, mark as documented
812822
return True
813823

814-
if isinstance(mapping[key], dict) and "link" in mapping[key]:
824+
if isinstance(mapping[key], Mapping) and "link" in mapping[key]:
815825
resolved_link = _follow_link({key: mapping[key]}, "")
816826

817827
if key not in resolved_link:

tests/dataconverter/test_validation.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,52 @@ def listify_template(data_dict: Template):
16931693
],
16941694
id="reserved-prefix",
16951695
),
1696+
pytest.param(
1697+
alter_dict(
1698+
TEMPLATE,
1699+
"/ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value",
1700+
{"compress": np.float32(2.0), "strength": 1},
1701+
),
1702+
[],
1703+
id="appdef-compressed-payload",
1704+
),
1705+
pytest.param(
1706+
alter_dict(
1707+
TEMPLATE,
1708+
"/ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value",
1709+
{"compress": np.int64(2.0), "strength": 1},
1710+
),
1711+
[
1712+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/float_value "
1713+
"should be one of the following Python types: "
1714+
"(<class 'float'>, <class 'numpy.floating'>), as defined in the "
1715+
"NXDL as NX_FLOAT."
1716+
],
1717+
id="appdef-compressed-payload-wrong-type",
1718+
),
1719+
pytest.param(
1720+
alter_dict(
1721+
TEMPLATE,
1722+
"/ENTRY[my_entry]/SAMPLE[sample1]]/changer_position",
1723+
{"compress": np.int64(2), "strength": 1},
1724+
),
1725+
[],
1726+
id="baseclass-compressed-payload",
1727+
),
1728+
pytest.param(
1729+
alter_dict(
1730+
TEMPLATE,
1731+
"/ENTRY[my_entry]/SAMPLE[sample1]]/changer_position",
1732+
{"compress": np.float32(2.0), "strength": 3},
1733+
),
1734+
[
1735+
"The value at /ENTRY[my_entry]/SAMPLE[sample1]]/changer_position "
1736+
"should be one of the following Python types: "
1737+
"(<class 'int'>, <class 'numpy.integer'>), as defined in the "
1738+
"NXDL as NX_INT."
1739+
],
1740+
id="baseclass-compressed-payload-wrong-type",
1741+
),
16961742
],
16971743
)
16981744
def test_validate_data_dict(caplog, data_dict, error_messages, request):

0 commit comments

Comments
 (0)