code: def test_flatten(space):
      """Test that a flattened sample have the `flatdim` shape."""
      flattened_sample = utils.flatten(space, space.sample())
  
      if space.is_np_flattenable:
          assert isinstance(flattened_sample, np.ndarray)
          (single_dim,) = flattened_sample.shape
          flatdim = utils.flatdim(space)
  
          assert single_dim == flatdim
      else:
          assert isinstance(flattened_sample, (tuple, dict, Graph))
  
file_path: gym/tests/spaces/test_utils.py
imports: from itertools import zip_longest
  from typing import Optional
  import numpy
  import pytest
  import gym
  from gym.spaces import Box, Graph, utils
  from gym.utils.env_checker import data_equivalence
  from tests.spaces.utils import TESTING_SPACES, TESTING_SPACES_IDS
label_desc: Use image node_id 3 for calling a global function with example usage: test_flatten(space) without return types