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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#!/usr/bin/python3
import os
import sys
import unittest
from unittest.mock import patch
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'scripts')))
import slurm_srst2
class TestSamtoolExec(unittest.TestCase):
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_samtools_index_with_overide(self, env_mock, path_mock, run_mock,
version_mock, stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: 'missing' not in f
env_mock.get.side_effect = {'SRST2_SAMTOOLS': '/usr/bin/samtools'}.get
slurm_srst2.samtools_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['/usr/bin/samtools'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['/usr/bin/samtools', 'faidx',
'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_samtools_index_with_default(self, env_mock, path_mock, run_mock,
version_mock, stdout_mock):
path_mock.exists.return_value = False
env_mock.get.return_value = None
slurm_srst2.samtools_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['samtools'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['samtools', 'faidx',
'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_samtools_index_with_missing_overide(self, env_mock, path_mock,
run_mock, version_mock,
stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: 'missing' not in f
env_mock.get.side_effect = {'SRST2_SAMTOOLS': '/missing/samtools'}.get
slurm_srst2.samtools_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['samtools'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['samtools', 'faidx',
'foo'])
class TestBowtieIndex(unittest.TestCase):
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_bowtie_index_with_overides(self, env_mock, path_mock, run_mock,
version_mock, stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: 'missing' not in f
fake_env_variables = {'SRST2_BOWTIE2': '/usr/bin/bowtie2',
'SRST2_BOWTIE2_BUILD': '/usr/bin/bowtie2-build'}
env_mock.get.side_effect = fake_env_variables.get
slurm_srst2.bowtie_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['/usr/bin/bowtie2',
'--version'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['/usr/bin/bowtie2-build', 'foo', 'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_bowtie_index_with_partial_overide(self, env_mock, path_mock, run_mock,
version_mock, stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: 'missing' not in f
fake_env_variables = {'SRST2_BOWTIE2': '/usr/bin/bowtie2'}
env_mock.get.side_effect = fake_env_variables.get
slurm_srst2.bowtie_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['/usr/bin/bowtie2',
'--version'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['/usr/bin/bowtie2-build', 'foo', 'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_bowtie_index_with_other_overide(self, env_mock, path_mock, run_mock,
version_mock, stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: 'missing' not in f
fake_env_variables = {'SRST2_BOWTIE2_BUILD': '/usr/bin/bowtie2-build'}
env_mock.get.side_effect = fake_env_variables.get
slurm_srst2.bowtie_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['bowtie2',
'--version'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['/usr/bin/bowtie2-build', 'foo', 'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_bowtie_index_with_default(self, env_mock, path_mock, run_mock,
version_mock, stdout_mock):
path_mock.exists.return_value = False
env_mock.get.return_value = None
slurm_srst2.bowtie_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['bowtie2',
'--version'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['bowtie2-build', 'foo', 'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_bowtie_index_with_missing_overide(self, env_mock, path_mock,
run_mock, version_mock,
stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: 'missing' not in f
env_mock.get.side_effect = {'SRST2_SAMTOOLS': '/missing/bowtie'}.get
slurm_srst2.bowtie_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['bowtie2',
'--version'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['bowtie2-build', 'foo', 'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_bowtie_index_with_one_missing_overide(self, env_mock, path_mock,
run_mock, version_mock,
stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: 'missing' not in f
fake_env_variables = {'SRST2_BOWTIE2': '/missing/bowtie2',
'SRST2_BOWTIE2_BUILD': '/usr/bin/bowtie2-build'}
env_mock.get.side_effect = fake_env_variables.get
slurm_srst2.bowtie_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['bowtie2',
'--version'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['/usr/bin/bowtie2-build', 'foo', 'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_bowtie_index_with_other_missing_overide(self, env_mock, path_mock,
run_mock, version_mock,
stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: 'missing' not in f
fake_env_variables = {'SRST2_BOWTIE2': '/usr/bin/bowtie2',
'SRST2_BOWTIE2_BUILD': '/missing/bowtie2-build'}
env_mock.get.side_effect = fake_env_variables.get
slurm_srst2.bowtie_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['/usr/bin/bowtie2',
'--version'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['/usr/bin/bowtie2-build', 'foo', 'foo'])
@patch('slurm_srst2.sys.stdout')
@patch('slurm_srst2.check_command_versions')
@patch('slurm_srst2.run_command')
@patch('slurm_srst2.os.path')
@patch('slurm_srst2.os.environ')
def test_bowtie_index_with_missing_inference(self, env_mock, path_mock,
run_mock, version_mock,
stdout_mock):
path_mock.exists.return_value = False
path_mock.isfile.side_effect = lambda f: f == '/usr/bin/bowtie2'
fake_env_variables = {'SRST2_BOWTIE2': '/usr/bin/bowtie2'}
env_mock.get.side_effect = fake_env_variables.get
slurm_srst2.bowtie_index(['foo'])
self.assertEqual(version_mock.call_count, 1)
self.assertEqual(version_mock.call_args[0][0], ['/usr/bin/bowtie2',
'--version'])
self.assertEqual(run_mock.call_count, 1)
run_mock.assert_called_once_with(['bowtie2-build', 'foo', 'foo'])
if __name__ == '__main__':
unittest.main()
|