Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: third_party/protobuf/python/google/protobuf/internal/reflection_test.py

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/python/google/protobuf/internal/reflection_test.py
diff --git a/third_party/protobuf/python/google/protobuf/internal/reflection_test.py b/third_party/protobuf/python/google/protobuf/internal/reflection_test.py
index 0e8810157825a72ba007d601407f07f12190fc45..6dc2fffe2b927afd0efb6947bca3f8b268df3c75 100755
--- a/third_party/protobuf/python/google/protobuf/internal/reflection_test.py
+++ b/third_party/protobuf/python/google/protobuf/internal/reflection_test.py
@@ -60,13 +60,9 @@ from google.protobuf.internal import more_messages_pb2
from google.protobuf.internal import message_set_extensions_pb2
from google.protobuf.internal import wire_format
from google.protobuf.internal import test_util
-from google.protobuf.internal import testing_refleaks
from google.protobuf.internal import decoder
-BaseTestCase = testing_refleaks.BaseTestCase
-
-
class _MiniDecoder(object):
"""Decodes a stream of values from a string.
@@ -99,12 +95,12 @@ class _MiniDecoder(object):
return wire_format.UnpackTag(self.ReadVarint())
def ReadFloat(self):
- result = struct.unpack('<f', self._bytes[self._pos:self._pos+4])[0]
+ result = struct.unpack("<f", self._bytes[self._pos:self._pos+4])[0]
self._pos += 4
return result
def ReadDouble(self):
- result = struct.unpack('<d', self._bytes[self._pos:self._pos+8])[0]
+ result = struct.unpack("<d", self._bytes[self._pos:self._pos+8])[0]
self._pos += 8
return result
@@ -112,7 +108,7 @@ class _MiniDecoder(object):
return self._pos == len(self._bytes)
-class ReflectionTest(BaseTestCase):
+class ReflectionTest(unittest.TestCase):
def assertListsEqual(self, values, others):
self.assertEqual(len(values), len(others))
@@ -621,15 +617,9 @@ class ReflectionTest(BaseTestCase):
self.assertRaises(TypeError, setattr, proto, 'optional_string', 10)
self.assertRaises(TypeError, setattr, proto, 'optional_bytes', 10)
- def assertIntegerTypes(self, integer_fn):
- """Verifies setting of scalar integers.
-
- Args:
- integer_fn: A function to wrap the integers that will be assigned.
- """
+ def testIntegerTypes(self):
def TestGetAndDeserialize(field_name, value, expected_type):
proto = unittest_pb2.TestAllTypes()
- value = integer_fn(value)
setattr(proto, field_name, value)
self.assertIsInstance(getattr(proto, field_name), expected_type)
proto2 = unittest_pb2.TestAllTypes()
@@ -641,12 +631,12 @@ class ReflectionTest(BaseTestCase):
TestGetAndDeserialize('optional_uint32', 1 << 30, int)
try:
integer_64 = long
- except NameError: # Python3
+ except NameError: # Python3
integer_64 = int
if struct.calcsize('L') == 4:
# Python only has signed ints, so 32-bit python can't fit an uint32
# in an int.
- TestGetAndDeserialize('optional_uint32', 1 << 31, integer_64)
+ TestGetAndDeserialize('optional_uint32', 1 << 31, long)
else:
# 64-bit python can fit uint32 inside an int
TestGetAndDeserialize('optional_uint32', 1 << 31, int)
@@ -655,33 +645,9 @@ class ReflectionTest(BaseTestCase):
TestGetAndDeserialize('optional_uint64', 1 << 30, integer_64)
TestGetAndDeserialize('optional_uint64', 1 << 60, integer_64)
- def testIntegerTypes(self):
- self.assertIntegerTypes(lambda x: x)
-
- def testNonStandardIntegerTypes(self):
- self.assertIntegerTypes(test_util.NonStandardInteger)
-
- def testIllegalValuesForIntegers(self):
- pb = unittest_pb2.TestAllTypes()
-
- # Strings are illegal, even when the represent an integer.
- with self.assertRaises(TypeError):
- pb.optional_uint64 = '2'
-
- # The exact error should propagate with a poorly written custom integer.
- with self.assertRaisesRegexp(RuntimeError, 'my_error'):
- pb.optional_uint64 = test_util.NonStandardInteger(5, 'my_error')
-
- def assetIntegerBoundsChecking(self, integer_fn):
- """Verifies bounds checking for scalar integer fields.
-
- Args:
- integer_fn: A function to wrap the integers that will be assigned.
- """
+ def testSingleScalarBoundsChecking(self):
def TestMinAndMaxIntegers(field_name, expected_min, expected_max):
pb = unittest_pb2.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)
@@ -693,22 +659,11 @@ class ReflectionTest(BaseTestCase):
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 = unittest_pb2.TestAllTypes()
- with self.assertRaises(ValueError):
- pb.optional_uint64 = integer_fn(-(1 << 63))
pb = unittest_pb2.TestAllTypes()
- pb.optional_nested_enum = integer_fn(1)
+ pb.optional_nested_enum = 1
self.assertEqual(1, pb.optional_nested_enum)
- def testSingleScalarBoundsChecking(self):
- self.assetIntegerBoundsChecking(lambda x: x)
-
- def testNonStandardSingleScalarBoundsChecking(self):
- self.assetIntegerBoundsChecking(test_util.NonStandardInteger)
-
def testRepeatedScalarTypeSafety(self):
proto = unittest_pb2.TestAllTypes()
self.assertRaises(TypeError, proto.repeated_int32.append, 1.1)
@@ -1017,7 +972,6 @@ class ReflectionTest(BaseTestCase):
proto.repeated_nested_message.add(bb=23)
self.assertEqual(1, len(proto.repeated_nested_message))
self.assertEqual(23, proto.repeated_nested_message[0].bb)
- self.assertRaises(TypeError, proto.repeated_nested_message.add, 23)
def testRepeatedCompositeRemove(self):
proto = unittest_pb2.TestAllTypes()
@@ -1228,18 +1182,12 @@ class ReflectionTest(BaseTestCase):
self.assertTrue(not extendee_proto.HasExtension(extension))
def testRegisteredExtensions(self):
- pool = unittest_pb2.DESCRIPTOR.pool
- self.assertTrue(
- pool.FindExtensionByNumber(
- unittest_pb2.TestAllExtensions.DESCRIPTOR, 1))
- self.assertIs(
- pool.FindExtensionByName(
- 'protobuf_unittest.optional_int32_extension').containing_type,
- unittest_pb2.TestAllExtensions.DESCRIPTOR)
+ self.assertTrue('protobuf_unittest.optional_int32_extension' in
+ unittest_pb2.TestAllExtensions._extensions_by_name)
+ self.assertTrue(1 in unittest_pb2.TestAllExtensions._extensions_by_number)
# Make sure extensions haven't been registered into types that shouldn't
# have any.
- self.assertEqual(0, len(
- pool.FindAllExtensions(unittest_pb2.TestAllTypes.DESCRIPTOR)))
+ self.assertEqual(0, len(unittest_pb2.TestAllTypes._extensions_by_name))
# If message A directly contains message B, and
# a.HasField('b') is currently False, then mutating any
@@ -1603,20 +1551,6 @@ class ReflectionTest(BaseTestCase):
self.assertFalse(proto.HasField('optional_foreign_message'))
self.assertEqual(0, proto.optional_foreign_message.c)
- def testDisconnectingInOneof(self):
- m = unittest_pb2.TestOneof2() # This message has two messages in a oneof.
- m.foo_message.qux_int = 5
- sub_message = m.foo_message
- # Accessing another message's field does not clear the first one
- self.assertEqual(m.foo_lazy_message.qux_int, 0)
- self.assertEqual(m.foo_message.qux_int, 5)
- # But mutating another message in the oneof detaches the first one.
- m.foo_lazy_message.qux_int = 6
- self.assertEqual(m.foo_message.qux_int, 0)
- # The reference we got above was detached and is still valid.
- self.assertEqual(sub_message.qux_int, 5)
- sub_message.qux_int = 7
-
def testOneOf(self):
proto = unittest_pb2.TestAllTypes()
proto.oneof_uint32 = 10
@@ -1875,7 +1809,7 @@ class ReflectionTest(BaseTestCase):
# into separate TestCase classes.
-class TestAllTypesEqualityTest(BaseTestCase):
+class TestAllTypesEqualityTest(unittest.TestCase):
def setUp(self):
self.first_proto = unittest_pb2.TestAllTypes()
@@ -1891,7 +1825,7 @@ class TestAllTypesEqualityTest(BaseTestCase):
self.assertEqual(self.first_proto, self.second_proto)
-class FullProtosEqualityTest(BaseTestCase):
+class FullProtosEqualityTest(unittest.TestCase):
"""Equality tests using completely-full protos as a starting point."""
@@ -1977,7 +1911,7 @@ class FullProtosEqualityTest(BaseTestCase):
self.assertEqual(self.first_proto, self.second_proto)
-class ExtensionEqualityTest(BaseTestCase):
+class ExtensionEqualityTest(unittest.TestCase):
def testExtensionEquality(self):
first_proto = unittest_pb2.TestAllExtensions()
@@ -2010,7 +1944,7 @@ class ExtensionEqualityTest(BaseTestCase):
self.assertEqual(first_proto, second_proto)
-class MutualRecursionEqualityTest(BaseTestCase):
+class MutualRecursionEqualityTest(unittest.TestCase):
def testEqualityWithMutualRecursion(self):
first_proto = unittest_pb2.TestMutualRecursionA()
@@ -2022,7 +1956,7 @@ class MutualRecursionEqualityTest(BaseTestCase):
self.assertEqual(first_proto, second_proto)
-class ByteSizeTest(BaseTestCase):
+class ByteSizeTest(unittest.TestCase):
def setUp(self):
self.proto = unittest_pb2.TestAllTypes()
@@ -2318,7 +2252,7 @@ class ByteSizeTest(BaseTestCase):
# * Handling of empty submessages (with and without "has"
# bits set).
-class SerializationTest(BaseTestCase):
+class SerializationTest(unittest.TestCase):
def testSerializeEmtpyMessage(self):
first_proto = unittest_pb2.TestAllTypes()
@@ -2879,7 +2813,7 @@ class SerializationTest(BaseTestCase):
self.assertEqual(3, proto.repeated_int32[2])
-class OptionsTest(BaseTestCase):
+class OptionsTest(unittest.TestCase):
def testMessageOptions(self):
proto = message_set_extensions_pb2.TestMessageSet()
@@ -2906,7 +2840,7 @@ class OptionsTest(BaseTestCase):
-class ClassAPITest(BaseTestCase):
+class ClassAPITest(unittest.TestCase):
@unittest.skipIf(
api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
@@ -2989,9 +2923,6 @@ class ClassAPITest(BaseTestCase):
text_format.Merge(file_descriptor_str, file_descriptor)
return file_descriptor.SerializeToString()
- @testing_refleaks.SkipReferenceLeakChecker('MakeDescriptor is not repeatable')
- # This test can only run once; the second time, it raises errors about
- # conflicting message descriptors.
def testParsingFlatClassWithExplicitClassDeclaration(self):
"""Test that the generated class can parse a flat message."""
# TODO(xiaofeng): This test fails with cpp implemetnation in the call
@@ -3016,7 +2947,6 @@ class ClassAPITest(BaseTestCase):
text_format.Merge(msg_str, msg)
self.assertEqual(msg.flat, [0, 1, 2])
- @testing_refleaks.SkipReferenceLeakChecker('MakeDescriptor is not repeatable')
def testParsingFlatClass(self):
"""Test that the generated class can parse a flat message."""
file_descriptor = descriptor_pb2.FileDescriptorProto()
@@ -3032,7 +2962,6 @@ class ClassAPITest(BaseTestCase):
text_format.Merge(msg_str, msg)
self.assertEqual(msg.flat, [0, 1, 2])
- @testing_refleaks.SkipReferenceLeakChecker('MakeDescriptor is not repeatable')
def testParsingNestedClass(self):
"""Test that the generated class can parse a nested message."""
file_descriptor = descriptor_pb2.FileDescriptorProto()

Powered by Google App Engine
This is Rietveld 408576698