code: def test_flatten_inference_data_to_dict(
      inference_data,
      var_names,
      groups,
      dimensions,
      group_info,
      var_name_format,
      index_origin,
  ):
      """Test flattening (stacking) inference data (subgroups) for dictionary."""
      res_dict = flatten_inference_data_to_dict(
          data=inference_data,
          var_names=var_names,
          groups=groups,
          dimensions=dimensions,
          group_info=group_info,
          var_name_format=var_name_format,
          index_origin=index_origin,
      )
      assert res_dict
      assert "draw" in res_dict
      assert any("mu" in item for item in res_dict)
      if group_info:
          if groups != "prior_groups":
              assert any("posterior" in item for item in res_dict)
              if var_names is None:
                  assert any(
                      "sample_stats" in item for item in res_dict
                  )
          else:
              assert any("prior" in item for item in res_dict)
      elif groups == "prior_groups":
          assert all("prior" not in item for item in res_dict)
  
      else:
          assert all("posterior" not in item for item in res_dict)
          if var_names is None:
              assert all(
                  "sample_stats" not in item for item in res_dict
              )
  
imports: from unittest.mock import Mock
  import numpy
  import pytest
  import scipy.stats
  from ...data import dict_to_dataset, from_dict, load_arviz_data
  from ...stats.density_utils import _circular_mean, _normalize_angle, _find_hdi_contours
  from ...utils import _stack, _subset_list, _var_names, expand_dims, flatten_inference_data_to_dict, one_de, two_de
  from ..helpers import TestRandomVariable
label_desc: Use image node_id 21 for calling a global function with example usage: test_flatten_inference_data_to_dict(inference_data, var_names, groups, dimensions, group_info, var_name_format, index_origin) without return types