From 52a1c748ef8be5d52e7771a0f5822c3d4fdb8c63 Mon Sep 17 00:00:00 2001 From: Cyril Danilevski <cyril.danilevski@xfel.eu> Date: Mon, 29 Mar 2021 17:18:48 +0200 Subject: [PATCH] Add test for module_index_to_qm --- cal_tools/cal_tools/enums.py | 6 +++--- cal_tools/cal_tools/tools.py | 1 + tests/test_cal_tools.py | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cal_tools/cal_tools/enums.py b/cal_tools/cal_tools/enums.py index 186e17208..21d4b4f08 100644 --- a/cal_tools/cal_tools/enums.py +++ b/cal_tools/cal_tools/enums.py @@ -51,9 +51,9 @@ class SnowResolution(Enum): class AgipdGainMode(IntEnum): - """Encoding added to distinguish between adaptive and fixed gain""" + """Gain Modes where the values is 0 if Adaptive, or High/Medium/Low.""" - ADAPTIVE_GAIN = 0 # adaptive is default (if gain mode missing in slow data) - FIXED_HIGH_GAIN = 1 # non-zero means fixed gain + ADAPTIVE_GAIN = 0 + FIXED_HIGH_GAIN = 1 FIXED_MEDIUM_GAIN = 2 FIXED_LOW_GAIN = 3 diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py index a6aa3f5e8..0ddf2c132 100644 --- a/cal_tools/cal_tools/tools.py +++ b/cal_tools/cal_tools/tools.py @@ -675,6 +675,7 @@ def get_constant_from_db_and_time(karabo_id: str, karabo_da: str, def module_index_to_qm(index: int, total_modules: int = 16): """Maps module index (0-indexed) to quadrant + module string (1-indexed)""" + assert index < total_modules, f'{index} is greater than {total_modules}' modules_per_quad = total_modules // 4 quad, mod = divmod(index, modules_per_quad) return f"Q{quad+1}M{mod+1}" diff --git a/tests/test_cal_tools.py b/tests/test_cal_tools.py index 7fe26e12a..c7656d177 100644 --- a/tests/test_cal_tools.py +++ b/tests/test_cal_tools.py @@ -3,7 +3,7 @@ from pathlib import Path import pytest from cal_tools.plotting import show_processed_modules -from cal_tools.tools import get_dir_creation_date +from cal_tools.tools import get_dir_creation_date, module_index_to_qm def test_show_processed_modules(): @@ -30,3 +30,19 @@ def test_dir_creation_date(): date = get_dir_creation_date(folder, 9999) assert isinstance(date, datetime) assert str(date) == '2019-12-16 08:52:25.196603' + + +def test_module_index_to_qm(): + + assert module_index_to_qm(0) == 'Q1M1' + assert module_index_to_qm(1) == 'Q1M2' + assert module_index_to_qm(4) == 'Q2M1' + assert module_index_to_qm(6) == 'Q2M3' + + assert module_index_to_qm(4, 5) == 'Q5M1' + + with pytest.raises(AssertionError): + module_index_to_qm(18) + + with pytest.raises(AssertionError): + module_index_to_qm(7, 5) -- GitLab