code: def test_magic_methods_and_spec_set(self):
      class Iterable(object):
          def __iter__(self):
              pass
  
      mock = Mock(spec_set=Iterable)
      self.assertRaises(AttributeError, lambda: mock.__iter__)
  
      mock.__iter__ = Mock(return_value=iter([]))
      self.assertEqual(list(mock), [])
  
      class NonIterable(object):
          pass
  
      mock = Mock(spec_set=NonIterable)
      self.assertRaises(AttributeError, lambda: mock.__iter__)
  
      def set_int():
          mock.__int__ = Mock(return_value=iter([]))
  
      self.assertRaises(AttributeError, set_int)
  
      mock = MagicMock(spec_set=Iterable)
      self.assertEqual(list(mock), [])
      self.assertRaises(AttributeError, set_int)
  
imports: import math
  import unittest
  import os
  from asyncio import iscoroutinefunction
  from unittest.mock import AsyncMock, Mock, MagicMock, _magics
label_desc: Use image node_id 21 for calling the TestMockingMagicMethods obj's underlying member method code with example usage: obj.test_magic_methods_and_spec_set() without return types