code: def test_rename_fields_exception():
      # If no replace_with field is given, an AssertionError will be raised
      d = {"api_server.port": 5000}
      with pytest.raises(
          AssertionError, match="'replace_with' must be provided."
      ):
          rename_fields(d, "api_server.port")
  
      with pytest.raises(
          AssertionError, match="'replace_with' must be provided."
      ):
          rename_fields(d, "api_server.port", remove_only=False)
  
      # If the given dictionary is not flattened, a ValueError will be raised
      d = {"a": 1, "b": {"c": 2}}
      with pytest.raises(
          ValueError, match="Given dictionary is not flattened. *"
      ):
          rename_fields(d, "b.c", "b.d.c")
  
      # If the given dictionary is not flattened + no replace_with field is given, a ValueError will be raised
      d = {"a": 1, "b": {"c": 2}}
      with pytest.raises(
          ValueError, match="Given dictionary is not flattened. *"
      ):
          rename_fields(d, "b.c")
  
imports: from __future__ import annotations
  import logging
  from typing import TYPE_CHECKING
  import pytest
  from bentoml._internal.configuration.helpers import expand_env_var_in_values
  from bentoml._internal.configuration.helpers import flatten_dict
  from bentoml._internal.configuration.helpers import is_valid_ip_address
  from bentoml._internal.configuration.helpers import load_config_file
  from bentoml._internal.configuration.helpers import rename_fields
  from bentoml.exceptions import BentoMLConfigException
label_desc: Use image node_id 7 for calling a global function with example usage: test_rename_fields_exception() without return types