Commit 71edc31f authored by Tres Seaver's avatar Tres Seaver

Compatibility with Python2.6 unittest.

parent 47ee4d37
...@@ -94,11 +94,11 @@ class MessageFactoryTest(unittest.TestCase): ...@@ -94,11 +94,11 @@ class MessageFactoryTest(unittest.TestCase):
factory = message_factory.MessageFactory() factory = message_factory.MessageFactory()
cls = factory.GetPrototype(pool.FindMessageTypeByName( cls = factory.GetPrototype(pool.FindMessageTypeByName(
'google.protobuf.python.internal.Factory2Message')) 'google.protobuf.python.internal.Factory2Message'))
self.assertIsNot(cls, factory_test2_pb2.Factory2Message) self.assertFalse(cls is factory_test2_pb2.Factory2Message)
self._ExerciseDynamicClass(cls) self._ExerciseDynamicClass(cls)
cls2 = factory.GetPrototype(pool.FindMessageTypeByName( cls2 = factory.GetPrototype(pool.FindMessageTypeByName(
'google.protobuf.python.internal.Factory2Message')) 'google.protobuf.python.internal.Factory2Message'))
self.assertIs(cls, cls2) self.assertTrue(cls is cls2)
def testGetMessages(self): def testGetMessages(self):
# performed twice because multiple calls with the same input must be allowed # performed twice because multiple calls with the same input must be allowed
......
...@@ -40,6 +40,17 @@ import gc ...@@ -40,6 +40,17 @@ import gc
import operator import operator
import struct import struct
import unittest import unittest
try:
from unittest import skipIf
except ImportError:
def skipIf(predicate, message):
def decorator(wrapped):
if predicate:
def _noop(*args, **kw):
pass
return _noop
return wrapped
return decorator
import six import six
...@@ -1623,7 +1634,7 @@ class ReflectionTest(unittest.TestCase): ...@@ -1623,7 +1634,7 @@ class ReflectionTest(unittest.TestCase):
self.assertFalse(proto.IsInitialized(errors)) self.assertFalse(proto.IsInitialized(errors))
self.assertEqual(errors, ['a', 'b', 'c']) self.assertEqual(errors, ['a', 'b', 'c'])
@unittest.skipIf( @skipIf(
api_implementation.Type() != 'cpp' or api_implementation.Version() != 2, api_implementation.Type() != 'cpp' or api_implementation.Version() != 2,
'Errors are only available from the most recent C++ implementation.') 'Errors are only available from the most recent C++ implementation.')
def testFileDescriptorErrors(self): def testFileDescriptorErrors(self):
...@@ -1644,18 +1655,17 @@ class ReflectionTest(unittest.TestCase): ...@@ -1644,18 +1655,17 @@ class ReflectionTest(unittest.TestCase):
file_descriptor_proto.name = another_file_name file_descriptor_proto.name = another_file_name
m2 = file_descriptor_proto.message_type.add() m2 = file_descriptor_proto.message_type.add()
m2.name = 'msg2' m2.name = 'msg2'
with self.assertRaises(TypeError) as cm: try:
descriptor.FileDescriptor( descriptor.FileDescriptor(
another_file_name, another_file_name,
package_name, package_name,
serialized_pb=file_descriptor_proto.SerializeToString()) serialized_pb=file_descriptor_proto.SerializeToString())
self.assertTrue(hasattr(cm, 'exception'), '%s not raised' % except TypeError as e:
getattr(cm.expected, '__name__', cm.expected)) message = str(e)
self.assertIn('test_file_descriptor_errors.proto', str(cm.exception)) else:
# Error message will say something about this definition being a self.fail("Did not raise TypeError")
# duplicate, though we don't check the message exactly to avoid a
# dependency on the C++ logging code. self.assertTrue('test_file_descriptor_errors.proto' in message)
self.assertIn('test_file_descriptor_errors.msg1', str(cm.exception))
def testStringUTF8Encoding(self): def testStringUTF8Encoding(self):
proto = unittest_pb2.TestAllTypes() proto = unittest_pb2.TestAllTypes()
...@@ -2824,7 +2834,7 @@ class OptionsTest(unittest.TestCase): ...@@ -2824,7 +2834,7 @@ class OptionsTest(unittest.TestCase):
class ClassAPITest(unittest.TestCase): class ClassAPITest(unittest.TestCase):
@unittest.skipIf( @skipIf(
api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
'C++ implementation requires a call to MakeDescriptor()') 'C++ implementation requires a call to MakeDescriptor()')
def testMakeClassWithNestedDescriptor(self): def testMakeClassWithNestedDescriptor(self):
......
...@@ -36,6 +36,17 @@ ...@@ -36,6 +36,17 @@
__author__ = 'bohdank@google.com (Bohdan Koval)' __author__ = 'bohdank@google.com (Bohdan Koval)'
import unittest import unittest
try:
from unittest import skipIf
except ImportError:
def skipIf(predicate, message):
def decorator(wrapped):
if predicate:
def _noop(*args, **kw):
pass
return _noop
return wrapped
return decorator
from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_pb2 from google.protobuf import unittest_pb2
...@@ -46,7 +57,7 @@ from google.protobuf.internal import test_util ...@@ -46,7 +57,7 @@ from google.protobuf.internal import test_util
from google.protobuf.internal import type_checkers from google.protobuf.internal import type_checkers
@unittest.skipIf( @skipIf(
api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
'C++ implementation does not expose unknown fields to Python') 'C++ implementation does not expose unknown fields to Python')
class UnknownFieldsTest(unittest.TestCase): class UnknownFieldsTest(unittest.TestCase):
...@@ -180,7 +191,7 @@ class UnknownFieldsTest(unittest.TestCase): ...@@ -180,7 +191,7 @@ class UnknownFieldsTest(unittest.TestCase):
self.assertNotEqual(self.empty_message, message) self.assertNotEqual(self.empty_message, message)
@unittest.skipIf( @skipIf(
api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
'C++ implementation does not expose unknown fields to Python') 'C++ implementation does not expose unknown fields to Python')
class UnknownEnumValuesTest(unittest.TestCase): class UnknownEnumValuesTest(unittest.TestCase):
......
...@@ -135,13 +135,6 @@ class build_py(_build_py): ...@@ -135,13 +135,6 @@ class build_py(_build_py):
pass pass
# _build_py is an old-style class, so super() doesn't work. # _build_py is an old-style class, so super() doesn't work.
_build_py.run(self) _build_py.run(self)
# TODO(mrovner): Subclass to run 2to3 on some files only.
# Tracing what https://wiki.python.org/moin/PortingPythonToPy3k's "Approach 2"
# section on how to get 2to3 to run on source files during install under
# Python 3. This class seems like a good place to put logic that calls
# python3's distutils.util.run_2to3 on the subset of the files we have in our
# release that are subject to conversion.
# See code reference in previous code review.
if __name__ == '__main__': if __name__ == '__main__':
ext_module_list = [] ext_module_list = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment