From 7e094ae5ecceec5b9fda9bcc0622ea255980eea4 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 9 Jan 2024 18:54:05 -0500 Subject: [PATCH] MNT: enforce that reg_root is absolute --- ophyd/areadetector/filestore_mixins.py | 3 +++ ophyd/tests/test_areadetector.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ophyd/areadetector/filestore_mixins.py b/ophyd/areadetector/filestore_mixins.py index 9882ece78..602dbb201 100644 --- a/ophyd/areadetector/filestore_mixins.py +++ b/ophyd/areadetector/filestore_mixins.py @@ -225,6 +225,9 @@ def reg_root(self): def reg_root(self, val): if val is None: val = os.path.sep + root = PurePath(val) + if not root.is_absolute(): + raise ValueError(f"The root part of the path must be absolute not {root=}.") self._root = PurePath(val) @property diff --git a/ophyd/tests/test_areadetector.py b/ophyd/tests/test_areadetector.py index 3903eaa68..abddd8efe 100644 --- a/ophyd/tests/test_areadetector.py +++ b/ophyd/tests/test_areadetector.py @@ -768,6 +768,29 @@ def test_file_store_paths_can_change(mock_now: Mock) -> None: check_file_store_paths(file_store, test_case) +def test_no_relative_root(mock_now: Mock) -> None: + fs = DummyFS() + + file_store = DummyFileStorePlugin( + name="test_file_store", + write_path_template="", + read_path_template="", + root=None, + reg=fs, + ) + with pytest.raises(ValueError, match="The root part of the path must be absolute"): + file_store.reg_root = "." + + with pytest.raises(ValueError, match="The root part of the path must be absolute"): + file_store = DummyFileStorePlugin( + name="test_file_store", + write_path_template="", + read_path_template="", + root=".", + reg=fs, + ) + + def check_file_store_paths( file_store: DummyFileStorePlugin, test_case: FileStorePathTestCase,