code: def test_app_state_state_access():
      """Test the many ways an AppState object can be accessed to set or get attributes on the state."""
      mocked_state = {
          "vars": {"root_var": "root"},
          "flows": {
              "child0": {
                  "vars": {"child_var": 1},
                  "flows": {},
                  "works": {},
              }
          },
          "works": {
              "work0": {
                  "vars": {"work_var": 2},
                  "flows": {},
                  "works": {},
              }
          },
      }
  
      state = AppState()
      state._state = state._last_state = mocked_state
  
      assert state.root_var == "root"
      assert isinstance(state.child0, AppState)
      assert isinstance(state.work0, AppState)
      assert state.child0.child_var == 1
      assert state.work0.work_var == 2
  
      with pytest.raises(
          AttributeError,
          match="Failed to access 'non_existent_var' through `AppState`.",
      ):
          _ = state.work0.non_existent_var
  
      with pytest.raises(
          AttributeError,
          match="Failed to access 'non_existent_var' through `AppState`.",
      ):
          state.work0.non_existent_var = 22
  
      # TODO: improve msg
      with pytest.raises(
          AttributeError, match="You shouldn't set the flows"
      ):
          state.child0 = "child0"
  
      # TODO: verify with tchaton
      with pytest.raises(
          AttributeError, match="You shouldn't set the works"
      ):
          state.work0 = "work0"
  
imports: import os
  from re import escape
  from unittest import mock
  import lightning.app
  import pytest
  import requests
  from lightning.app import LightningApp, LightningFlow, LightningWork
  from lightning.app.structures import Dict, List
  from lightning.app.utilities.app_helpers import AppStatePlugin, BaseStatePlugin
  from lightning.app.utilities.state import AppState
  from lightning_cloud.openapi import Externalv1LightningappInstance, V1LightningappInstanceStatus
label_desc: Use image node_id 3 for calling a global function with example usage: test_app_state_state_access() without return types