Mercurial > repos > padge > clipkit
comparison clipkit_repo/tests/unit/test_files.py @ 0:49b058e85902 draft
"planemo upload for repository https://github.com/jlsteenwyk/clipkit commit cbe1e8577ecb1a46709034a40dff36052e876e7a-dirty"
author | padge |
---|---|
date | Fri, 25 Mar 2022 13:04:31 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:49b058e85902 |
---|---|
1 import pytest | |
2 from pathlib import Path | |
3 | |
4 from Bio import AlignIO | |
5 from clipkit.files import get_alignment_and_format, FileFormat | |
6 | |
7 here = Path(__file__) | |
8 | |
9 | |
10 class TestAutomaticFileTypeDetermination(object): | |
11 def test_get_alignment_and_format_when_format_is_provided(self): | |
12 # setup | |
13 in_file = f"{here.parent}/examples/simple.fa" | |
14 file_format = 'fasta' | |
15 | |
16 # execution | |
17 alignment, in_file_format = get_alignment_and_format(in_file, file_format) | |
18 | |
19 # check results | |
20 assert in_file_format == FileFormat.fasta | |
21 assert alignment.get_alignment_length() == 6 | |
22 | |
23 def test_get_alignment_and_format_when_format_is_not_provided(self): | |
24 # setup | |
25 in_file = f"{here.parent}/examples/simple.fa" | |
26 file_format = None | |
27 | |
28 # execution | |
29 alignment, in_file_format = get_alignment_and_format(in_file, file_format) | |
30 | |
31 # check results | |
32 assert in_file_format == FileFormat.fasta | |
33 assert alignment.get_alignment_length() == 6 | |
34 | |
35 def test_get_alignment_and_format_raises_error_when_file_not_known(self, mocker): | |
36 in_file = "" | |
37 file_format = None | |
38 mocker.patch("clipkit.files.AlignIO.read", side_effect=ValueError()) | |
39 | |
40 with pytest.raises(Exception) as excinfo: | |
41 get_alignment_and_format(in_file, file_format) | |
42 assert "No such file or directory" in str(excinfo.value) | |
43 | |
44 def test_get_alignment_and_format_raises_error_when_detection_fails(self, mocker): | |
45 in_file = f"{here.parent}/examples/simple.fa" | |
46 file_format = None | |
47 mocker.patch("clipkit.files.AlignIO.read", side_effect=ValueError()) | |
48 | |
49 with pytest.raises(Exception) as excinfo: | |
50 get_alignment_and_format(in_file, file_format) | |
51 assert "Input file could not be read" in str(excinfo.value) |