Mercurial > repos > davidvanzessen > shm_csr
comparison tests/test_shm_csr.py @ 90:6809c63d9161 draft
"planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
author | rhpvorderman |
---|---|
date | Tue, 25 Jan 2022 11:28:29 +0000 |
parents | 729738462297 |
children | cf8ad181628f |
comparison
equal
deleted
inserted
replaced
89:3c9d4d976c47 | 90:6809c63d9161 |
---|---|
22 import shutil | 22 import shutil |
23 import subprocess | 23 import subprocess |
24 import sys | 24 import sys |
25 import tempfile | 25 import tempfile |
26 from pathlib import Path | 26 from pathlib import Path |
27 from xml.etree import ElementTree | |
28 from xml.etree.ElementTree import Element | |
27 | 29 |
28 import pytest | 30 import pytest |
29 | 31 |
30 GIT_ROOT = str(Path(__file__).parent.parent.absolute()) | 32 GIT_ROOT = Path(__file__).parent.parent.absolute() |
31 TEST_DIR = Path(__file__).parent | 33 TEST_DIR = Path(__file__).parent |
32 TEST_DATA_DIR = TEST_DIR / "data" | 34 TEST_DATA_DIR = TEST_DIR / "data" |
33 VALIDATION_DATA_DIR = TEST_DIR / "validation_data" | 35 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" | 36 CONTROL_NWK377_PB_IGHC_MID1_40nt_2 = TEST_DATA_DIR / "CONTROL_NWK377_PB_IGHC_MID1_40nt_2.txz" |
35 | 37 |
36 | 38 |
39 def get_container(): | |
40 tool = ElementTree.parse(GIT_ROOT / "shm_csr.xml").getroot() | |
41 requirements: Element = tool.find("requirements") | |
42 container = requirements.find("container") | |
43 return container.text | |
44 | |
45 | |
37 @pytest.fixture(scope="module") | 46 @pytest.fixture(scope="module") |
38 def shm_csr_result(): | 47 def shm_csr_result(): |
39 temp_dir = tempfile.mktemp() | 48 temp_dir = Path(tempfile.mkdtemp()) |
40 shutil.copytree(GIT_ROOT, temp_dir) | 49 tool_dir = temp_dir / "shm_csr" |
50 shutil.copytree(GIT_ROOT, tool_dir) | |
51 working_dir = temp_dir / "working" | |
52 working_dir.mkdir(parents=True) | |
53 output_dir = temp_dir / "outputs" | |
54 output_dir.mkdir(parents=True) | |
55 wrapper = str(tool_dir / "wrapper.sh") | |
41 input = str(CONTROL_NWK377_PB_IGHC_MID1_40nt_2) | 56 input = str(CONTROL_NWK377_PB_IGHC_MID1_40nt_2) |
42 out_files_path = os.path.join(temp_dir, "results") | 57 out_files_path = output_dir / "results" |
43 out_file = os.path.join(out_files_path, "result.html") | 58 out_file = out_files_path / "result.html" |
44 infile_name = "input_data" | 59 infile_name = "input_data" |
45 functionality = "productive" | 60 functionality = "productive" |
46 unique = "Sequence.ID" | 61 unique = "Sequence.ID" |
47 naive_output = "no" | 62 naive_output = "no" |
48 naive_output_ca = "None" | 63 naive_output_ca = "None" |
55 class_filter = '70_70' | 70 class_filter = '70_70' |
56 empty_region_filter = 'FR1' | 71 empty_region_filter = 'FR1' |
57 fast = 'no' | 72 fast = 'no' |
58 cmd = [ | 73 cmd = [ |
59 "bash", | 74 "bash", |
60 "wrapper.sh", | 75 wrapper, |
61 input, | 76 input, |
62 "custom", | 77 "custom", |
63 out_file, | 78 str(out_file), |
64 out_files_path, | 79 str(out_files_path), |
65 infile_name, | 80 infile_name, |
66 "-", | 81 "-", |
67 functionality, | 82 functionality, |
68 unique, | 83 unique, |
69 naive_output, | 84 naive_output, |
76 filter_unique_count, | 91 filter_unique_count, |
77 class_filter, | 92 class_filter, |
78 empty_region_filter, | 93 empty_region_filter, |
79 fast | 94 fast |
80 ] | 95 ] |
81 subprocess.run(cmd, cwd=temp_dir, stdout=sys.stdout, stderr=sys.stderr, | 96 docker_cmd = ["docker", "run", "-v", f"{temp_dir}:{temp_dir}", |
82 check=True) | 97 "--rm", # Remove container after running |
98 "-v", f"{input}:{input}", | |
99 "-w", str(working_dir), | |
100 # Run as current user which allows deletion of files. | |
101 # It also mitigates some security considerations | |
102 "-u", f"{os.getuid()}:{os.getgid()}", | |
103 # Run with default seccomp profile to mitigate mitigation slowdown | |
104 # http://mamememo.blogspot.com/2020/05/cpu-intensive-rubypython-code-runs.html | |
105 # This knocks down test runtime from 8 to 6 minutes. | |
106 "--security-opt", "seccomp=unconfined", | |
107 # Use a mulled container generated with `planemo mull` | |
108 "quay.io/biocontainers/mulled-v2-f7d31c9d7424063a492fc0e5ecbf89bc757c0107:2b50bdd4d8c1fefc6ec24b0753fad0dcecec843b-0" | |
109 ] + cmd | |
110 with open(temp_dir / "stderr", "wt") as stderr_file: | |
111 with open(temp_dir / "stdout", "wt") as stdout_file: | |
112 subprocess.run(docker_cmd, cwd=working_dir, stdout=stdout_file, | |
113 stderr=stderr_file, check=True) | |
83 yield Path(out_files_path) | 114 yield Path(out_files_path) |
84 #shutil.rmtree(temp_dir) | |
85 | 115 |
86 | 116 |
87 def test_check_output(shm_csr_result): | 117 def test_check_output(shm_csr_result): |
88 assert shm_csr_result.exists() | 118 assert shm_csr_result.exists() |
89 | 119 |
90 | 120 |
91 @pytest.mark.parametrize("filename", os.listdir(VALIDATION_DATA_DIR)) | 121 @pytest.mark.parametrize("filename", os.listdir(VALIDATION_DATA_DIR)) |
92 def test_results_match_validation(shm_csr_result, filename): | 122 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: | 123 with open(Path(shm_csr_result, filename)) as result_h: |
97 with open(Path(VALIDATION_DATA_DIR, filename)) as validate_h: | 124 with open(Path(VALIDATION_DATA_DIR, filename)) as validate_h: |
98 for line in result_h: | 125 for line in result_h: |
99 assert line == validate_h.readline() | 126 # Skip two faulty lines in shm_overview. |
127 # TODO: Fix the issue. | |
128 validation_line = validate_h.readline() | |
129 if filename == "shm_overview.txt": | |
130 if (line.startswith("RGYW (%)") or | |
131 line.startswith("WRCY (%)")): | |
132 continue | |
133 assert line == validation_line | |
100 | 134 |
101 | 135 |
102 def test_nt_overview(shm_csr_result): | 136 def test_nt_overview(shm_csr_result): |
103 with open(Path(shm_csr_result, "sequence_overview", "ntoverview.txt") | 137 with open(Path(shm_csr_result, "sequence_overview", "ntoverview.txt") |
104 ) as result_h: | 138 ) as result_h: |