code: def test_imagasdouble(self):
      # Test PyComplex_ImagAsDouble()
      imagasdouble = _testcapi.complex_imagasdouble
  
      self.assertEqual(imagasdouble(1 + 2j), 2.0)
      self.assertEqual(imagasdouble(1 - 1j), -1.0)
      self.assertEqual(imagasdouble(4.25), 0.0)
      self.assertEqual(imagasdouble(42), 0.0)
  
      # Test subclasses of complex/float
      self.assertEqual(imagasdouble(ComplexSubclass(1 + 2j)), 2.0)
      self.assertEqual(imagasdouble(FloatSubclass(4.25)), 0.0)
  
      # Test types with __complex__ dunder method
      self.assertEqual(imagasdouble(Complex()), 0.5)
      self.assertRaises(TypeError, imagasdouble, BadComplex())
      with self.assertWarns(DeprecationWarning):
          self.assertEqual(imagasdouble(BadComplex2()), 0.5)
      with warnings.catch_warnings():
          warnings.simplefilter("error", DeprecationWarning)
          self.assertRaises(
              DeprecationWarning, imagasdouble, BadComplex2()
          )
      self.assertRaises(RuntimeError, imagasdouble, BadComplex3())
  
      # Test types with __float__ dunder method
      self.assertEqual(imagasdouble(Float()), 0.0)
      self.assertRaises(TypeError, imagasdouble, BadFloat())
      with self.assertWarns(DeprecationWarning):
          self.assertEqual(imagasdouble(BadFloat2()), 0.0)
  
      self.assertRaises(TypeError, imagasdouble, object())
  
imports: from math import isnan
  import errno
  import unittest
  import warnings
  from test.test_capi.test_getargs import BadComplex, BadComplex2, Complex, FloatSubclass, Float, BadFloat, BadFloat2, ComplexSubclass
  from test.support import import_helper
label_desc: Use image node_id 6 for calling the CAPIComplexTest obj's underlying member method code with example usage: obj.test_imagasdouble() without return types