code: def assert_rst(sig, doc, allowed_rtypes=(None,)):
      # Parse RST from the docstring and generate an XML tree:
      doctree = docutils.core.publish_doctree(
          doc,
          settings_overrides={
              "report_level": docutils.utils.Reporter.SEVERE_LEVEL + 1,
          },
      ).asdom()
  
      def get_all_text(node):
          if node.nodeType == node.TEXT_NODE:
              return node.data
          else:
              text_string = ""
              for child_node in node.childNodes:
                  if child_node.nodeName == "system_message":
                      # skip warnings/errors
                      continue
                  if child_node.nodeName == "literal":
                      tmpl = "``%s``"
                  else:
                      tmpl = "%s"
                  text_string += tmpl % (get_all_text(child_node),)
              return text_string
  
      documented_rtype = None
      documented_types = {}
      documented_params = []
      for field in doctree.getElementsByTagName("field"):
          field_name = get_all_text(
              field.getElementsByTagName("field_name")[0]
          )
          if field_name == "rtype":
              assert (
                  documented_rtype is None
              ), "There must be single :rtype: directive"
              field_body = get_all_text(
                  field.getElementsByTagName("field_body")[0]
              )
              assert field_body, ":rtype: directive must have a value"
              documented_rtype = field_body.replace("\n", " ")
          if field_name.startswith("type"):
              parts = field_name.split(" ")  # ['type', 'ssl_context']
              param_name = parts[-1]
              assert (
                  param_name not in documented_types
              ), "Duplicate `type` definition"
              field_body = get_all_text(
                  field.getElementsByTagName("field_body")[0]
              )
              documented_types[param_name] = field_body
          if field_name.startswith("param"):
              parts = field_name.split(" ")  # ['param', 'str', 'query']
              param_name = parts[-1]
              documented_params.append(param_name)
              if len(parts) == 3:
                  assert (
                      param_name not in documented_types
                  ), "Duplicate `type` definition"
                  documented_types[param_name] = parts[1]
  
      method_params = list(sig.parameters.keys())[1:]  # skip `self`
  
      assert method_params == documented_params, (
          "Actual method params set or order doesn't match the documented "
          ":param ...: directives in the docstring."
      )
      missing_types = set(documented_params) - documented_types.keys()
      assert not missing_types, "Not all params have types"
      assert set(documented_types.keys()) == set(
          documented_params
      ), "There are extraneous :type: directives"
      assert documented_rtype in allowed_rtypes
  
file_path: geopy/test/geocoders/__init__.py
imports: import importlib
  import inspect
  import pkgutil
  import docutils.core
  import docutils.utils
  import pytest
  import geopy.geocoders
  from geopy.geocoders.base import DEFAULT_SENTINEL, Geocoder
label_desc: Use image node_id 2 for calling a global function with example usage: assert_rst(sig, doc, allowed_rtypes) and returns: node, text_string