import os
import logging
import time
-import unittest
-
+from unittest import TestCase
from htsworkflow.util.queuecommands import QueueCommands
-class testQueueCommands(unittest.TestCase):
+class testQueueCommands(TestCase):
def setUp(self):
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-8s %(message)s')
-
-
- def test_unlimited_run(self):
+ def test_unlimited_run_slow(self):
"""
Run everything at once
"""
'/bin/sleep 1',
'/bin/sleep 2',]
- q = QueueCommands(cmds)
+ q = QueueCommands(cmds, 3)
start = time.time()
q.run()
end = time.time()-start
# we should only take the length of the longest sleep
- # pity I had to add a 1 second sleep
- self.failUnless( end > 2.9 and end < 3.1,
- "took %s seconds, exected ~3" % (end,))
+ self.failUnless( end > 1.9 and end < 2.1,
+ "took %s seconds, exected ~2" % (end,))
- def test_limited_run(self):
+ def test_limited_run_slow(self):
"""
Run a limited number of jobs
"""
start = time.time()
q.run()
end = time.time()-start
- # pity I had to add a 1 second sleep
- self.failUnless( end > 5.9 and end < 6.1,
- "took %s seconds, expected ~6" % (end,))
-
-def suite():
- return unittest.makeSuite(testQueueCommands, 'test')
-
-if __name__ == "__main__":
- unittest.main(defaultTest='suite')
+ self.failUnless( end > 3.9 and end < 4.1,
+ "took %s seconds, expected ~4" % (end,))
+def suite():
+ from unittest import TestSuite, defaultTestLoader
+ suite = TestSuite()
+ suite.addTests(defaultTestLoader.loadTestsFromTestCase(testQueueCommands))
+ return suite
+if __name__ == "__main__":
+ from unittest import main
+ main(defaultTest="suite")