From e68c807e6598a4087d7c83510ba33c81139f5544 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 28 Jun 2022 15:20:54 +0300 Subject: Check for inconsistent columns The number columns in each contents line should be equal to the nember of columns in the header line. --- tests/qc/test_error_collection.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests/qc') diff --git a/tests/qc/test_error_collection.py b/tests/qc/test_error_collection.py index fe85bb1..ee1e6c2 100644 --- a/tests/qc/test_error_collection.py +++ b/tests/qc/test_error_collection.py @@ -2,8 +2,9 @@ import pytest -from quality_control.errors import InvalidValue, DuplicateHeading from quality_control.parsing import take, FileType, collect_errors +from quality_control.errors import ( + InvalidValue, DuplicateHeading, InconsistentColumns) @pytest.mark.parametrize( "sample,num,expected", @@ -34,3 +35,20 @@ def test_collect_errors(filepath, filetype, strains, count): def __valid_instance(item): return isinstance(item, (InvalidValue, DuplicateHeading)) assert all(__valid_instance(error) for error in results) + +@pytest.mark.parametrize( + "filepath,filetype,expected", + (("tests/test_data/average_inconsistent_columns.tsv", FileType.AVERAGE, + (InconsistentColumns( + 4, 4, 5, "Header row has 4 columns while row 4 has 5 columns"), + InconsistentColumns( + 5, 4, 3, "Header row has 4 columns while row 5 has 3 columns"), + InconsistentColumns( + 6, 4, 7, "Header row has 4 columns while row 6 has 7 columns"))),)) +def test_collect_inconsistent_column_errors(filepath, filetype, strains, expected): + """ + Given: A file with inconsistent columns in certain lines + When: collect_errors is run on the file + Then: All the lines with inconsistent columns are flagged + """ + assert tuple(collect_errors(filepath, filetype, strains)) == expected -- cgit v1.2.3