code: def test_set_levels_codes_directly(idx):
      # setting levels/codes directly raises AttributeError
  
      levels = idx.levels
      new_levels = [[lev + "a" for lev in level] for level in levels]
  
      codes = idx.codes
      major_codes, minor_codes = codes
      major_codes = [(x + 1) % 3 for x in major_codes]
      minor_codes = [(x + 1) % 1 for x in minor_codes]
      new_codes = [major_codes, minor_codes]
  
      msg = "Can't set attribute"
      with pytest.raises(AttributeError, match=msg):
          idx.levels = new_levels
  
      msg = (
          "property 'codes' of 'MultiIndex' object has no setter"
          if PY311
          else "can't set attribute"
      )
      with pytest.raises(AttributeError, match=msg):
          idx.codes = new_codes
  
imports: import numpy
  import pytest
  from pandas.compat import PY311
  from pandas.core.dtypes.dtypes import DatetimeTZDtype
  import pandas
  from pandas import CategoricalIndex, MultiIndex
  import pandas._testing
label_desc: Use image node_id 8 for calling a global function with example usage: test_set_levels_codes_directly(idx) without return types