diff options
Diffstat (limited to 'tests/qc/test_error_collection.py')
-rw-r--r-- | tests/qc/test_error_collection.py | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/tests/qc/test_error_collection.py b/tests/qc/test_error_collection.py index 466f455..fe85bb1 100644 --- a/tests/qc/test_error_collection.py +++ b/tests/qc/test_error_collection.py @@ -1,33 +1,9 @@ +"""Check that error collection works as expected""" + import pytest -from quality_control.parsing import take, FileType, parse_errors -from quality_control.parsing import collect_errors - -@pytest.mark.slow -@pytest.mark.parametrize( - "filepath,filetype,seek_pos", - (("tests/test_data/average_crlf.tsv", FileType.AVERAGE, 0), - ("tests/test_data/average_error_at_end_200MB.tsv", FileType.AVERAGE, - 205500004 # Skip first 500K lines - ), - ("tests/test_data/average.tsv", FileType.AVERAGE, 0), - ("tests/test_data/standarderror_1_error_at_end.tsv", - FileType.STANDARD_ERROR, 0), - ("tests/test_data/standarderror.tsv", FileType.STANDARD_ERROR, 0), - ("tests/test_data/duplicated_headers_no_data_errors.tsv", - FileType.AVERAGE, 0))) -def test_parse_errors(filepath, filetype, strains, seek_pos): - """ - Check that only errors are returned, and that certain properties hold for - said errors. - """ - for error in parse_errors(filepath, filetype, strains, seek_pos): - assert isinstance(error, dict) - assert "filepath" in error - assert "filetype" in error - assert "position" in error - assert "error" in error and isinstance(error["error"], str) - assert "message" in error +from quality_control.errors import InvalidValue, DuplicateHeading +from quality_control.parsing import take, FileType, collect_errors @pytest.mark.parametrize( "sample,num,expected", @@ -35,13 +11,11 @@ def test_parse_errors(filepath, filetype, strains, seek_pos): ([0, 1, 2, 3], 200, [0, 1, 2, 3]), (("he", "is", "a", "lovely", "boy"), 3, ["he", "is", "a"]))) def test_take(sample, num, expected): + """Check that `take` works correctly.""" taken = take(sample, num) assert len(taken) <= num assert taken == expected - -## ================================================== - @pytest.mark.slow @pytest.mark.parametrize( "filepath,filetype,count", @@ -55,4 +29,8 @@ def test_take(sample, num, expected): ("tests/test_data/duplicated_headers_no_data_errors.tsv", FileType.AVERAGE, 10))) def test_collect_errors(filepath, filetype, strains, count): - assert len(collect_errors(filepath, filetype, strains, count)) <= count + """Check that `collect_errors` works as expected.""" + results = take(collect_errors(filepath, filetype, strains), count) + def __valid_instance(item): + return isinstance(item, (InvalidValue, DuplicateHeading)) + assert all(__valid_instance(error) for error in results) |