From fd978c40f7c46f36608bb400ab19dd3951c28964 Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Tue, 17 Nov 2026 10:37:30 +0100 Subject: [PATCH 1/2] test: skip on windows --- packages/essreduce/tests/nexus/merge_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/essreduce/tests/nexus/merge_test.py b/packages/essreduce/tests/nexus/merge_test.py index 10f10c6d9..cf81ef83d 100644 --- a/packages/essreduce/tests/nexus/merge_test.py +++ b/packages/essreduce/tests/nexus/merge_test.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2026 Scipp contributors (https://github.com/scipp) +import sys from collections.abc import Callable from pathlib import Path @@ -309,6 +310,9 @@ def test_write_merges_three_runs(tmp_path: Path) -> None: assert list(f[f'{TEMPERATURE}/cue_index']) == [0, 1, 2] +@pytest.mark.skipif( + sys.platform == 'win32', reason='chmod cannot disable reads on Windows' +) def test_write_leaves_no_file_if_writing_fails( runs: list[Path], tmp_path: Path ) -> None: From 6e73d106e0b68f7f954319b7d8d38fc384886565 Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Thu, 19 Nov 2026 12:28:58 +0000 Subject: [PATCH 2/2] Make write-failure test portable instead of skipping on Windows chmod(0) does not prevent reads on Windows. Overwrite the second input with zeros of the same size and restore its modification time instead: opening it fails after the partial file exists, while the size and modification time check in write still passes. Deleting the file would not work, since that check would then fail before the partial file is created and the cleanup would go untested. Document in the write docstring why a partial output must not exist. Co-Authored-By: Claude Opus 5.5 --- .../essreduce/src/ess/reduce/nexus/merge.py | 4 +++- packages/essreduce/tests/nexus/merge_test.py | 19 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/essreduce/src/ess/reduce/nexus/merge.py b/packages/essreduce/src/ess/reduce/nexus/merge.py index 9278bea70..8c3b906ca 100644 --- a/packages/essreduce/src/ess/reduce/nexus/merge.py +++ b/packages/essreduce/src/ess/reduce/nexus/merge.py @@ -300,7 +300,9 @@ def write(self, output: Path | str) -> Path: Write the merged file. The file is written under a temporary name next to ``output`` and renamed - when complete, so ``output`` never holds a partial file. + when complete, so ``output`` never holds a partial file. A partial file + would look valid: it starts as a copy of the first run's file, so + reducing it would silently give wrong results. Parameters ---------- diff --git a/packages/essreduce/tests/nexus/merge_test.py b/packages/essreduce/tests/nexus/merge_test.py index cf81ef83d..ced1766a9 100644 --- a/packages/essreduce/tests/nexus/merge_test.py +++ b/packages/essreduce/tests/nexus/merge_test.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2026 Scipp contributors (https://github.com/scipp) -import sys +import os from collections.abc import Callable from pathlib import Path @@ -310,19 +310,18 @@ def test_write_merges_three_runs(tmp_path: Path) -> None: assert list(f[f'{TEMPERATURE}/cue_index']) == [0, 1, 2] -@pytest.mark.skipif( - sys.platform == 'win32', reason='chmod cannot disable reads on Windows' -) def test_write_leaves_no_file_if_writing_fails( runs: list[Path], tmp_path: Path ) -> None: plan = plan_merge(runs, RULES) - plan.files[1].chmod(0) # keeps the size and modification time - try: - with pytest.raises(OSError, match='nable to'): - plan.write(tmp_path / 'merged.nxs') - finally: - plan.files[1].chmod(0o644) + # Make opening the second file fail, after the partial file was created. + # Size and modification time must stay the same, or `write` refuses earlier. + path = plan.files[1] + stat = path.stat() + path.write_bytes(b'\0' * stat.st_size) + os.utime(path, ns=(stat.st_atime_ns, stat.st_mtime_ns)) + with pytest.raises(OSError, match='file signature not found'): + plan.write(tmp_path / 'merged.nxs') assert sorted(p.name for p in tmp_path.iterdir()) == ['a.nxs', 'b.nxs']