summaryrefslogtreecommitdiff
path: root/unit_tests/test_multiprocess_runner.py
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-08-29 12:32:40 +0300
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-08-29 12:32:40 +0300
commitc07e4756def1c264799e682b10a052d8791d30cc (patch)
tree7936cea8ff6502caca0756e29af5068a0a35ff4e /unit_tests/test_multiprocess_runner.py
downloadpython-nose-c07e4756def1c264799e682b10a052d8791d30cc.tar.gz
python-nose-c07e4756def1c264799e682b10a052d8791d30cc.tar.bz2
python-nose-c07e4756def1c264799e682b10a052d8791d30cc.zip
Imported Upstream version 0.11.4upstream/0.11.4
Diffstat (limited to 'unit_tests/test_multiprocess_runner.py')
-rw-r--r--unit_tests/test_multiprocess_runner.py120
1 files changed, 120 insertions, 0 deletions
diff --git a/unit_tests/test_multiprocess_runner.py b/unit_tests/test_multiprocess_runner.py
new file mode 100644
index 0000000..71ee398
--- /dev/null
+++ b/unit_tests/test_multiprocess_runner.py
@@ -0,0 +1,120 @@
+import unittest
+import imp
+import sys
+from nose.loader import TestLoader
+from nose.plugins import multiprocess
+from nose.suite import ContextSuite
+
+class T_fixt:
+ def setupClass(cls):
+ pass
+ setupClass = classmethod(setupClass)
+
+ def test_a(self):
+ pass
+ def test_b(self):
+ pass
+
+class T:
+ def test_a(self):
+ pass
+ def test_b(self):
+ pass
+
+
+
+class TestMultiProcessTestRunner(unittest.TestCase):
+
+ def test_next_batch_with_classes(self):
+ r = multiprocess.MultiProcessTestRunner()
+ l = TestLoader()
+ tests = list(r.nextBatch(ContextSuite(
+ tests=[l.makeTest(T_fixt), l.makeTest(T)])))
+ print tests
+ self.assertEqual(len(tests), 3)
+
+ def test_next_batch_with_module_fixt(self):
+ mod_with_fixt = imp.new_module('mod_with_fixt')
+ sys.modules['mod_with_fixt'] = mod_with_fixt
+
+ def teardown():
+ pass
+
+ class Test(T):
+ pass
+
+ mod_with_fixt.Test = Test
+ mod_with_fixt.teardown = teardown
+ Test.__module__ = 'mod_with_fixt'
+
+ r = multiprocess.MultiProcessTestRunner()
+ l = TestLoader()
+ tests = list(r.nextBatch(l.loadTestsFromModule(mod_with_fixt)))
+ print tests
+ self.assertEqual(len(tests), 1)
+
+ def test_next_batch_with_module(self):
+ mod_no_fixt = imp.new_module('mod_no_fixt')
+ sys.modules['mod_no_fixt'] = mod_no_fixt
+
+ class Test2(T):
+ pass
+
+ class Test_fixt(T_fixt):
+ pass
+
+ mod_no_fixt.Test = Test2
+ Test2.__module__ = 'mod_no_fixt'
+ mod_no_fixt.Test_fixt = Test_fixt
+ Test_fixt.__module__ = 'mod_no_fixt'
+
+ r = multiprocess.MultiProcessTestRunner()
+ l = TestLoader()
+ tests = list(r.nextBatch(l.loadTestsFromModule(mod_no_fixt)))
+ print tests
+ self.assertEqual(len(tests), 3)
+
+ def test_next_batch_with_generator_method(self):
+ class Tg:
+ def test_gen(self):
+ for i in range(0, 3):
+ yield self.check, i
+ def check(self, val):
+ pass
+ r = multiprocess.MultiProcessTestRunner()
+ l = TestLoader()
+ tests = list(r.nextBatch(l.makeTest(Tg)))
+ print tests
+ print [r.address(t) for t in tests]
+ self.assertEqual(len(tests), 1)
+
+ def test_next_batch_can_split_set(self):
+
+ mod_with_fixt2 = imp.new_module('mod_with_fixt2')
+ sys.modules['mod_with_fixt2'] = mod_with_fixt2
+
+ def setup():
+ pass
+
+ class Test(T):
+ pass
+
+ class Test_fixt(T_fixt):
+ pass
+
+ mod_with_fixt2.Test = Test
+ mod_with_fixt2.Test_fixt = Test_fixt
+ mod_with_fixt2.setup = setup
+ mod_with_fixt2._multiprocess_can_split_ = True
+ Test.__module__ = 'mod_with_fixt2'
+ Test_fixt.__module__ = 'mod_with_fixt2'
+
+ r = multiprocess.MultiProcessTestRunner()
+ l = TestLoader()
+ tests = list(r.nextBatch(l.loadTestsFromModule(mod_with_fixt2)))
+ print tests
+ self.assertEqual(len(tests), 3)
+
+
+if __name__ == '__main__':
+ unittest.main()