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..5c1b949d2 100644 --- a/ophyd/tests/test_areadetector.py +++ b/ophyd/tests/test_areadetector.py @@ -768,6 +768,31 @@ 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,