code: def test_check_integrity(self):
      var1 = MyVariable("var1")
      var2 = MyVariable("var2")
      var3 = op1(var2, var1)
      var4 = op2(var3, var2)
      var5 = op3(var4, var2, var2)
      fg = FunctionGraph([var1, var2], [var3, var5], clone=False)
  
      with pytest.raises(Exception, match="The following nodes are .*"):
          fg.apply_nodes.remove(var5.owner)
  
          fg.check_integrity()
  
      with pytest.raises(Exception, match="Inconsistent clients.*"):
          fg.apply_nodes.add(var5.owner)
          fg.remove_client(var2, (var5.owner, 1))
  
          fg.check_integrity()
  
      fg.add_client(var2, (var5.owner, 1))
  
      with pytest.raises(
          Exception, match="The following variables are.*"
      ):
          fg.variables.remove(var4)
  
          fg.check_integrity()
  
      fg.variables.add(var4)
  
      with pytest.raises(Exception, match="Undeclared input.*"):
          var6 = MyVariable2("var6")
          fg.clients[var6] = [(var5.owner, 3)]
          fg.variables.add(var6)
          var5.owner.inputs.append(var6)
  
          fg.check_integrity()
  
      fg.variables.remove(var6)
      var5.owner.inputs.remove(var6)
  
      # TODO: What if the index value is greater than 1?  It will throw an
      # `IndexError`, but that doesn't sound like anything we'd want.
      with pytest.raises(
          Exception, match="Inconsistent clients list.*"
      ):
          fg.add_client(var4, ("output", 1))
  
          fg.check_integrity()
  
      fg.remove_client(var4, ("output", 1))
  
      with pytest.raises(TypeError, match="The first entry of.*"):
          fg.add_client(var4, (None, 0))
  
      var7 = op1(var4)
  
      with pytest.raises(
          Exception, match="Client not in FunctionGraph.*"
      ):
          fg.add_client(var4, (var7.owner, 0))
  
          fg.check_integrity()
  
      fg.remove_client(var4, (var7.owner, 0))
  
      with pytest.raises(
          Exception, match="Inconsistent clients list.*"
      ):
          fg.add_client(var4, (var3.owner, 0))
  
          fg.check_integrity()
  
imports: import pickle
  import numpy
  import pytest
  from pytensor.configdefaults import config
  from pytensor.graph.basic import NominalVariable
  from pytensor.graph.fg import FunctionGraph
  from pytensor.graph.utils import MissingInputError
  from tests.graph.utils import MyConstant, MyOp, MyType, MyVariable, MyVariable2, op1, op2, op3
label_desc: Use image node_id 13 for calling the TestFunctionGraph obj's underlying member method code with example usage: obj.test_check_integrity() without return types