code: def test_roundtrip_array_capsule(
      arr, schema_accessor, bad_type, good_type
  ):
      gc.collect()  # Make sure no Arrow data dangles in a ref cycle
      old_allocated = pa.total_allocated_bytes()
  
      import_array = type(arr)._import_from_c_capsule
  
      schema_capsule, capsule = arr.__arrow_c_array__()
      assert PyCapsule_IsValid(schema_capsule, b"arrow_schema") == 1
      assert PyCapsule_IsValid(capsule, b"arrow_array") == 1
      arr_out = import_array(schema_capsule, capsule)
      assert arr_out.equals(arr)
  
      assert pa.total_allocated_bytes() > old_allocated
      del arr_out
  
      assert pa.total_allocated_bytes() == old_allocated
  
      capsule = arr.__arrow_c_array__()
  
      assert pa.total_allocated_bytes() > old_allocated
      del capsule
      assert pa.total_allocated_bytes() == old_allocated
  
      with pytest.raises(
          ValueError,
          match=r"Could not cast.* string to requested .* int32",
      ):
          arr.__arrow_c_array__(bad_type.__arrow_c_schema__())
  
      schema_capsule, array_capsule = arr.__arrow_c_array__(
          good_type.__arrow_c_schema__()
      )
      arr_out = import_array(schema_capsule, array_capsule)
      assert schema_accessor(arr_out) == good_type
  
imports: import contextlib
  import ctypes
  import gc
  import pyarrow
  import pytest
label_desc: Use image node_id 27 for calling a global function with example usage: test_roundtrip_array_capsule(arr, schema_accessor, bad_type, good_type) without return types