code: def test_should_explain_output(mocker):
      mock_get_gradients = mocker.patch(
          "tf_explain.core.grad_cam.GradCAM.get_gradients_and_filters",
          return_value=(
              [
                  mocker.sentinel.conv_output_1,
                  mocker.sentinel.conv_output_2,
              ],
              [
                  mocker.sentinel.guided_grads_1,
                  mocker.sentinel.guided_grads_2,
              ],
          ),
      )
      mocker.sentinel.cam_1.numpy = lambda: mocker.sentinel.cam_1
      mocker.sentinel.cam_2.numpy = lambda: mocker.sentinel.cam_2
      mock_generate_output = mocker.patch(
          "tf_explain.core.grad_cam.GradCAM.generate_ponderated_output",
          return_value=[mocker.sentinel.cam_1, mocker.sentinel.cam_2],
      )
      mocker.patch(
          "tf_explain.core.grad_cam.heatmap_display",
          side_effect=[
              mocker.sentinel.heatmap_1,
              mocker.sentinel.heatmap_2,
          ],
      )
      mocker.patch(
          "tf_explain.core.grad_cam.grid_display",
          side_effect=lambda x: x,
      )
  
      explainer = GradCAM()
      data = (
          [mocker.sentinel.image_1, mocker.sentinel.image_2],
          mocker.sentinel.labels,
      )
      grid = explainer.explain(
          data,
          mocker.sentinel.model,
          mocker.sentinel.class_index,
          mocker.sentinel.layer_name,
          mocker.sentinel.use_guided_grads,
      )
  
      for heatmap, expected_heatmap in zip(
          grid, [mocker.sentinel.heatmap_1, mocker.sentinel.heatmap_2]
      ):
          assert heatmap == expected_heatmap
  
      mock_get_gradients.assert_called_once_with(
          mocker.sentinel.model,
          [mocker.sentinel.image_1, mocker.sentinel.image_2],
          mocker.sentinel.layer_name,
          mocker.sentinel.class_index,
          mocker.sentinel.use_guided_grads,
      )
  
      mock_generate_output.assert_called_once_with(
          [
              mocker.sentinel.conv_output_1,
              mocker.sentinel.conv_output_2,
          ],
          [
              mocker.sentinel.guided_grads_1,
              mocker.sentinel.guided_grads_2,
          ],
      )
  
file_path: tf-explain/tests/core/test_grad_cam.py
imports: import numpy
  import pytest
  import tensorflow
  from tf_explain.core.grad_cam import GradCAM
label_desc: Use image node_id 4 for calling a global function with example usage: test_should_explain_output(mocker) without return types