code: def test_coalesce_widget_states(self):
      session_state = SessionState()
  
      old_states = WidgetStates()
  
      _create_widget("old_set_trigger", old_states).trigger_value = True
      _create_widget(
          "old_unset_trigger", old_states
      ).trigger_value = False
      _create_widget(
          "old_set_string_trigger", old_states
      ).string_trigger_value.CopyFrom(
          StringTriggerValueProto(data="Some String")
      )
      _create_widget(
          "old_set_empty_string_trigger", old_states
      ).string_trigger_value.CopyFrom(StringTriggerValueProto(data=""))
      _create_widget(
          "old_unset_string_trigger", old_states
      ).string_trigger_value.CopyFrom(
          StringTriggerValueProto(data=None)
      )
      _create_widget("missing_in_new", old_states).int_value = 123
      _create_widget(
          "shape_changing_trigger", old_states
      ).trigger_value = True
  
      session_state._set_widget_metadata(
          create_metadata("old_set_trigger", "trigger_value")
      )
      session_state._set_widget_metadata(
          create_metadata("old_unset_trigger", "trigger_value")
      )
      session_state._set_widget_metadata(
          create_metadata(
              "old_set_string_trigger", "string_trigger_value"
          )
      )
      session_state._set_widget_metadata(
          create_metadata(
              "old_set_empty_string_trigger", "string_trigger_value"
          )
      )
      session_state._set_widget_metadata(
          create_metadata(
              "old_unset_string_trigger", "string_trigger_value"
          )
      )
      session_state._set_widget_metadata(
          create_metadata("missing_in_new", "int_value")
      )
      session_state._set_widget_metadata(
          create_metadata("shape changing trigger", "trigger_value")
      )
  
      new_states = WidgetStates()
  
      _create_widget(
          "old_set_trigger", new_states
      ).trigger_value = False
      _create_widget("new_set_trigger", new_states).trigger_value = True
      _create_widget(
          "old_set_string_trigger", new_states
      ).string_trigger_value.CopyFrom(
          StringTriggerValueProto(data=None)
      )
      _create_widget(
          "old_set_empty_string_trigger", new_states
      ).string_trigger_value.CopyFrom(
          StringTriggerValueProto(data=None)
      )
      _create_widget(
          "new_set_string_trigger", new_states
      ).string_trigger_value.CopyFrom(
          StringTriggerValueProto(data="Some other string")
      )
      _create_widget("added_in_new", new_states).int_value = 456
      _create_widget("shape_changing_trigger", new_states).int_value = 3
      session_state._set_widget_metadata(
          create_metadata("new_set_trigger", "trigger_value")
      )
      session_state._set_widget_metadata(
          create_metadata(
              "new_set_string_trigger", "string_trigger_value"
          )
      )
      session_state._set_widget_metadata(
          create_metadata("added_in_new", "int_value")
      )
      session_state._set_widget_metadata(
          create_metadata("shape_changing_trigger", "int_value")
      )
  
      session_state.set_widgets_from_proto(
          coalesce_widget_states(old_states, new_states)
      )
  
      self.assertRaises(
          KeyError, lambda: session_state["old_unset_trigger"]
      )
      self.assertRaises(
          KeyError, lambda: session_state["missing_in_new"]
      )
      self.assertRaises(
          KeyError, lambda: session_state["old_unset_string_trigger"]
      )
  
      self.assertEqual(True, session_state["old_set_trigger"])
      self.assertEqual(True, session_state["new_set_trigger"])
      self.assertEqual(456, session_state["added_in_new"])
      self.assertEqual(
          "Some String", session_state["old_set_string_trigger"].data
      )
      self.assertEqual(
          "", session_state["old_set_empty_string_trigger"].data
      )
      self.assertEqual(
          "Some other string",
          session_state["new_set_string_trigger"].data,
      )
  
      # Widgets that were triggers before, but no longer are, will *not*
      # be coalesced
      self.assertEqual(3, session_state["shape_changing_trigger"])
  
imports: import inspect
  import unittest
  from unittest.mock import ANY, MagicMock, call, patch
  from parameterized import parameterized
  import streamlit
  from streamlit import errors
  from streamlit.proto.Common_pb2 import StringTriggerValue
  from streamlit.proto.WidgetStates_pb2 import WidgetStates
  from streamlit.runtime.scriptrunner.script_run_context import get_script_run_ctx
  from streamlit.runtime.state import coalesce_widget_states
  from streamlit.runtime.state.common import GENERATED_WIDGET_ID_PREFIX, compute_widget_id
  from streamlit.runtime.state.session_state import SessionState, WidgetMetadata
  from streamlit.runtime.state.widgets import user_key_from_widget_id
  from tests.delta_generator_test_case import DeltaGeneratorTestCase
label_desc: Use image node_id 9 for calling the WidgetManagerTests obj's underlying member method code with example usage: obj.test_coalesce_widget_states() without return types