code: def test_state():
      # init via dict
      inputs = {"key1": 1, "key2": "abc"}
      state = AttributeDict(inputs)
      for key, value in inputs.items():
          assert getattr(state, key) == value
  
      # init via kwargs
      inputs = {"key1": 1, "key2": "abc"}
      state = AttributeDict(**inputs)
      for key, value in inputs.items():
          assert getattr(state, key) == value
  
      # update via dict
      state = AttributeDict()
      state.update({"key1": 1})
      assert state.key1 == 1
  
      # update via setter
      state = AttributeDict({"key1": 1})
      state.key1 = 123
      assert state.key1 == 123
  
      with pytest.raises(
          AttributeError, match="has no attribute 'key3'"
      ):
          _ = state.key3
  
      # delete attribute
      del state.key1
      assert "key1" not in state
      with pytest.raises(KeyError):
          del state.key3
  
imports: import contextlib
  import os
  import random
  from unittest import mock
  from unittest.mock import Mock
  import lightning.fabric
  import numpy
  import pytest
  import torch
  from lightning.fabric.utilities.data import AttributeDict, _get_dataloader_init_args_and_kwargs, _replace_dunder_methods, _replace_value_in_saved_args, _set_sampler_epoch, _update_dataloader, _WrapAttrTag, has_iterable_dataset, has_len, suggested_max_num_workers
  from lightning.fabric.utilities.exceptions import MisconfigurationException
  from lightning_utilities.test.warning import no_warning_call
  from torch import Tensor
  from torch.utils.data import BatchSampler, DataLoader, RandomSampler
  from tests_fabric.helpers.models import RandomDataset, RandomIterableDataset
label_desc: Use image node_id 20 for calling a global function with example usage: test_state() without return types