diff options
author | Frederick Muriuki Muriithi | 2022-04-13 12:26:38 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-04-13 12:26:38 +0300 |
commit | aa6bdfc390a22734cfd356a45b99a8cf2032e992 (patch) | |
tree | f4c7ad57048f077df20b5af2325711b9f729dae6 | |
parent | de22890b9c10ece94560dc91a8de2ca3bdb5944b (diff) | |
download | gn-uploader-aa6bdfc390a22734cfd356a45b99a8cf2032e992.tar.gz |
Update `valid_header` to pass check for duplicated headers
-rw-r--r-- | quality_control/headers.py | 11 |
1 files changed, 10 insertions, 1 deletions
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 |