code: def test_save_load_stateful_objects(tmp_path):
      """Test that stateful objects other than modules and optimizers get converted and loaded correctly."""
  
      class Fruit:
          count = 1
  
          def state_dict(self):
              return {"count": self.count}
  
          def load_state_dict(self, state_dict):
              self.count = state_dict["count"]
  
      state = Fruit()
      state.count = 100
      assert isinstance(state, _Stateful)
      strategy = (
          SingleDeviceStrategy()
      )  # surrogate class to test implementation in base class
      strategy.save_checkpoint(
          tmp_path / "checkpoint.ckpt", {"state": state}
      )
      state = Fruit()
      assert state.count == 1
      strategy.load_checkpoint(
          tmp_path / "checkpoint.ckpt", {"state": state}
      )
      assert state.count == 100
  
imports: from unittest import mock
  from unittest.mock import Mock, PropertyMock
  import pytest
  import torch
  from lightning.fabric.plugins import DoublePrecision, HalfPrecision, Precision
  from lightning.fabric.strategies import SingleDeviceStrategy
  from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_0
  from lightning.fabric.utilities.types import _Stateful
  from tests_fabric.helpers.runif import RunIf
label_desc: Use image node_id 4 for calling a global function with example usage: test_save_load_stateful_objects(tmp_path) and returns: dict