This repository has been archived by the owner on Nov 9, 2023. It is now read-only.
/
test_make_cluster_jobs.py
68 lines (51 loc) · 2.01 KB
/
test_make_cluster_jobs.py
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
#!/usr/bin/env python
"""Tests for submitting jobs via qsub."""
__author__ = "Jens Reeder"
__copyright__ = "Copyright 2011, The QIIME Project"
# remember to add yourself if you make changes
__credits__ = ["Jens Reeder", "Rob Knight"]
__license__ = "GPL"
__version__ = "1.9.1-dev"
__maintainer__ = "Jens Reeder"
__email__ = "jens.reeder@gmail.com"
from os import remove, environ, close
from os.path import exists
from time import sleep
from tempfile import mkstemp
from unittest import TestCase, main
from qiime.denoiser.make_cluster_jobs import QSUB_TEXT, make_jobs, \
submit_jobs
class Test_make_cluster_jobs(TestCase):
def setUp(self):
self.home = environ['HOME']
self.queue = "friendlyq"
fd, self.tmp_result_file = mkstemp(dir=self.home,
prefix="test_hello_",
suffix=".txt")
close(fd)
self.command = "echo hello > %s\n" % self.tmp_result_file
fd, self.tmp_name = mkstemp(dir="/tmp",
prefix="make_cluster_jobs_test_",
suffix=".txt")
close(fd)
fh = open(self.tmp_name, "w")
fh.write(self.command)
fh.close()
def tearDown(self):
remove(self.tmp_name)
if exists(self.tmp_result_file):
remove(self.tmp_result_file)
def test_make_jobs(self):
"""writing the job files works"""
# no commands should make no jobs files
self.assertEqual(make_jobs([], "test", self.queue), [])
# one job file should be created
filenames = make_jobs([self.command], "test_qsub", self.queue)
self.assertTrue(len(filenames) == 1)
observed_text = list(open(filenames[0]))
self.assertEqual("".join(observed_text),
QSUB_TEXT % ("72:00:00", 1, 1, self.queue,
"test_qsub", "oe",
self.command))
if __name__ == "__main__":
main()