def test_do_work(self, m_logging): worker = NowcastWorker("worker_name", "description") worker.init_cli() m_worker_func = Mock(name="worker_func") m_success = Mock(name="success") m_failure = Mock(name="failure") worker.cli.parser.parse_args = Mock(name="parse_args") worker._configure_logging = Mock(name="_configure_logging") worker.logger = m_logging() worker._install_signal_handlers = Mock(name="_install_signal_handlers") worker._init_zmq_interface = Mock(name="_init_zmq_interface") worker._do_work = Mock(name="_do_work") p_config_open = patch("nemo_nowcast.config.open", mock_open(read_data=self.config)) with p_config_open: worker.run(m_worker_func, m_success, m_failure) assert worker._do_work.call_count == 1
def test_logging_info_debug_mode(self, m_logging): worker = NowcastWorker("worker_name", "description") worker.init_cli() m_worker_func = Mock(name="worker_func") m_success = Mock(name="success") m_failure = Mock(name="failure") worker.cli.parser.parse_args = Mock( name="parse_args", return_value=SimpleNamespace(debug=True, config_file="nowcast.yaml"), ) worker._configure_logging = Mock(name="_configure_logging") worker.logger = m_logging() worker._install_signal_handlers = Mock(name="_install_signal_handlers") worker._init_zmq_interface = Mock(name="_init_zmq_interface") worker._do_work = Mock(name="_do_work") p_config_open = patch("nemo_nowcast.config.open", mock_open(read_data=self.config)) with p_config_open: worker.run(m_worker_func, m_success, m_failure) assert worker.logger.info.call_count == 2
def test_config_load(self, m_logging): worker = NowcastWorker("worker_name", "description") worker.config._dict = { "logging": {}, "message registry": { "next workers module": "nowcast.next_workers", "workers": {}, }, } worker.config.load = Mock() worker.init_cli() m_worker_func = Mock(name="worker_func") m_success = Mock(name="success") m_failure = Mock(name="failure") worker.cli.parser.parse_args = Mock(name="parse_args") worker._configure_logging = Mock(name="_configure_logging") worker.logger = m_logging() worker._install_signal_handlers = Mock(name="_install_signal_handlers") worker._init_zmq_interface = Mock(name="_init_zmq_interface") worker._do_work = Mock(name="_do_work") worker.run(m_worker_func, m_success, m_failure) worker.config.load.assert_called_once_with( worker._parsed_args.config_file)
def test_signal_handlers(self, i, sig): worker = NowcastWorker("worker_name", "description") with patch("nemo_nowcast.worker.signal.signal") as m_signal: worker._install_signal_handlers() args, kwargs = m_signal.call_args_list[i] assert args[0] == sig