diff options
Diffstat (limited to 'tests/qc/test_header.py')
-rw-r--r-- | tests/qc/test_header.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/qc/test_header.py b/tests/qc/test_header.py index 6ca9376..f860a71 100644 --- a/tests/qc/test_header.py +++ b/tests/qc/test_header.py @@ -4,7 +4,10 @@ from hypothesis import given from hypothesis import strategies as st from quality_control.headers import valid_header +from quality_control.errors import InvalidValue, DuplicateHeading from quality_control.errors import DuplicateHeader, InvalidHeaderValue +from quality_control.headers import ( + invalid_header, invalid_headings, duplicate_headings) @given(headers=st.lists(st.text(max_size=10))) def test_valid_header_errors_with_invalid_headers(headers): @@ -31,3 +34,58 @@ def test_valid_header_fails_with_duplicate_headers(strains, headers): """Check that parsing fails if any header is duplicated""" with pytest.raises(DuplicateHeader): valid_header(strains, headers) + +## ============================================================ + +@given(headers=st.lists(st.text(max_size=10), max_size=1)) +def test_invalid_header_with_list_of_one_value(headers): + assert invalid_header(0, headers) == InvalidValue( + 0, 0, "<TAB>".join(headers), + "The header MUST contain at least 2 columns") + +@given(headings=st.lists(st.text(min_size=2, max_size=10), min_size=2)) +def test_invalid_headings_with_invalid_inputs(headings): + "Verify that the check for header validity works" + assert invalid_headings(0, ("BXD1", "BXD2", "BXD3"), headings) == tuple( + InvalidValue(0, col, heading, f"'{heading}' not a valid strain.") + for col, heading in enumerate(headings, start=2)) + +@pytest.mark.parametrize( + "strains,headers", [ + (("BXD1", "BXD2", "BXD3"), ("ProbeSet", "BXD3", "BXD1")), + (("AStrain", "AnotherStrain", "YetAnotherStrain"), + ("Individual", "AStrain", "AnotherStrain", "YetAnotherStrain"))]) +def test_invalid_header_with_valid_headers(strains, headers): + "Verify that the check for header validity works" + assert invalid_header(0, headers) == None + +@pytest.mark.parametrize( + "strains,headings", [ + (("BXD1", "BXD2", "BXD3"), ("BXD3", "BXD1")), + (("AStrain", "AnotherStrain", "YetAnotherStrain"), + ("AStrain", "AnotherStrain", "YetAnotherStrain"))]) +def test_invalid_headings_with_valid_headings(strains, headings): + "Verify that the check for header validity works" + assert invalid_headings(0, strains, headings) == tuple() + +@pytest.mark.parametrize( + "headers,repeated", [ + (("ProbeSet", "BXD3", "BXD1", "BXD1"), {"BXD1": (3, 4)}), + (("Individual", "AStrain", "AnotherStrain", "YetAnotherStrain", + "AStrain"), {"AStrain": (2, 5)})]) +def test_duplicate_headers_with_repeated_column_headings(headers, repeated): + """Check that parsing fails if any header is duplicated""" + assert duplicate_headings(0, headers) == tuple( + DuplicateHeading(0, head, cols, ( + f"Heading '{head}', is repeated in columns " + f"{','.join(str(i) for i in cols)}")) + for head, cols in repeated.items()) + +@pytest.mark.parametrize( + "headers", [ + (("ProbeSet", "BXD3", "BXD1")), + (("Individual", "AStrain", "AnotherStrain", "YetAnotherStrain",))]) +def test_duplicate_headers_with_unique_column_headings(headers): + """Check that parsing fails if any header is duplicated""" + assert duplicate_headings(0, headers) == tuple() + |