def assetIntegerBoundsChecking(self, integer_fn, message_module):
    """Verifies bounds checking for scalar integer fields.

    Args:
      integer_fn: A function to wrap the integers that will be assigned.
      message_module: unittest_pb2 or unittest_proto3_arena_pb2
    """
    def TestMinAndMaxIntegers(field_name, expected_min, expected_max):
      pb = message_module.TestAllTypes()
      expected_min = integer_fn(expected_min)
      expected_max = integer_fn(expected_max)
      setattr(pb, field_name, expected_min)
      self.assertEqual(expected_min, getattr(pb, field_name))
      setattr(pb, field_name, expected_max)
      self.assertEqual(expected_max, getattr(pb, field_name))
      self.assertRaises((ValueError, TypeError), setattr, pb, field_name,
                        expected_min - 1)
      self.assertRaises((ValueError, TypeError), setattr, pb, field_name,
                        expected_max + 1)

    TestMinAndMaxIntegers('optional_int32', -(1 << 31), (1 << 31) - 1)
    TestMinAndMaxIntegers('optional_uint32', 0, 0xffffffff)
    TestMinAndMaxIntegers('optional_int64', -(1 << 63), (1 << 63) - 1)
    TestMinAndMaxIntegers('optional_uint64', 0, 0xffffffffffffffff)
    # A bit of white-box testing since -1 is an int and not a long in C++ and
    # so goes down a different path.
    pb = message_module.TestAllTypes()
    with self.assertRaises((ValueError, TypeError)):
      pb.optional_uint64 = integer_fn(-(1 << 63))

    pb = message_module.TestAllTypes()
    pb.optional_nested_enum = integer_fn(1)
    self.assertEqual(1, pb.optional_nested_enum)
Verifies bounds checking for scalar integer fields.

    Args:
      integer_fn: A function to wrap the integers that will be assigned.
      message_module: unittest_pb2 or unittest_proto3_arena_pb2
    
deps/protobuf/python/google/protobuf/internal/reflection_test.py