code: def test_axcodes2ornt():
      # Go from axcodes back to orientations
      labels = (("left", "right"), ("back", "front"), ("down", "up"))
      assert_array_equal(
          axcodes2ornt(("right", "front", "up"), labels),
          [[0, 1], [1, 1], [2, 1]],
      )
      assert_array_equal(
          axcodes2ornt(("left", "back", "down"), labels),
          [[0, -1], [1, -1], [2, -1]],
      )
      assert_array_equal(
          axcodes2ornt(("down", "back", "left"), labels),
          [[2, -1], [1, -1], [0, -1]],
      )
      assert_array_equal(
          axcodes2ornt(("front", "down", "right"), labels),
          [[1, 1], [2, -1], [0, 1]],
      )
  
      # default is RAS output directions
      default = np.c_[range(3), [1] * 3]
      assert_array_equal(axcodes2ornt(("R", "A", "S")), default)
  
      # dropped axes produce None
      assert_array_equal(
          axcodes2ornt(("R", None, "S")),
          [[0, 1], [np.nan, np.nan], [2, 1]],
      )
  
      # Missing axcodes raise an error
      assert_array_equal(axcodes2ornt("RAS"), default)
      with pytest.raises(ValueError):
          axcodes2ornt("rAS")
      # None is OK as axis code
      assert_array_equal(
          axcodes2ornt(("R", None, "S")),
          [[0, 1], [np.nan, np.nan], [2, 1]],
      )
      # Bad axis code with None also raises error.
      with pytest.raises(ValueError):
          axcodes2ornt(("R", None, "s"))
      # Axis codes checked with custom labels
      labels = ("SD", "BF", "lh")
      assert_array_equal(
          axcodes2ornt("BlD", labels), [[1, -1], [2, -1], [0, 1]]
      )
      with pytest.raises(ValueError):
          axcodes2ornt("blD", labels)
  
      # Duplicate labels
      for labels in [("SD", "BF", "lD"), ("SD", "SF", "lD")]:
          with pytest.raises(ValueError):
              axcodes2ornt("blD", labels)
  
      for axcodes, ornt in zip(ALL_AXCODES, ALL_ORNTS):
          assert_array_equal(axcodes2ornt(axcodes), ornt)
  
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 6 for calling a global function with example usage: test_axcodes2ornt() without return types