diff options
author | Frederick Muriuki Muriithi | 2022-04-25 08:08:08 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-04-25 08:08:08 +0300 |
commit | 20c4028f567f0d4b5df1b80f1b6bea1bc99887b4 (patch) | |
tree | 49a2eaf24d6fb700de69f0cd6f264cacad62cd92 /tests/qc | |
parent | 043d83d1cadd5b5abfa418ac02773c7a979c611d (diff) | |
download | gn-uploader-20c4028f567f0d4b5df1b80f1b6bea1bc99887b4.tar.gz |
`take`: function to select a few items from an iterable
To avoid processing all the items in an iterable, the `take` function
is added in this commit. It realised a limited number (specified at
call time) of items from the iterable given.
Diffstat (limited to 'tests/qc')
-rw-r--r-- | tests/qc/test_error_collection.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tests/qc/test_error_collection.py b/tests/qc/test_error_collection.py index c45803a..f1bd8b9 100644 --- a/tests/qc/test_error_collection.py +++ b/tests/qc/test_error_collection.py @@ -1,6 +1,6 @@ import pytest -from quality_control.parsing import FileType, parse_errors +from quality_control.parsing import take, FileType, parse_errors @pytest.mark.slow @pytest.mark.parametrize( @@ -14,8 +14,7 @@ from quality_control.parsing import FileType, parse_errors FileType.STANDARD_ERROR, 0), ("tests/test_data/standarderror.tsv", FileType.STANDARD_ERROR, 0), ("tests/test_data/duplicated_headers_no_data_errors.tsv", - FileType.AVERAGE), - )) + FileType.AVERAGE, 0))) def test_parse_errors(filepath, filetype, strains, seek_pos): """ Check that only errors are returned, and that certain properties hold for @@ -28,3 +27,14 @@ def test_parse_errors(filepath, filetype, strains, seek_pos): assert "position" in error assert "error" in error and isinstance(error["error"], str) assert "message" in error + + +@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): + taken = take(sample, num) + assert len(taken) <= num + assert taken == expected |