def testForkParamPassing(self): def test_func(foo, bar): return "%s%s" % (foo, bar) val = fork_process(target=test_func, kwargs={"foo": "foo", "bar": 10}) self.assertEquals(len(val), 2) self.assertEquals(val[0], 0) self.assertEquals(val[1], "foo10") val = fork_process(target=test_func, args=("foo", 20)) self.assertEquals(len(val), 2) self.assertEquals(val[0], 0) self.assertEquals(val[1], "foo20")
def testForkWithException(self): def test_func(): raise PyBuilderException("Test failure message") try: val = fork_process(Mock(), target=test_func) val = fork_process(Mock(), target=test_func) self.fail("should not have reached here, returned %s" % val) except: ex_type, ex, tb = sys.exc_info() self.assertEquals(ex_type, PyBuilderException) self.assertEquals(ex.message, "Test failure message") self.assertTrue(tb)
def testForkParamPassing(self): def test_func(foo, bar): return "%s%s" % (foo, bar) val = fork_process(mock(), target=test_func, kwargs={"foo": "foo", "bar": 10}) self.assertEquals(len(val), 2) self.assertEquals(val[0], 0) self.assertEquals(val[1], "foo10") val = fork_process(mock(), target=test_func, args=("foo", 20)) self.assertEquals(len(val), 2) self.assertEquals(val[0], 0) self.assertEquals(val[1], "foo20")
def testForkWithSendPicklingError(self): class Foo(object): @staticmethod def bar(): pass class FooError(Exception): def __init__(self, message): super(Exception, self).__init__(message) def test_func(): raise FooError(Foo.bar) try: val = fork_process(Mock(), target=test_func) self.fail("should not have reached here, returned %s" % val) except: ex_type, ex, tb = sys.exc_info() self.assertEquals(ex_type, Exception) self.assertTrue( str(ex).startswith( "Fatal error occurred in the forked process")) self.assertTrue("Can't pickle" in str(ex)) self.assertTrue("FooError" in str(ex)) self.assertTrue( "This error masked the send error '<function" in str(ex)) self.assertTrue("raise FooError(Foo.bar)" in str(ex))
def run_coverage(project, logger, reactor, execution_prefix, execution_name, target_task, shortest_plan=False): logger.info("Collecting coverage information") if project.get_property("%s_fork" % execution_prefix) is not None: logger.warn( "%s_fork is deprecated, coverage always runs in its own fork", execution_prefix) if project.get_property("%s_reload_modules" % execution_prefix) is not None: logger.warn( "%s_reload_modules is deprecated - modules are no longer reloaded", execution_prefix) if project.get_property("%s_branch_threshold_warn" % execution_prefix) == 0: logger.warn("%s_branch_threshold_warn is 0 and branch coverage will not be checked", execution_prefix) if project.get_property("%s_branch_partial_threshold_warn" % execution_prefix) == 0: logger.warn("%s_branch_partial_threshold_warn is 0 and partial branch coverage will not be checked", execution_prefix) logger.debug("Forking process to do %s analysis", execution_name) exit_code, _ = fork_process(logger, target=do_coverage, args=( project, logger, reactor, execution_prefix, execution_name, target_task, shortest_plan)) if exit_code and project.get_property("%s_break_build" % execution_prefix): raise BuildFailedException( "Forked %s process indicated failure with error code %d" % (execution_name, exit_code))
def testForkWithValuePicklingError(self): class FooError(Exception): def __init__(self): self.val = 'Blah' def test_func(): return FooError() try: fork_process(target=test_func) self.fail("should not have reached here") except: ex_type, ex, tb = sys.exc_info() self.assertEquals(ex_type, Exception) self.assertTrue(str(ex).startswith("Fatal error occurred in the forked process")) self.assertTrue("Can't pickle" in str(ex)) self.assertTrue("FooError" in str(ex))
def testForkWithValuePicklingError(self): class FooError(Exception): def __init__(self): self.val = 'Blah' def test_func(): return FooError() try: fork_process(mock(), target=test_func) self.fail("should not have reached here") except: ex_type, ex, tb = sys.exc_info() self.assertEquals(ex_type, Exception) self.assertTrue(str(ex).startswith("Fatal error occurred in the forked process")) self.assertTrue("Can't pickle" in str(ex)) self.assertTrue("FooError" in str(ex))
def testForkNoException(self): def test_func(): return "success" val = fork_process(Mock(), target=test_func) self.assertEquals(len(val), 2) self.assertEquals(val[0], 0) self.assertEquals(val[1], "success")
def testForkNoException(self): def test_func(): return "success" val = fork_process(mock(), target=test_func) self.assertEquals(len(val), 2) self.assertEquals(val[0], 0) self.assertEquals(val[1], "success")
def run_tests(project, logger, execution_prefix, execution_name): logger.info("Running %s", execution_name) if not project.get_property("__running_coverage"): logger.debug("Forking process to run %s", execution_name) exit_code, _ = fork_process(target=do_run_tests, args=(project, logger, execution_prefix, execution_name)) if exit_code: raise BuildFailedException( "Forked %s process indicated failure with error code %d" % (execution_name, exit_code) ) else: do_run_tests(project, logger, execution_prefix, execution_name)
def run_tests(project, logger, execution_prefix, execution_name): logger.info("Running %s", execution_name) if not project.get_property('__running_coverage'): logger.debug("Forking process to run %s", execution_name) exit_code, _ = fork_process(target=do_run_tests, args=(project, logger, execution_prefix, execution_name)) if exit_code: raise BuildFailedException( "Forked %s process indicated failure with error code %d" % (execution_name, exit_code)) else: do_run_tests(project, logger, execution_prefix, execution_name)
def testForkWithExceptionPicklingError(self): class FooError(Exception): def __init__(self): self.val = "Blah" def test_func(): raise FooError() try: val = fork_process(target=test_func) self.fail("should not have reached here, returned %s" % val) except: ex_type, ex, tb = sys.exc_info() self.assertEquals(ex_type, Exception) self.assertTrue(str(ex).startswith("Fatal error occurred in the forked process")) self.assertTrue("Can't pickle" in str(ex)) self.assertTrue("FooError" in str(ex))
def testForkWithSendPicklingError(self): class Foo(object): @staticmethod def bar(): pass class FooError(Exception): def __init__(self, message): super(Exception, self).__init__(message) def test_func(): raise FooError(Foo.bar) try: val = fork_process(mock(), target=test_func) self.fail("should not have reached here, returned %s" % val) except: ex_type, ex, tb = sys.exc_info() self.assertEquals(ex_type, Exception) self.assertTrue(str(ex).startswith("Fatal error occurred in the forked process")) self.assertTrue("Can't pickle" in str(ex)) self.assertTrue("FooError" in str(ex)) self.assertTrue("This error masked the send error '<function" in str(ex)) self.assertTrue("raise FooError(Foo.bar)" in str(ex))