Mercurial > repos > yufei-luo > s_mart
comparison smart_toolShed/commons/core/sql/test/Test_F_JobAdaptator.py @ 0:e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
author | yufei-luo |
---|---|
date | Thu, 17 Jan 2013 10:52:14 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e0f8dcca02ed |
---|---|
1 from commons.core.launcher.WriteScript import WriteScript | |
2 from commons.core.sql.Job import Job | |
3 from commons.core.sql.DbFactory import DbFactory | |
4 from commons.core.sql.TableJobAdaptatorFactory import TableJobAdaptatorFactory | |
5 import sys | |
6 import stat | |
7 import os | |
8 import time | |
9 import unittest | |
10 import glob | |
11 | |
12 class Test_F_TableJobAdaptator(unittest.TestCase): | |
13 | |
14 def setUp(self): | |
15 self._jobTableName = "dummyJobTable" | |
16 self._iJA = TableJobAdaptatorFactory.createJobInstance() | |
17 | |
18 def tearDown(self): | |
19 pass | |
20 | |
21 def test_submitJob(self): | |
22 job1 = self._createJobInstance("job1") | |
23 self._createLauncherFile(job1, self._iJA) | |
24 job2 = self._createJobInstance("job2") | |
25 self._createLauncherFile(job2, self._iJA) | |
26 job3 = self._createJobInstance("job3") | |
27 self._createLauncherFile(job3, self._iJA) | |
28 | |
29 self._iJA.submitJob( job1, maxNbWaitingJobs=3, checkInterval=5, verbose=0 ) | |
30 self._iJA.submitJob( job2, maxNbWaitingJobs=3, checkInterval=5, verbose=0 ) | |
31 self._iJA.submitJob( job3, maxNbWaitingJobs=3, checkInterval=5, verbose=0 ) | |
32 | |
33 time.sleep(120) | |
34 | |
35 expErrorFilePrefix1 = job1.jobname + ".e" | |
36 expOutputFilePrefix1 = job1.jobname + ".o" | |
37 expErrorFilePrefix2 = job2.jobname + ".e" | |
38 expOutputFilePrefix2 = job2.jobname + ".o" | |
39 expErrorFilePrefix3 = job3.jobname + ".e" | |
40 expOutputFilePrefix3 = job3.jobname + ".o" | |
41 | |
42 lErrorFiles1 = glob.glob(expErrorFilePrefix1 + "*") | |
43 lOutputFiles1 = glob.glob(expOutputFilePrefix1 + "*") | |
44 lErrorFiles2 = glob.glob(expErrorFilePrefix2 + "*") | |
45 lOutputFiles2 = glob.glob(expOutputFilePrefix2 + "*") | |
46 lErrorFiles3 = glob.glob(expErrorFilePrefix3 + "*") | |
47 lOutputFiles3 = glob.glob(expOutputFilePrefix3 + "*") | |
48 | |
49 isLErrorFileNotEmpty1 = (len(lErrorFiles1) != 0) | |
50 isLOutputFileNotEmpty1 = (len(lOutputFiles1) != 0) | |
51 isLErrorFileNotEmpty2 = (len(lErrorFiles2) != 0) | |
52 isLOutputFileNotEmpty2 = (len(lOutputFiles2) != 0) | |
53 isLErrorFileNotEmpty3 = (len(lErrorFiles3) != 0) | |
54 isLOutputFileNotEmpty3 = (len(lOutputFiles3) != 0) | |
55 | |
56 os.system("rm launcherFileTest*.py *.e* *.o*") | |
57 self.assertTrue(isLErrorFileNotEmpty1 and isLOutputFileNotEmpty1) | |
58 self.assertTrue(isLErrorFileNotEmpty2 and isLOutputFileNotEmpty2) | |
59 self.assertTrue(isLErrorFileNotEmpty3 and isLOutputFileNotEmpty3) | |
60 | |
61 def test_submit_and_waitJobGroup(self): | |
62 iJob = self._createJobInstance("test") | |
63 self._createLauncherFile(iJob, self._iJA) | |
64 | |
65 self._iJA.submitJob( iJob, maxNbWaitingJobs=3, checkInterval=5, verbose=0 ) | |
66 self._iJA.waitJobGroup(iJob.groupid, 0, 2) | |
67 | |
68 expErrorFilePrefix1 = iJob.jobname + ".e" | |
69 expOutputFilePrefix1 = iJob.jobname + ".o" | |
70 | |
71 lErrorFiles1 = glob.glob(expErrorFilePrefix1 + "*") | |
72 lOutputFiles1 = glob.glob(expOutputFilePrefix1 + "*") | |
73 | |
74 isLErrorFileExist = (len(lErrorFiles1) != 0) | |
75 isLOutputFileExist = (len(lOutputFiles1) != 0) | |
76 os.system("rm launcherFileTest*.py *.e* *.o*") | |
77 self.assertTrue(isLErrorFileExist and isLOutputFileExist) | |
78 | |
79 def _createJobInstance(self, name): | |
80 lResources = [] | |
81 if os.environ.get("HOSTNAME") == "compute-2-46.local": | |
82 lResources.append("test=TRUE") | |
83 return Job(0, name, "test", "", "log = os.system(\"date;sleep 5;date\")", "%s/launcherFileTest_%s.py" % (os.getcwd(), name), lResources=lResources) | |
84 | |
85 def _createLauncherFile(self, iJob, iJA): | |
86 iWriteScript = WriteScript(iJob, iJA, os.getcwd(), os.getcwd(), False, True) | |
87 iWriteScript.run(iJob.command, "", iJob.launcher) | |
88 os.chmod(iJob.launcher, stat.S_IRWXU+stat.S_IRWXG+stat.S_IRWXO) | |
89 | |
90 if __name__ == "__main__": | |
91 unittest.main() |