From 5e8b6fc2933a2b2b2e788d432c8408317ac4a5cc Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Fri, 6 Sep 2024 15:48:57 +0100 Subject: [PATCH 1/3] Make sure to add trailing slash on paths --- src/dodal/devices/detector/detector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dodal/devices/detector/detector.py b/src/dodal/devices/detector/detector.py index 8d0cd51e95..96b4112f01 100644 --- a/src/dodal/devices/detector/detector.py +++ b/src/dodal/devices/detector/detector.py @@ -79,7 +79,7 @@ def _parse_detector_size_constants(cls, det_type: str) -> DetectorSizeConstants: def _parse_directory(cls, directory: str | Path) -> str: path = Path(directory) assert path.is_dir() - return str(path) + return f"{path}/" def get_beam_position_mm(self, detector_distance: float) -> tuple[float, float]: x_beam_mm = self.beam_xy_converter.get_beam_xy_from_det_dist( From a6e897f258d842d5ecb240997c5e18e1e932150d Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Fri, 6 Sep 2024 15:56:05 +0100 Subject: [PATCH 2/3] Fix unit tests --- tests/devices/unit_tests/detector/test_detector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/devices/unit_tests/detector/test_detector.py b/tests/devices/unit_tests/detector/test_detector.py index f6ba3ddc3c..25a57978db 100644 --- a/tests/devices/unit_tests/detector/test_detector.py +++ b/tests/devices/unit_tests/detector/test_detector.py @@ -28,7 +28,7 @@ def create_det_params_with_dir_and_prefix(directory: str | Path, prefix="test"): def test_if_string_provided_check_is_dir(tmp_path: Path): assert not (_dir := str(tmp_path)).endswith("/") params = create_det_params_with_dir_and_prefix(_dir) - assert params.directory == str(tmp_path) + assert params.directory == f"{tmp_path}/" file_path = tmp_path / "foo.h5" file_path.touch() with pytest.raises(ValidationError): @@ -37,7 +37,7 @@ def test_if_string_provided_check_is_dir(tmp_path: Path): def test_if_path_provided_check_is_dir(tmp_path: Path): params = create_det_params_with_dir_and_prefix(tmp_path) - assert params.directory == str(tmp_path) + assert params.directory == f"{tmp_path}/" file_path = tmp_path / "foo.h5" file_path.touch() with pytest.raises(ValidationError): From 93f8f0777d84af002c48a138fb91aa4708f94225 Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Fri, 6 Sep 2024 17:14:26 +0100 Subject: [PATCH 3/3] Fix linting --- src/dodal/devices/util/lookup_tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dodal/devices/util/lookup_tables.py b/src/dodal/devices/util/lookup_tables.py index d920aa8eac..bc5cae4d99 100644 --- a/src/dodal/devices/util/lookup_tables.py +++ b/src/dodal/devices/util/lookup_tables.py @@ -27,7 +27,7 @@ async def energy_distance_table(lookup_table_path: str) -> np.ndarray: # Slight cheat to make the file IO async, numpy doesn't do any real IO now, just # decodes the text - async with aiofiles.open(lookup_table_path, "r") as stream: + async with aiofiles.open(lookup_table_path) as stream: raw_table = await stream.read() return loadtxt(StringIO(raw_table), comments=["#", "Units"])