docstr: Test custom format function for each element in array.
docstr_tok: ["Test","custom","format","function","for","each","element","in","array","."]
code: def test_format_function(self):
      """Test custom format function for each element in array."""
  
      def _format_function(x):
          if np.abs(x) < 1:
              return "."
          elif np.abs(x) < 2:
              return "o"
          else:
              return "O"
  
      x = np.arange(3)
      x_hex = "[0x0 0x1 0x2]"
      x_oct = "[0o0 0o1 0o2]"
      assert_(
          np.array2string(x, formatter={"all": _format_function})
          == "[. o O]"
      )
      assert_(
          np.array2string(x, formatter={"int_kind": _format_function})
          == "[. o O]"
      )
      assert_(
          np.array2string(x, formatter={"all": lambda x: "%.4f" % x})
          == "[0.0000 1.0000 2.0000]"
      )
      assert_equal(
          np.array2string(x, formatter={"int": lambda x: hex(x)}), x_hex
      )
      assert_equal(
          np.array2string(x, formatter={"int": lambda x: oct(x)}), x_oct
      )
  
      x = np.arange(3.0)
      assert_(
          np.array2string(
              x, formatter={"float_kind": lambda x: "%.2f" % x}
          )
          == "[0.00 1.00 2.00]"
      )
      assert_(
          np.array2string(x, formatter={"float": lambda x: "%.2f" % x})
          == "[0.00 1.00 2.00]"
      )
  
      s = np.array(["abc", "def"])
      assert_(
          np.array2string(s, formatter={"numpystr": lambda s: s * 2})
          == "[abcabc defdef]"
      )
  
imports: import sys
  import gc
  from hypothesis import given
  from hypothesis.extra import numpy
  import pytest
  import numpy
  from numpy.testing import assert_, assert_equal, assert_raises, assert_warns, HAS_REFCOUNT, assert_raises_regex
  from numpy.core.arrayprint import _typelessdata
  import textwrap
label_desc: Use image node_id 3 for calling the TestArray2String obj's underlying member method code with example usage: obj.test_format_function() and returns: str, str, str