Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: enforce that reg_root is absolute #1174

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions ophyd/tests/test_areadetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading