class_docstr: Subclasses ScriptRunner to provide some testing features.
class_docstr_tok: ["Subclasses","ScriptRunner","to","provide","some","testing","features","."]
docstr: Initializes the ScriptRunner for the given script_path.
docstr_tok: ["Initializes","the","ScriptRunner","for","the","given","script_path","."]
code: def __init__(
      self,
      script_path: str,
      session_state: SafeSessionState,
  ):
      """Initializes the ScriptRunner for the given script_path."""
  
      assert os.path.isfile(
          script_path
      ), f"File not found at {script_path}"
  
      self.forward_msg_queue = ForwardMsgQueue()
      self.script_path = script_path
      self.session_state = session_state
  
      super().__init__(
          session_id="test session id",
          main_script_path=script_path,
          session_state=self.session_state._state,
          uploaded_file_mgr=MemoryUploadedFileManager("/mock/upload"),
          script_cache=ScriptCache(),
          initial_rerun_data=RerunData(),
          user_info={"email": "test@test.com"},
      )
  
      # Accumulates all ScriptRunnerEvents emitted by us.
      self.events: list[ScriptRunnerEvent] = []
      self.event_data: list[Any] = []
  
      def record_event(
          sender: ScriptRunner | None,
          event: ScriptRunnerEvent,
          **kwargs,
      ) -> None:
          # Assert that we're not getting unexpected `sender` params
          # from ScriptRunner.on_event
          assert (
              sender is None or sender == self
          ), "Unexpected ScriptRunnerEvent sender!"
  
          self.events.append(event)
          self.event_data.append(kwargs)
  
          # Send ENQUEUE_FORWARD_MSGs to our queue
          if event == ScriptRunnerEvent.ENQUEUE_FORWARD_MSG:
              forward_msg = kwargs["forward_msg"]
              self.forward_msg_queue.enqueue(forward_msg)
  
      self.on_event.connect(record_event, weak=False)
  
imports: from __future__ import annotations
  import os
  import time
  from typing import Any
  from urllib import parse
  from streamlit import runtime
  from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
  from streamlit.proto.WidgetStates_pb2 import WidgetStates
  from streamlit.runtime.forward_msg_queue import ForwardMsgQueue
  from streamlit.runtime.memory_uploaded_file_manager import MemoryUploadedFileManager
  from streamlit.runtime.scriptrunner import RerunData, ScriptRunner, ScriptRunnerEvent
  from streamlit.runtime.scriptrunner.script_cache import ScriptCache
  from streamlit.runtime.scriptrunner.script_run_context import ScriptRunContext
  from streamlit.runtime.state.safe_session_state import SafeSessionState
  from streamlit.testing.v1.element_tree import ElementTree, parse_tree_from_messages
label_desc: Use image node_id 1 to create a new LocalScriptRunner object from inherited base classes: ScriptRunner with example: obj = LocalScriptRunner(script_path, session_state)