code: def test_append_diag():
      # Routine for appending diagonal elements
      assert_array_equal(
          append_diag(np.diag([2, 3, 1]), [1]), np.diag([2, 3, 1, 1])
      )
      assert_array_equal(
          append_diag(np.diag([2, 3, 1]), [1, 1]),
          np.diag([2, 3, 1, 1, 1]),
      )
      aff = np.array(
          [
              [2, 0, 0],
              [0, 3, 0],
              [0, 0, 1],
              [0, 0, 1],
          ]
      )
      assert_array_equal(
          append_diag(aff, [5], [9]),
          [
              [2, 0, 0, 0],
              [0, 3, 0, 0],
              [0, 0, 0, 1],
              [0, 0, 5, 9],
              [0, 0, 0, 1],
          ],
      )
      assert_array_equal(
          append_diag(aff, [5, 6], [9, 10]),
          [
              [2, 0, 0, 0, 0],
              [0, 3, 0, 0, 0],
              [0, 0, 0, 0, 1],
              [0, 0, 5, 0, 9],
              [0, 0, 0, 6, 10],
              [0, 0, 0, 0, 1],
          ],
      )
      aff = np.array(
          [
              [2, 0, 0, 0],
              [0, 3, 0, 0],
              [0, 0, 0, 1],
          ]
      )
      assert_array_equal(
          append_diag(aff, [5], [9]),
          [
              [2, 0, 0, 0, 0],
              [0, 3, 0, 0, 0],
              [0, 0, 0, 5, 9],
              [0, 0, 0, 0, 1],
          ],
      )
      # Length of starts has to match length of steps
      with pytest.raises(AffineError):
          append_diag(aff, [5, 6], [9])
  
file_path: nibabel/nibabel/tests/test_affines.py
imports: from itertools import product
  import numpy
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
  from ..affines import AffineError, append_diag, apply_affine, dot_reduce, from_matvec, obliquity, rescale_affine, to_matvec, voxel_sizes
  from ..eulerangles import euler2mat
  from ..orientations import aff2axcodes
label_desc: Use image node_id 4 for calling a global function with example usage: test_append_diag() without return types