code: def create_lazy_graph_instance(
      cls_name: str, *init_args, **init_kwargs
  ) -> mock.NonCallableMagicMock:
      cls = getattr(graphviz, cls_name)
      if cls not in (graphviz.Graph, graphviz.Digraph):
          raise ValueError(f"cls_name: {cls_name!r}")
  
      fake = mock.create_autospec(cls, instance=True, spec_set=True)
  
      fake.copy.side_effect = NotImplementedError  # TODO
  
      def make_real_inst(calls):
          dot = cls(*init_args, **init_kwargs)
          for method_name, args, kwargs in calls:
              method = getattr(dot, method_name)
              method(*args, **kwargs)  # ignore return value
          return dot
  
      def make_methodcaller(method_name):
          def call_method(*args, **kwargs):
              last_call = fake.mock_calls.pop()
              assert last_call == getattr(mock.call, method_name)(
                  *args, **kwargs
              )
  
              dot = make_real_inst(fake.mock_calls)
              method = getattr(dot, method_name)
              return method(*args, **kwargs)
  
          return call_method
  
      for method_name in RENDERING_METHODS:
          getattr(fake, method_name).side_effect = make_methodcaller(
              method_name
          )
  
      def make_property(property_name):
          def property_func(*args):
              last_call = property_mock.mock_calls.pop()
              assert last_call == mock.call(*args)
              assert not property_mock.mock_calls
  
              dot = make_real_inst(fake.mock_calls)
              property_obj = getattr(dot.__class__, property_name)
              property_func = (
                  property_obj.fset if args else property_obj.fget
              )
              return property_func(dot, *args)
  
          property_mock = mock.PropertyMock(side_effect=property_func)
          return property_mock
  
      for property_name in INPUT_PROPERTIES:
          setattr(
              type(fake), property_name, make_property(property_name)
          )
  
      return fake
  
imports: import functools
  from unittest import mock
  import graphviz
label_desc: Use image node_id 2 for calling a global function with example usage: create_lazy_graph_instance(cls_name) and returns: fake, dot, call_method, property_mock, method, property_func