code: def test_get_affine_from_reference():
      filename = os.path.join(data_path, "example_nifti2.nii.gz")
      img = nib.load(filename)
      affine = img.affine
  
      # Get affine from an numpy array.
      assert_array_equal(get_affine_from_reference(affine), affine)
      wrong_ref = np.array([[1, 2, 3], [4, 5, 6]])
      with pytest.raises(ValueError):
          get_affine_from_reference(wrong_ref)
  
      # Get affine from a `SpatialImage`.
      assert_array_equal(get_affine_from_reference(img), affine)
  
      # Get affine from a `SpatialImage` using by its filename.
      assert_array_equal(get_affine_from_reference(filename), affine)
  
file_path: nibabel/nibabel/streamlines/tests/test_utils.py
imports: import os
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  import nibabel
  from nibabel.testing import data_path
  from ..utils import get_affine_from_reference
label_desc: Use image node_id 1 for calling a global function with example usage: test_get_affine_from_reference() without return types