def testEjecutarDeberiaInvocarAlCorregirCuandoHayCorreccionesPendientes(self): corrector = AutomaticCorrectionRunner() automatic_correction = Mock() return_value = Mock() automatic_correction.delivery.practice.get_script.return_value = return_value automatic_correction.script = "test_script.sh" selection_strategy_mock = Mock() selection_strategy_mock.get_automatic_corrections.return_value = (automatic_correction, ) setup_enviroment_mock = Mock() script_result = ScriptResult() script_result.exit_value = 0 script_result.captured_stdout = "some stdout" execution_command_mock = Mock() execution_command_mock.execute.return_value = script_result publication_visitor = Mock() corrector.selection_strategy = selection_strategy_mock corrector.setup_enviroment = setup_enviroment_mock corrector.run_script_command = execution_command_mock corrector.publish_result_visitors = (publication_visitor, ) corrector.run() selection_strategy_mock.get_automatic_corrections.assert_called() setup_enviroment_mock.setup_enviroment.assert_called() execution_command_mock.execute.assert_called() publication_visitor.visit.assert_called()
def testEjecutarDeberiaInvocarAlCorregirCuandoHayCorreccionesPendientes( self): corrector = AutomaticCorrectionRunner() automatic_correction = Mock() return_value = Mock() automatic_correction.delivery.practice.get_script.return_value = return_value automatic_correction.script = "test_script.sh" selection_strategy_mock = Mock() selection_strategy_mock.get_automatic_corrections.return_value = ( automatic_correction, ) setup_enviroment_mock = Mock() script_result = ScriptResult() script_result.exit_value = 0 script_result.captured_stdout = "some stdout" execution_command_mock = Mock() execution_command_mock.execute.return_value = script_result publication_visitor = Mock() corrector.selection_strategy = selection_strategy_mock corrector.setup_enviroment = setup_enviroment_mock corrector.run_script_command = execution_command_mock corrector.publish_result_visitors = (publication_visitor, ) corrector.run() selection_strategy_mock.get_automatic_corrections.assert_called() setup_enviroment_mock.setup_enviroment.assert_called() execution_command_mock.execute.assert_called() publication_visitor.visit.assert_called()
def testEjecutarDeberiaConsultarCorreccionesPendientes(self): corrector = AutomaticCorrectionRunner() selection_strategy_mock = Mock() selection_strategy_mock.get_automatic_corrections.return_value = list() corrector.selection_strategy = selection_strategy_mock corrector.run() corrector.selection_strategy.get_automatic_corrections.assert_called()
def testEjecutarDeberiaConsultarCorreccionesPendientes(self): corrector = AutomaticCorrectionRunner() selection_strategy_mock = Mock() selection_strategy_mock.get_automatic_corrections.return_value = list() corrector.selection_strategy = selection_strategy_mock corrector.run() corrector.selection_strategy.get_automatic_corrections.assert_called()
class LoopRunner(): LOOP_INTERVAL = 65 def __init__(self): logger_manager = LoggerManager() self.log = logger_manager.get_new_logger("loop runner") self.loop_interval = LoopRunner.LOOP_INTERVAL # in seconds self.stdin_path = '/dev/null' self.stdout_path = '/dev/tty' self.stderr_path = '/dev/tty' self.pidfile_path = '/tmp/foo.pid' self.pidfile_timeout = 5 self.automatic_correction_runner = AutomaticCorrectionRunner() self.administrator_mail = AdministratorMail() def stall_loop(self, start_timestamp, finish_timestamp): delta = finish_timestamp - start_timestamp time_to_wait = self.loop_interval - delta.seconds # if the process took less than 30 seconds, we will wait if (time_to_wait > 0): time.sleep(time_to_wait) else: print("not sleeping... delta: " + str(delta)) start_timestamp = datetime.today() def print_result(self, result): # TODO: pass to a log entry print str(datetime.today()) + " | " + str(result) def run(self): self.log = LoggerManager().get_new_logger("daemon control") self.log.info("Daemon's game loop started.") while True: start_timestamp = datetime.today() try: result = self.automatic_correction_runner.run() self.log.info( "Automatic correction process completed.\nResult summary: \n\tsuccessfull: %d\n\tfailed: %d", result[AutomaticCorrectionRunner.SUCCESSFULL_RESULTS_KEY], result[AutomaticCorrectionRunner.FAILED_RESULTS_KEY]) except: self.log.exception( "The automatic correction process failed. Have in mind that is required that the web service must be online." ) try: self.administrator_mail.send_mails() except: self.log.exception( "The mail sending process failed. Have in mind that is required that the web service must be online." ) finish_timestamp = datetime.today() self.stall_loop(start_timestamp, finish_timestamp)
class LoopRunner(): LOOP_INTERVAL = 65 def __init__(self): logger_manager = LoggerManager() self.log = logger_manager.get_new_logger("loop runner") self.loop_interval = LoopRunner.LOOP_INTERVAL # in seconds self.stdin_path = '/dev/null' self.stdout_path = '/dev/tty' self.stderr_path = '/dev/tty' self.pidfile_path = '/tmp/foo.pid' self.pidfile_timeout = 5 self.automatic_correction_runner = AutomaticCorrectionRunner() self.administrator_mail = AdministratorMail() def stall_loop(self, start_timestamp, finish_timestamp): delta = finish_timestamp - start_timestamp time_to_wait = self.loop_interval - delta.seconds # if the process took less than 30 seconds, we will wait if (time_to_wait > 0): time.sleep(time_to_wait) else: print("not sleeping... delta: " + str(delta)) start_timestamp = datetime.today() def print_result(self, result): # TODO: pass to a log entry print str(datetime.today()) + " | " + str(result) def run(self): self.log = LoggerManager().get_new_logger("daemon control") self.log.info("Daemon's game loop started.") while True: start_timestamp = datetime.today() try: result = self.automatic_correction_runner.run() self.log.info("Automatic correction process completed.\nResult summary: \n\tsuccessfull: %d\n\tfailed: %d", result[AutomaticCorrectionRunner.SUCCESSFULL_RESULTS_KEY], result[AutomaticCorrectionRunner.FAILED_RESULTS_KEY]) except: self.log.exception("The automatic correction process failed. Have in mind that is required that the web service must be online.") try: self.administrator_mail.send_mails() except: self.log.exception("The mail sending process failed. Have in mind that is required that the web service must be online.") finish_timestamp = datetime.today() self.stall_loop(start_timestamp, finish_timestamp)