Skip to content

Commit 271ea3a

Browse files
authored
Merge pull request #98 from scipp/fix-flaky-test
fix: silence warnings explicitly in the tests and in the notebook
2 parents 15a7cef + ef61cfc commit 271ea3a

File tree

4 files changed

+19
-30
lines changed

4 files changed

+19
-30
lines changed

docs/user-guide/amor/amor-reduction.ipynb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27+
"import warnings\n",
2728
"import scipp as sc\n",
2829
"from ess import amor\n",
2930
"from ess.amor import data # noqa: F401\n",
3031
"from ess.reflectometry.types import *\n",
31-
"from ess.amor.types import *"
32+
"from ess.amor.types import *\n",
33+
"\n",
34+
"# The files used in this tutorial have some issues that makes scippnexus\n",
35+
"# raise warnings when loading them. To avoid noise in the notebook the warnings are silenced.\n",
36+
"warnings.filterwarnings('ignore', 'Failed to convert .* into a transformation')\n",
37+
"warnings.filterwarnings('ignore', 'Invalid transformation, missing attribute')"
3238
]
3339
},
3440
{

docs/user-guide/amor/compare-to-eos.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"metadata": {},
1919
"outputs": [],
2020
"source": [
21+
"import warnings\n",
2122
"import orsopy\n",
2223
"import matplotlib.pyplot as plt\n",
2324
"\n",
@@ -26,7 +27,12 @@
2627
"from ess import amor\n",
2728
"from ess.amor import data # noqa: F401\n",
2829
"from ess.reflectometry.types import *\n",
29-
"from ess.amor.types import ChopperPhase"
30+
"from ess.amor.types import ChopperPhase\n",
31+
"\n",
32+
"# The files used in this tutorial have some issues that makes scippnexus\n",
33+
"# raise warnings when loading them. To avoid noise in the notebook the warnings are silenced.\n",
34+
"warnings.filterwarnings('ignore', 'Failed to convert .* into a transformation')\n",
35+
"warnings.filterwarnings('ignore', 'Invalid transformation, missing attribute')"
3036
]
3137
},
3238
{
@@ -225,7 +231,7 @@
225231
"name": "python",
226232
"nbconvert_exporter": "python",
227233
"pygments_lexer": "ipython3",
228-
"version": "3.10.13"
234+
"version": "3.10.14"
229235
}
230236
},
231237
"nbformat": 4,

src/ess/amor/load.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3-
import warnings
4-
from functools import wraps
5-
63
import scipp as sc
74

85
from ..reflectometry.load import load_nx
@@ -26,33 +23,12 @@
2623
)
2724

2825

29-
def ignore_amor_warnings(func):
30-
@wraps(func)
31-
def wrapped(*args, **kwargs):
32-
with warnings.catch_warnings():
33-
warnings.filterwarnings(
34-
'ignore',
35-
category=UserWarning,
36-
message=r'Failed to convert .* into a transformation',
37-
)
38-
warnings.filterwarnings(
39-
'ignore',
40-
category=UserWarning,
41-
message='Invalid transformation, missing attribute',
42-
)
43-
return func(*args, **kwargs)
44-
45-
return wrapped
46-
47-
48-
@ignore_amor_warnings
4926
def load_detector(
5027
file_path: Filename[RunType], detector_name: NeXusDetectorName[RunType]
5128
) -> LoadedNeXusDetector[RunType]:
5229
return next(load_nx(file_path, f"NXentry/NXinstrument/{detector_name}"))
5330

5431

55-
@ignore_amor_warnings
5632
def load_events(
5733
detector: LoadedNeXusDetector[RunType], detector_rotation: DetectorRotation[RunType]
5834
) -> RawDetectorData[RunType]:
@@ -130,7 +106,6 @@ def compute_tof(
130106
return ReducibleDetectorData[RunType](data)
131107

132108

133-
@ignore_amor_warnings
134109
def amor_chopper(f: Filename[RunType]) -> RawChopper[RunType]:
135110
return next(load_nx(f, "NXentry/NXinstrument/NXdisk_chopper"))
136111

@@ -163,7 +138,6 @@ def load_amor_ch_frequency(ch: RawChopper[RunType]) -> ChopperFrequency[RunType]
163138
raise ValueError("No unit was found for the chopper frequency")
164139

165140

166-
@ignore_amor_warnings
167141
def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]:
168142
(mu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/mu")
169143
# Jochens Amor code reads the first value of this log
@@ -172,7 +146,6 @@ def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]:
172146
return sc.scalar(mu['value'].data['dim_1', 0]['time', 0].value, unit='deg')
173147

174148

175-
@ignore_amor_warnings
176149
def load_amor_detector_rotation(fp: Filename[RunType]) -> DetectorRotation[RunType]:
177150
(nu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/nu")
178151
# Jochens Amor code reads the first value of this log

tests/amor/pipeline_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ def amor_pipeline() -> sciline.Pipeline:
5656
return pl
5757

5858

59+
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
60+
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
5961
def test_run_data_pipeline(amor_pipeline: sciline.Pipeline):
6062
res = amor_pipeline.compute(ReflectivityOverQ)
6163
assert "Q" in res.coords
6264
assert "Q_resolution" in res.coords
6365

6466

67+
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
68+
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
6569
def test_run_full_pipeline(amor_pipeline: sciline.Pipeline):
6670
res = amor_pipeline.compute(orso.OrsoIofQDataset)
6771
assert res.info.data_source.experiment.instrument == "Amor"

0 commit comments

Comments
 (0)