From aa6bdfc390a22734cfd356a45b99a8cf2032e992 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 13 Apr 2022 12:26:38 +0300 Subject: Update `valid_header` to pass check for duplicated headers --- quality_control/headers.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'quality_control') diff --git a/quality_control/headers.py b/quality_control/headers.py index 59d3d77..b7bc01e 100644 --- a/quality_control/headers.py +++ b/quality_control/headers.py @@ -1,6 +1,6 @@ """Validate the headers""" -from quality_control.errors import InvalidHeaderValue +from quality_control.errors import DuplicateHeader, InvalidHeaderValue def valid_header(strains, headers): "Return the valid headers with reference to strains or throw an error" @@ -13,4 +13,13 @@ def valid_header(strains, headers): raise InvalidHeaderValue( *(f"'{header}' not a valid strain." for header in invalid_headers)) + unique_headers = set(headers) + if len(unique_headers) != len(headers): + repeated = ( + (header, headers.count(header)) + for header in unique_headers if headers.count(header) > 1) + raise DuplicateHeader(*( + f"'{header}' is present in the header row {times} times." + for header, times in repeated)) + return headers -- cgit v1.2.3