Ejemplo n.º 1
0
    async def does_script_run_without_error(self) -> Tuple[bool, str]:
        """Load and execute the app's script to verify it runs without an error.

        Returns
        -------
        (True, "ok") if the script completes without error, or (False, err_msg)
        if the script raises an exception.
        """
        session_data = SessionData(self._main_script_path, self._command_line)
        local_sources_watcher = LocalSourcesWatcher(session_data)
        session = AppSession(
            ioloop=self._ioloop,
            session_data=session_data,
            uploaded_file_manager=self._uploaded_file_mgr,
            message_enqueued_callback=self._enqueued_some_message,
            local_sources_watcher=local_sources_watcher,
        )

        try:
            session.request_rerun(None)

            now = time.perf_counter()
            while (SCRIPT_RUN_WITHOUT_ERRORS_KEY not in session.session_state
                   and (time.perf_counter() - now) < SCRIPT_RUN_CHECK_TIMEOUT):
                await tornado.gen.sleep(0.1)

            if SCRIPT_RUN_WITHOUT_ERRORS_KEY not in session.session_state:
                return False, "timeout"

            ok = session.session_state[SCRIPT_RUN_WITHOUT_ERRORS_KEY]
            msg = "ok" if ok else "error"

            return ok, msg
        finally:
            session.shutdown()
Ejemplo n.º 2
0
    def test_passes_client_state_on_run_on_save(self, _):
        rs = AppSession(
            None, SessionData("", ""), UploadedFileManager(), None, MagicMock()
        )
        rs._run_on_save = True
        rs.request_rerun = MagicMock()
        rs._on_source_file_changed()

        rs.request_rerun.assert_called_once_with(rs._client_state)