code: def test_evaluate_func(
      model,
      data: np.ndarray,
      params: dict,
      expected: Union[float, dict, bool],
  ):
      x_batch, y_batch = data["x_batch"], data["y_batch"]
      explain = params.get("explain_func", None)
      explain_func_kwargs = params.get("explain_func_kwargs", None)
      return_as_df = params.get("return_as_df", None)
  
      call_kwargs = params.get("call_kwargs", None)
      try:
          call_kwargs = eval(params["call_kwargs"])
      except Exception as e:
          print(e)
  
      if explain_func_kwargs is not None:
          a_batch = explain(
              model=model,
              inputs=x_batch,
              targets=y_batch,
              **explain_func_kwargs,
          )
  
      if "None" in expected:
          results = evaluate(
              metrics=eval(params["eval_metrics"]),
              xai_methods=eval(params["eval_xai_methods"]),
              model=model,
              x_batch=x_batch,
              y_batch=y_batch,
              agg_func=np.mean,
              explain_func_kwargs=explain_func_kwargs,
              call_kwargs=call_kwargs,
              return_as_df=return_as_df,
          )
          assert results == None, "Test failed."
  
      else:
          results = evaluate(
              metrics=eval(params["eval_metrics"]),
              xai_methods=eval(params["eval_xai_methods"]),
              model=model,
              x_batch=x_batch,
              y_batch=y_batch,
              agg_func=np.mean,
              explain_func_kwargs=explain_func_kwargs,
              call_kwargs=call_kwargs,
              return_as_df=return_as_df,
          )
  
          if return_as_df:
              assert isinstance(results, pd.DataFrame), "Test failed."
          else:
              assert isinstance(results, dict), "Test failed."
  
          # Slice from result dictionary.
          index_metric, index_method = 0, 0
          xai_method = list(eval(params["eval_xai_methods"]).keys())[
              index_method
          ]
          metric = list(eval(params["eval_metrics"]).keys())[
              index_metric
          ]
  
          if call_kwargs is not None:
              if len(call_kwargs) > 1:
                  index_call = 0
                  call_run = list(call_kwargs.keys())[index_call]
                  results[xai_method][metric][call_run] >= expected[
                      "min"
                  ], "Test failed."
                  results[xai_method][metric][call_run] <= expected[
                      "max"
                  ], "Test failed."
              return None
          assert (
              results[xai_method][metric] >= expected["min"]
          ), "Test failed."
          assert (
              results[xai_method][metric] <= expected["max"]
          ), "Test failed."
  
file_path: Quantus/tests/test_evaluation.py
imports: from typing import Union
  import pandas
  import pytest
  from pytest_lazyfixture import lazy_fixture
  import numpy
  from quantus.evaluation import evaluate
  from quantus.functions.explanation_func import explain
  from quantus.metrics.complexity import Sparseness, Complexity
  from quantus.metrics.robustness import MaxSensitivity
label_desc: Use image node_id 1 for calling a global function with example usage: test_evaluate_func(model, data, params, expected) and returns: None