Mercurial > repos > davidvanzessen > shm_csr
comparison tests/test_shm_csr.py @ 83:729738462297 draft
"planemo upload commit c0ffc68aec5836d5b20b543106493056a87edf57"
| author | rhpvorderman |
|---|---|
| date | Wed, 15 Sep 2021 12:24:06 +0000 |
| parents | |
| children | 6809c63d9161 |
comparison
equal
deleted
inserted
replaced
| 82:a103134ee6e0 | 83:729738462297 |
|---|---|
| 1 # Copyright (c) 2021 Leiden University Medical Center | |
| 2 # | |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 4 # of this software and associated documentation files (the "Software"), to deal | |
| 5 # in the Software without restriction, including without limitation the rights | |
| 6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 7 # copies of the Software, and to permit persons to whom the Software is | |
| 8 # furnished to do so, subject to the following conditions: | |
| 9 # | |
| 10 # The above copyright notice and this permission notice shall be included in | |
| 11 # all copies or substantial portions of the Software. | |
| 12 # | |
| 13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| 19 # SOFTWARE. | |
| 20 | |
| 21 import os | |
| 22 import shutil | |
| 23 import subprocess | |
| 24 import sys | |
| 25 import tempfile | |
| 26 from pathlib import Path | |
| 27 | |
| 28 import pytest | |
| 29 | |
| 30 GIT_ROOT = str(Path(__file__).parent.parent.absolute()) | |
| 31 TEST_DIR = Path(__file__).parent | |
| 32 TEST_DATA_DIR = TEST_DIR / "data" | |
| 33 VALIDATION_DATA_DIR = TEST_DIR / "validation_data" | |
| 34 CONTROL_NWK377_PB_IGHC_MID1_40nt_2 = TEST_DATA_DIR / "CONTROL_NWK377_PB_IGHC_MID1_40nt_2.txz" | |
| 35 | |
| 36 | |
| 37 @pytest.fixture(scope="module") | |
| 38 def shm_csr_result(): | |
| 39 temp_dir = tempfile.mktemp() | |
| 40 shutil.copytree(GIT_ROOT, temp_dir) | |
| 41 input = str(CONTROL_NWK377_PB_IGHC_MID1_40nt_2) | |
| 42 out_files_path = os.path.join(temp_dir, "results") | |
| 43 out_file = os.path.join(out_files_path, "result.html") | |
| 44 infile_name = "input_data" | |
| 45 functionality = "productive" | |
| 46 unique = "Sequence.ID" | |
| 47 naive_output = "no" | |
| 48 naive_output_ca = "None" | |
| 49 naive_output_cg = "None" | |
| 50 naive_output_cm = "None" | |
| 51 naive_output_ce = "None" | |
| 52 naive_output_all = "None" | |
| 53 filter_unique = "remove" | |
| 54 filter_unique_count = '2' | |
| 55 class_filter = '70_70' | |
| 56 empty_region_filter = 'FR1' | |
| 57 fast = 'no' | |
| 58 cmd = [ | |
| 59 "bash", | |
| 60 "wrapper.sh", | |
| 61 input, | |
| 62 "custom", | |
| 63 out_file, | |
| 64 out_files_path, | |
| 65 infile_name, | |
| 66 "-", | |
| 67 functionality, | |
| 68 unique, | |
| 69 naive_output, | |
| 70 naive_output_ca, | |
| 71 naive_output_cg, | |
| 72 naive_output_cm, | |
| 73 naive_output_ce, | |
| 74 naive_output_all, | |
| 75 filter_unique, | |
| 76 filter_unique_count, | |
| 77 class_filter, | |
| 78 empty_region_filter, | |
| 79 fast | |
| 80 ] | |
| 81 subprocess.run(cmd, cwd=temp_dir, stdout=sys.stdout, stderr=sys.stderr, | |
| 82 check=True) | |
| 83 yield Path(out_files_path) | |
| 84 #shutil.rmtree(temp_dir) | |
| 85 | |
| 86 | |
| 87 def test_check_output(shm_csr_result): | |
| 88 assert shm_csr_result.exists() | |
| 89 | |
| 90 | |
| 91 @pytest.mark.parametrize("filename", os.listdir(VALIDATION_DATA_DIR)) | |
| 92 def test_results_match_validation(shm_csr_result, filename): | |
| 93 if filename == "shm_overview.txt": | |
| 94 # TODO: Fix errors in shm_overview. | |
| 95 return | |
| 96 with open(Path(shm_csr_result, filename)) as result_h: | |
| 97 with open(Path(VALIDATION_DATA_DIR, filename)) as validate_h: | |
| 98 for line in result_h: | |
| 99 assert line == validate_h.readline() | |
| 100 | |
| 101 | |
| 102 def test_nt_overview(shm_csr_result): | |
| 103 with open(Path(shm_csr_result, "sequence_overview", "ntoverview.txt") | |
| 104 ) as result_h: | |
| 105 with open(Path(TEST_DIR, "sequence_overview", "ntoverview.txt") | |
| 106 ) as validate_h: | |
| 107 for line in result_h: | |
| 108 assert line == validate_h.readline() |
