PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/unit_tests/test_multiprocess_runner.py

https://bitbucket.org/jpellerin/nose/
Python | 120 lines | 93 code | 27 blank | 0 comment | 5 complexity | 5139f7a589aca0866e35ff9985c7fbc8 MD5 | raw file
  1import unittest
  2import imp
  3import sys
  4from nose.loader import TestLoader
  5from nose.plugins import multiprocess
  6from nose.suite import ContextSuite
  7
  8class T_fixt:
  9    def setupClass(cls):
 10        pass
 11    setupClass = classmethod(setupClass)
 12
 13    def test_a(self):
 14        pass
 15    def test_b(self):
 16        pass
 17    
 18class T:
 19    def test_a(self):
 20        pass
 21    def test_b(self):
 22        pass
 23
 24
 25
 26class TestMultiProcessTestRunner(unittest.TestCase):
 27
 28    def test_next_batch_with_classes(self):
 29        r = multiprocess.MultiProcessTestRunner()
 30        l = TestLoader()
 31        tests = list(r.nextBatch(ContextSuite(
 32                    tests=[l.makeTest(T_fixt), l.makeTest(T)])))
 33        print tests
 34        self.assertEqual(len(tests), 3)
 35
 36    def test_next_batch_with_module_fixt(self):
 37        mod_with_fixt = imp.new_module('mod_with_fixt')
 38        sys.modules['mod_with_fixt'] = mod_with_fixt
 39
 40        def teardown():
 41            pass
 42
 43        class Test(T):
 44            pass
 45
 46        mod_with_fixt.Test = Test
 47        mod_with_fixt.teardown = teardown
 48        Test.__module__ = 'mod_with_fixt'
 49
 50        r = multiprocess.MultiProcessTestRunner()
 51        l = TestLoader()
 52        tests = list(r.nextBatch(l.loadTestsFromModule(mod_with_fixt)))
 53        print tests
 54        self.assertEqual(len(tests), 1)
 55
 56    def test_next_batch_with_module(self):
 57        mod_no_fixt = imp.new_module('mod_no_fixt')
 58        sys.modules['mod_no_fixt'] = mod_no_fixt
 59
 60        class Test2(T):
 61            pass
 62
 63        class Test_fixt(T_fixt):
 64            pass
 65
 66        mod_no_fixt.Test = Test2
 67        Test2.__module__ = 'mod_no_fixt'
 68        mod_no_fixt.Test_fixt = Test_fixt
 69        Test_fixt.__module__ = 'mod_no_fixt'
 70
 71        r = multiprocess.MultiProcessTestRunner()
 72        l = TestLoader()
 73        tests = list(r.nextBatch(l.loadTestsFromModule(mod_no_fixt)))
 74        print tests
 75        self.assertEqual(len(tests), 3)
 76
 77    def test_next_batch_with_generator_method(self):
 78        class Tg:
 79            def test_gen(self):
 80                for i in range(0, 3):
 81                    yield self.check, i
 82            def check(self, val):
 83                pass
 84        r = multiprocess.MultiProcessTestRunner()
 85        l = TestLoader()
 86        tests = list(r.nextBatch(l.makeTest(Tg)))
 87        print tests
 88        print [r.address(t) for t in tests]
 89        self.assertEqual(len(tests), 1)
 90
 91    def test_next_batch_can_split_set(self):
 92
 93        mod_with_fixt2 = imp.new_module('mod_with_fixt2')
 94        sys.modules['mod_with_fixt2'] = mod_with_fixt2
 95
 96        def setup():
 97            pass
 98
 99        class Test(T):
100            pass
101
102        class Test_fixt(T_fixt):
103            pass
104
105        mod_with_fixt2.Test = Test
106        mod_with_fixt2.Test_fixt = Test_fixt
107        mod_with_fixt2.setup = setup
108        mod_with_fixt2._multiprocess_can_split_ = True
109        Test.__module__ = 'mod_with_fixt2'
110        Test_fixt.__module__ = 'mod_with_fixt2'
111
112        r = multiprocess.MultiProcessTestRunner()
113        l = TestLoader()
114        tests = list(r.nextBatch(l.loadTestsFromModule(mod_with_fixt2)))
115        print tests
116        self.assertEqual(len(tests), 3)
117        
118            
119if __name__ == '__main__':
120    unittest.main()