def test_profilePrintStatsError(self): """ When an error happens during the print of the stats, C{sys.stdout} should be restored to its initial value. """ class ErroneousProfile(profile.Profile): def print_stats(self): raise RuntimeError("Boom") self.patch(profile, "Profile", ErroneousProfile) config = twistd.ServerOptions() config["profile"] = self.mktemp() config["profiler"] = "profile" profiler = app.AppProfiler(config) reactor = DummyReactor() oldStdout = sys.stdout self.assertRaises(RuntimeError, profiler.run, reactor) self.assertIdentical(sys.stdout, oldStdout)
def test_defaultProfiler(self): """ L{app.Profiler} defaults to the hotshot profiler if not specified. """ profiler = app.AppProfiler({}) self.assertEqual(profiler.profiler, "hotshot")
app_name = config.get('application', 'name') application = service.Application(app_name) log_file = config.get('log', 'file') log_path = config.get('log', 'directory') log_level = config.get('log', 'level') logfile = CustomDailyLogFile(log_file, log_path) application.setComponent( ILogObserver, log.FileLogObserver(logfile, log_level, exclude_systems=[]).emit) if __name__ == '__main__': app_config = { 'no_save': True, 'nodaemon': False, 'profile': False, 'debug': False } oldstdout = sys.stdout oldstderr = sys.stderr profiler = app.AppProfiler(app_config) logger = app.AppLogger(app_config) logger.start(application) sys.stdout = oldstdout run_test() logger.stop()