diff --git a/libra_toolbox/tritium/lsc_measurements.py b/libra_toolbox/tritium/lsc_measurements.py index ec2b8e3..3511d93 100644 --- a/libra_toolbox/tritium/lsc_measurements.py +++ b/libra_toolbox/tritium/lsc_measurements.py @@ -76,6 +76,8 @@ def substract_background(self, background_sample: "LSCSample"): @staticmethod def from_file(file_reader: LSCFileReader, vial_name): values = file_reader.get_bq1_values_with_labels() + if vial_name not in values: + raise ValueError(f"Vial {vial_name} not found in the file reader.") activity = values[vial_name] * ureg.Bq return LSCSample(activity, vial_name) diff --git a/test/tritium/test_lsc_samples.py b/test/tritium/test_lsc_samples.py index 1fe6577..c3a2760 100644 --- a/test/tritium/test_lsc_samples.py +++ b/test/tritium/test_lsc_samples.py @@ -60,3 +60,31 @@ def test_lscsample_from_file(): sample = LSCSample.from_file(file_reader, "Sample1") assert sample.activity == 0.334 * ureg.Bq assert sample.name == "Sample1" + + +def test_lscsample_from_file_when_not_found(): + file_reader = LSCFileReader( + Path(__file__).parent / "TEST_CSV.csv", + vial_labels=[ + "1L-OV-1-0-1", + "1L-OV-1-0-2", + "1L-OV-1-0-3", + "1L-OV-1-0-4", + None, + "1L-IV-1-0-1", + "1L-IV-1-0-2", + "1L-IV-1-0-3", + "1L-IV-1-0-4", + None, + "Sample1", + "1L-IV-1-1-2", + "1L-IV-1-1-3", + "1L-IV-1-1-4", + ], + ) + + file_reader.read_file() + with pytest.raises( + ValueError, match="Vial coucoucou not found in the file reader." + ): + LSCSample.from_file(file_reader, "coucoucou")