code: def test_astype_copyflag():
      # test the various copyflag options
      arr = np.arange(10, dtype=np.intp)
  
      res_true = arr.astype(np.intp, copy=True)
      assert not np.may_share_memory(arr, res_true)
      res_always = arr.astype(np.intp, copy=np._CopyMode.ALWAYS)
      assert not np.may_share_memory(arr, res_always)
  
      res_false = arr.astype(np.intp, copy=False)
      # `res_false is arr` currently, but check `may_share_memory`.
      assert np.may_share_memory(arr, res_false)
      res_if_needed = arr.astype(np.intp, copy=np._CopyMode.IF_NEEDED)
      # `res_if_needed is arr` currently, but check `may_share_memory`.
      assert np.may_share_memory(arr, res_if_needed)
  
      res_never = arr.astype(np.intp, copy=np._CopyMode.NEVER)
      assert np.may_share_memory(arr, res_never)
  
      # Simple tests for when a copy is necessary:
      res_false = arr.astype(np.float64, copy=False)
      assert_array_equal(res_false, arr)
      res_if_needed = arr.astype(
          np.float64, copy=np._CopyMode.IF_NEEDED
      )
      assert_array_equal(res_if_needed, arr)
      assert_raises(
          ValueError, arr.astype, np.float64, copy=np._CopyMode.NEVER
      )
  
imports: import sys
  import numpy
  from numpy.core._rational_tests import rational
  import pytest
  from numpy.testing import assert_, assert_equal, assert_array_equal, assert_raises, assert_warns, HAS_REFCOUNT
label_desc: Use image node_id 20 for calling a global function with example usage: test_astype_copyflag() without return types