Skip to content

Commit

Permalink
MNT: enforce that reg_root is absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
tacaswell committed Jan 10, 2024
1 parent a0a79e2 commit c69619c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ophyd/areadetector/filestore_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions ophyd/tests/test_areadetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c69619c

Please sign in to comment.