aboutsummaryrefslogtreecommitdiff
path: root/tests/qc/test_error_collection.py
blob: fe85bb1d1231a106d441a173b4a899db78442929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Check that error collection works as expected"""

import pytest

from quality_control.errors import InvalidValue, DuplicateHeading
from quality_control.parsing import take, FileType, collect_errors

@pytest.mark.parametrize(
    "sample,num,expected",
    ((range(0,25), 5, [0, 1, 2, 3, 4]),
     ([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",
    (("tests/test_data/average_crlf.tsv", FileType.AVERAGE, 10),
     ("tests/test_data/average_error_at_end_200MB.tsv", FileType.AVERAGE,
      20),
     ("tests/test_data/average.tsv", FileType.AVERAGE, 5),
     ("tests/test_data/standarderror_1_error_at_end.tsv",
      FileType.STANDARD_ERROR, 13),
     ("tests/test_data/standarderror.tsv", FileType.STANDARD_ERROR, 9),
     ("tests/test_data/duplicated_headers_no_data_errors.tsv",
      FileType.AVERAGE, 10)))
def test_collect_errors(filepath, filetype, strains, 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)