code: def test_as_dict(unittest):
      """Should only work if object is an instance of MutableMapping or it implements to_dict"""
  
      from dtale.global_state import DtaleBaseStore
  
      mutable_mapping_instance = DtaleBaseStore(a=1, b=2)
      unittest.assertEqual(
          mutable_mapping_instance,
          global_state._as_dict(mutable_mapping_instance),
      )
  
      class CustomDataStore:
          def __init__(self, keys, values):
              self.keys = keys
              self.values = values
  
      custom_store = CustomDataStore(keys=["a", "b"], values=[1, 2])
  
      # Fails without a to_dict method
      with pytest.raises(AttributeError) as error:
          global_state._as_dict(custom_store)
          assert "has no attribute 'to_dict'" in str(error.value)
  
      # Works if it does have to_dict method
      custom_store.to_dict = lambda: dict(
          zip(custom_store.keys, custom_store.values)
      )
      assert isinstance(global_state._as_dict(custom_store), dict)
  
file_path: dtale/tests/dtale/test_global_state.py
imports: import mock
  import pandas
  import pytest
  import dtale.global_state
  from dtale.views import build_dtypes_state
label_desc: Use image node_id 9 for calling a global function with example usage: test_as_dict(unittest) without return types