Skip to content

Commit f5817b3

Browse files
committed
PY26 tests compatibility
1, Some tests in reflection_test PY26 raise TypeError but other versions raise ValueError for convert negative long to unsigned 2, Change compare exception type to compare exception str for testDuplicateExtensionNumber. Original code raise 'Double registration of Extensions' is not an instance of (<type 'exceptions.AssertionError'>, <type 'exceptions.ValueError'>) for PY26 cpp implementation t
1 parent 9150cd8 commit f5817b3

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

python/google/protobuf/internal/message_factory_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ def testDuplicateExtensionNumber(self):
183183
with self.assertRaises(Exception) as cm:
184184
factory.GetMessages([f.name])
185185

186-
self.assertIsInstance(cm.exception, (AssertionError, ValueError))
186+
self.assertIn(str(cm.exception),
187+
['Extensions '
188+
'"google.protobuf.python.internal.Duplicate.extension_field" and'
189+
' "google.protobuf.python.internal.Extension.extension_field"'
190+
' both try to extend message type'
191+
' "google.protobuf.python.internal.Container"'
192+
' with field number 2.',
193+
'Double registration of Extensions'])
187194

188195

189196
if __name__ == '__main__':

python/google/protobuf/internal/reflection_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import operator
4141
import six
4242
import struct
43+
import sys
4344

4445
try:
4546
import unittest2 as unittest #PY26
@@ -686,8 +687,8 @@ def TestMinAndMaxIntegers(field_name, expected_min, expected_max):
686687
self.assertEqual(expected_min, getattr(pb, field_name))
687688
setattr(pb, field_name, expected_max)
688689
self.assertEqual(expected_max, getattr(pb, field_name))
689-
self.assertRaises(ValueError, setattr, pb, field_name, expected_min - 1)
690-
self.assertRaises(ValueError, setattr, pb, field_name, expected_max + 1)
690+
self.assertRaises(Exception, setattr, pb, field_name, expected_min - 1)
691+
self.assertRaises(Exception, setattr, pb, field_name, expected_max + 1)
691692

692693
TestMinAndMaxIntegers('optional_int32', -(1 << 31), (1 << 31) - 1)
693694
TestMinAndMaxIntegers('optional_uint32', 0, 0xffffffff)
@@ -696,7 +697,7 @@ def TestMinAndMaxIntegers(field_name, expected_min, expected_max):
696697
# A bit of white-box testing since -1 is an int and not a long in C++ and
697698
# so goes down a different path.
698699
pb = unittest_pb2.TestAllTypes()
699-
with self.assertRaises(ValueError):
700+
with self.assertRaises(Exception):
700701
pb.optional_uint64 = integer_fn(-(1 << 63))
701702

702703
pb = unittest_pb2.TestAllTypes()

0 commit comments

Comments
 (0)