code: def test_io_orientation():
      for shape in ((2, 3, 4), (20, 15, 7)):
          for in_arr, out_ornt in zip(IN_ARRS, OUT_ORNTS):
              ornt = io_orientation(in_arr)
              assert_array_equal(ornt, out_ornt)
              taff = inv_ornt_aff(ornt, shape)
              assert same_transform(taff, ornt, shape)
              for axno in range(3):
                  arr = in_arr.copy()
                  ex_ornt = out_ornt.copy()
                  # flip the input axis in affine
                  arr[:, axno] *= -1
                  # check that result shows flip
                  ex_ornt[axno, 1] *= -1
                  ornt = io_orientation(arr)
                  assert_array_equal(ornt, ex_ornt)
                  taff = inv_ornt_aff(ornt, shape)
                  assert same_transform(taff, ornt, shape)
      # Test nasty hang for zero columns
      rzs = np.c_[np.diag([2, 3, 4, 5]), np.zeros((4, 3))]
      arr = from_matvec(rzs, [15, 16, 17, 18])
      ornt = io_orientation(arr)
      assert_array_equal(
          ornt,
          [
              [0, 1],
              [1, 1],
              [2, 1],
              [3, 1],
              [np.nan, np.nan],
              [np.nan, np.nan],
              [np.nan, np.nan],
          ],
      )
      # Test behavior of thresholding
      def_aff = np.array(
          [
              [1.0, 1, 0, 0],
              [0, 0, 0, 0],
              [0, 0, 1, 0],
              [0, 0, 0, 1],
          ]
      )
      fail_tol = np.array(
          [
              [0, 1],
              [np.nan, np.nan],
              [2, 1],
          ]
      )
      pass_tol = np.array(
          [
              [0, 1],
              [1, 1],
              [2, 1],
          ]
      )
      eps = np.finfo(float).eps
      # Test that a Y axis appears as we increase the difference between the
      # first two columns
      for y_val, has_y in (
          (0, False),
          (eps, False),
          (eps * 5, False),
          (eps * 10, True),
      ):
          def_aff[1, 1] = y_val
          res = pass_tol if has_y else fail_tol
          assert_array_equal(io_orientation(def_aff), res)
      # Test tol input argument
      def_aff[1, 1] = eps
      assert_array_equal(io_orientation(def_aff, tol=0), pass_tol)
      def_aff[1, 1] = eps * 10
      assert_array_equal(io_orientation(def_aff, tol=1e-5), fail_tol)
      # Test drop of rows, columns
      mat, vec = to_matvec(def_aff)
      aff_extra_col = np.zeros((4, 5))
      aff_extra_col[
          -1, -1
      ] = 1  # Not strictly necessary, but for completeness
      aff_extra_col[:3, :3] = mat
      aff_extra_col[:3, -1] = vec
      assert_array_equal(
          io_orientation(aff_extra_col, tol=1e-5),
          [
              [0, 1],
              [np.nan, np.nan],
              [2, 1],
              [np.nan, np.nan],
          ],
      )
      aff_extra_row = np.zeros((5, 4))
      aff_extra_row[
          -1, -1
      ] = 1  # Not strictly necessary, but for completeness
      aff_extra_row[:3, :3] = mat
      aff_extra_row[:3, -1] = vec
      assert_array_equal(
          io_orientation(aff_extra_row, tol=1e-5),
          [
              [0, 1],
              [np.nan, np.nan],
              [2, 1],
          ],
      )
  
file_path: nibabel/nibabel/tests/test_orientations.py
imports: import warnings
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from ..affines import from_matvec, to_matvec
  from ..orientations import OrientationError, aff2axcodes, apply_orientation, axcodes2ornt, flip_axis, inv_ornt_aff, io_orientation, ornt2axcodes, ornt_transform
  from ..testing import expires
label_desc: Use image node_id 3 for calling a global function with example usage: test_io_orientation() without return types