diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/README.txt | 9 | ||||
-rwxr-xr-x | python/google/protobuf/internal/reflection_test.py | 23 | ||||
-rw-r--r-- | python/google/protobuf/pyext/__init__.py | 0 | ||||
-rwxr-xr-x | python/setup.py | 42 |
4 files changed, 33 insertions, 41 deletions
diff --git a/python/README.txt b/python/README.txt index 4ed9bc0d..9ba42f8b 100644 --- a/python/README.txt +++ b/python/README.txt @@ -47,9 +47,9 @@ Installation $ python setup.py build $ python setup.py google_test - + if you want to test c++ implementation, run: - $ python setup.py google_test --cpp_implementation + $ python setup.py test If some tests fail, this library may not work correctly on your system. Continue at your own risk. @@ -66,7 +66,7 @@ Installation $ python setup.py install or: - $ python setup.py install --cpp_implementation + $ python setup.py install --nocpp_implementation This step may require superuser privileges. NOTE: To use C++ implementation, you need to install C++ protobuf runtime @@ -101,8 +101,7 @@ You need to export this variable before running setup.py script to build and install the extension. You must also set the variable at runtime, otherwise the pure-Python implementation will be used. In a future release, we will change the default so that C++ implementation is used whenever it is available. -It is strongly recommended to run `python setup.py google_test ---cpp_implementation` after setting the +It is strongly recommended to run `python setup.py test` after setting the variable to "cpp", so the tests will be against C++ implemented Python messages. diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 587246a7..b3c414c7 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -41,7 +41,6 @@ import copy import gc import operator import struct -import sys from google.apputils import basetest from google.protobuf import unittest_import_pb2 @@ -1557,20 +1556,7 @@ class ReflectionTest(basetest.TestCase): def assertNotInitialized(self, proto): self.assertFalse(proto.IsInitialized()) - try: - proto.SerializeToString() - except message.EncodeError: - return - except: - # C++ implementation in opensource do not consider the catched - # exception google.protobuf.message.EncodeError same as - # message.EncodeError. Add an additional catch to deal with it. - if api_implementation.Type() == 'python': - raise self.failureException('message.EncodeError not raised') - self.assertEqual('<class \'google.protobuf.message.EncodeError\'>', - str(sys.exc_info()[0])) - else: - raise self.failureException('message.EncodeError not raised') + self.assertRaises(message.EncodeError, proto.SerializeToString) # "Partial" serialization doesn't care if message is uninitialized. proto.SerializePartialToString() @@ -2500,13 +2486,6 @@ class SerializationTest(basetest.TestCase): # Check if the exception message is the right one. self.assertEqual(exception, str(ex)) return - except: - # C++ implementation in opensource do not consider the catched - # exception google.protobuf.message.EncodeError same as - # message.EncodeError. Add an additional catch to deal with it. - if api_implementation.Type() == 'python': - raise self.failureException('%s not raised' % str(exc_class)) - self.assertEqual(exception, str(sys.exc_info()[1])) else: raise self.failureException('%s not raised' % str(exc_class)) diff --git a/python/google/protobuf/pyext/__init__.py b/python/google/protobuf/pyext/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/python/google/protobuf/pyext/__init__.py diff --git a/python/setup.py b/python/setup.py index 51b27d72..6eecd489 100755 --- a/python/setup.py +++ b/python/setup.py @@ -83,6 +83,23 @@ def GenerateUnittestProtos(): generate_proto("google/protobuf/internal/factory_test2.proto") generate_proto("google/protobuf/pyext/python.proto") +def MakeTestSuite(): + # Test C++ implementation + import unittest + import google.protobuf.pyext.descriptor_cpp2_test as descriptor_cpp2_test + import google.protobuf.pyext.message_factory_cpp2_test \ + as message_factory_cpp2_test + import google.protobuf.pyext.reflection_cpp2_generated_test \ + as reflection_cpp2_generated_test + + loader = unittest.defaultTestLoader + suite = unittest.TestSuite() + for test in [ descriptor_cpp2_test, + message_factory_cpp2_test, + reflection_cpp2_generated_test]: + suite.addTest(loader.loadTestsFromModule(test)) + return suite + class clean(_clean): def run(self): # Delete generated files in the code tree. @@ -119,14 +136,14 @@ class build_py(_build_py): # release that are subject to conversion. # See code reference in previous code review. - if __name__ == '__main__': - # C++ implementation extension - cpp_impl = '--cpp_implementation' - if cpp_impl in sys.argv: + ext_module_list = [] + nocpp = '--nocpp_implementation' + if nocpp in sys.argv: sys.argv.remove(cpp_impl) - test_dir = "google/protobuf/pyext" - ext_module_list = [Extension( + else: + # C++ implementation extension + ext_module_list.append(Extension( "google.protobuf.pyext._message", [ "google/protobuf/pyext/descriptor.cc", "google/protobuf/pyext/message.cc", @@ -134,20 +151,17 @@ if __name__ == '__main__': "google/protobuf/pyext/repeated_scalar_container.cc", "google/protobuf/pyext/repeated_composite_container.cc" ], define_macros=[('GOOGLE_PROTOBUF_HAS_ONEOF', '1')], - include_dirs = [ ".", "../src" ], + include_dirs = [ ".", "../src"], libraries = [ "protobuf" ], library_dirs = [ '../src/.libs' ], - )] - else: - test_dir = "google/protobuf/internal" - ext_module_list = [] - + )) setup(name = 'protobuf', - version = '2.6-pre', + version = '2.6.0', packages = [ 'google' ], namespace_packages = [ 'google' ], - google_test_dir = test_dir, + test_suite = 'setup.MakeTestSuite', + google_test_dir = "google/protobuf/internal", # Must list modules explicitly so that we don't install tests. py_modules = [ 'google.protobuf.internal.api_implementation', |