code: def test_validator_backrefs(self, include_backrefs, include_removes):
      users, addresses = (self.tables.users, self.tables.addresses)
      canary = Mock()
  
      need_remove_param = (
          bool(include_removes) and not include_removes.default
      )
      validate_kw = {}
      if not include_removes.default:
          validate_kw["include_removes"] = bool(include_removes)
      if not include_backrefs.default:
          validate_kw["include_backrefs"] = bool(include_backrefs)
  
      expect_include_backrefs = include_backrefs.default or bool(
          include_backrefs
      )
      expect_include_removes = (
          bool(include_removes) and not include_removes.default
      )
  
      class User(ComparableEntity):
          if need_remove_param:
  
              @validates("addresses", **validate_kw)
              def validate_address(self, key, item, remove):
                  canary(key, item, remove)
                  return item
  
          else:
  
              @validates("addresses", **validate_kw)
              def validate_address(self, key, item):
                  canary(key, item)
                  return item
  
      class Address(ComparableEntity):
          if need_remove_param:
  
              @validates("user", **validate_kw)
              def validate_user(self, key, item, remove):
                  canary(key, item, remove)
                  return item
  
          else:
  
              @validates("user", **validate_kw)
              def validate_user(self, key, item):
                  canary(key, item)
                  return item
  
      self.mapper_registry.map_imperatively(
          User,
          users,
          properties={
              "addresses": relationship(Address, backref="user")
          },
      )
      self.mapper_registry.map_imperatively(Address, addresses)
  
      u1 = User()
      u2 = User()
      a1, a2 = Address(), Address()
  
      # 3 append/set, two removes
      u1.addresses.append(a1)
      u1.addresses.append(a2)
      a2.user = u2
      del a1.user
      u2.addresses.remove(a2)
  
      # copy, so that generation of the
      # comparisons don't get caught
      calls = list(canary.mock_calls)
  
      if expect_include_backrefs:
          if expect_include_removes:
              eq_(
                  calls,
                  [
                      # append #1
                      call("addresses", Address(), False),
                      # backref for append
                      call("user", User(addresses=[]), False),
                      # append #2
                      call("addresses", Address(user=None), False),
                      # backref for append
                      call("user", User(addresses=[]), False),
                      # assign a2.user = u2
                      call("user", User(addresses=[]), False),
                      # backref for u1.addresses.remove(a2)
                      call("addresses", Address(user=None), True),
                      # backref for u2.addresses.append(a2)
                      call("addresses", Address(user=None), False),
                      # del a1.user
                      call("user", User(addresses=[]), True),
                      # backref for u1.addresses.remove(a1)
                      call("addresses", Address(), True),
                      # u2.addresses.remove(a2)
                      call("addresses", Address(user=None), True),
                      # backref for a2.user = None
                      call("user", None, False),
                  ],
              )
          else:
              eq_(
                  calls,
                  [
                      call("addresses", Address()),
                      call("user", User(addresses=[])),
                      call("addresses", Address(user=None)),
                      call("user", User(addresses=[])),
                      call("user", User(addresses=[])),
                      call("addresses", Address(user=None)),
                      call("user", None),
                  ],
              )
      else:
          if expect_include_removes:
              eq_(
                  calls,
                  [
                      call("addresses", Address(), False),
                      call("addresses", Address(user=None), False),
                      call("user", User(addresses=[]), False),
                      call("user", User(addresses=[]), True),
                      call("addresses", Address(user=None), True),
                  ],
              )
          else:
              eq_(
                  calls,
                  [
                      call("addresses", Address()),
                      call("addresses", Address(user=None)),
                      call("user", User(addresses=[])),
                  ],
              )
  
imports: from unittest.mock import call
  from unittest.mock import Mock
  from sqlalchemy import exc
  from sqlalchemy import testing
  from sqlalchemy.orm import collections
  from sqlalchemy.orm import relationship
  from sqlalchemy.orm import validates
  from sqlalchemy.testing import assert_raises
  from sqlalchemy.testing import assert_raises_message
  from sqlalchemy.testing import eq_
  from sqlalchemy.testing import ne_
  from sqlalchemy.testing.entities import ComparableEntity
  from sqlalchemy.testing.fixtures import fixture_session
  from test.orm import _fixtures
label_desc: Use image node_id 9 for calling the ValidatorTest obj's underlying member method code with example usage: obj.test_validator_backrefs(include_backrefs, include_removes) and returns: item, item, item, item