Skip to content

Commit

Permalink
error message if vial name not found
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Nov 8, 2024
1 parent f04c82e commit df9c909
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libra_toolbox/tritium/lsc_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 28 additions & 0 deletions test/tritium/test_lsc_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit df9c909

Please sign in to comment.