From dbea00ae882b0a1df1f76cb5b23657234bf073c4 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Mon, 5 Oct 2015 16:08:22 -0700 Subject: [PATCH] Revert back changes to import unittest2 for py26 --- .../google/protobuf/internal/descriptor_database_test.py | 5 ++++- python/google/protobuf/internal/descriptor_pool_test.py | 5 ++++- python/google/protobuf/internal/descriptor_test.py | 7 +++++-- python/google/protobuf/internal/generator_test.py | 5 ++++- python/google/protobuf/internal/json_format_test.py | 5 ++++- python/google/protobuf/internal/message_factory_test.py | 5 ++++- python/google/protobuf/internal/message_test.py | 5 ++++- python/google/protobuf/internal/proto_builder_test.py | 5 ++++- python/google/protobuf/internal/reflection_test.py | 9 ++++++--- .../google/protobuf/internal/service_reflection_test.py | 5 ++++- python/google/protobuf/internal/symbol_database_test.py | 5 ++++- python/google/protobuf/internal/test_util.py | 7 ------- python/google/protobuf/internal/text_encoding_test.py | 5 ++++- python/google/protobuf/internal/text_format_test.py | 5 ++++- python/google/protobuf/internal/unknown_fields_test.py | 7 +++++-- python/google/protobuf/internal/wire_format_test.py | 5 ++++- 16 files changed, 64 insertions(+), 26 deletions(-) diff --git a/python/google/protobuf/internal/descriptor_database_test.py b/python/google/protobuf/internal/descriptor_database_test.py index 3241cb7281..1baff7d1d1 100644 --- a/python/google/protobuf/internal/descriptor_database_test.py +++ b/python/google/protobuf/internal/descriptor_database_test.py @@ -34,7 +34,10 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import descriptor_pb2 from google.protobuf.internal import factory_test2_pb2 from google.protobuf import descriptor_database diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index 6bbc8233b4..da9a78dbee 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -36,7 +36,10 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' import os -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import unittest_pb2 from google.protobuf import descriptor_pb2 from google.protobuf.internal import api_implementation diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index f94f9f14ec..99afee63ea 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -36,7 +36,10 @@ __author__ = 'robinson@google.com (Will Robinson)' import sys -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_pb2 @@ -391,7 +394,7 @@ class DescriptorTest(unittest.TestCase): self.assertEqual(self.my_file.name, 'some/filename/some.proto') self.assertEqual(self.my_file.package, 'protobuf_unittest') - @test_util.skipIf( + @unittest.skipIf( api_implementation.Type() != 'cpp' or api_implementation.Version() != 2, 'Immutability of descriptors is only enforced in v2 implementation') def testImmutableCppDescriptor(self): diff --git a/python/google/protobuf/internal/generator_test.py b/python/google/protobuf/internal/generator_test.py index 7fcb137793..9956da59b4 100755 --- a/python/google/protobuf/internal/generator_test.py +++ b/python/google/protobuf/internal/generator_test.py @@ -41,7 +41,10 @@ further ensures that we can use Python protocol message objects as we expect. __author__ = 'robinson@google.com (Will Robinson)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf.internal import test_bad_identifiers_pb2 from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index dddc2df8ee..4e2f35e4dd 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -38,7 +38,10 @@ import json import math import sys -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import json_format from google.protobuf.util import json_format_proto3_pb2 diff --git a/python/google/protobuf/internal/message_factory_test.py b/python/google/protobuf/internal/message_factory_test.py index 9ec54fff53..d760b898f5 100644 --- a/python/google/protobuf/internal/message_factory_test.py +++ b/python/google/protobuf/internal/message_factory_test.py @@ -34,7 +34,10 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import descriptor_pb2 from google.protobuf.internal import factory_test1_pb2 from google.protobuf.internal import factory_test2_pb2 diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 604c426a88..13c3caa6cc 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -52,7 +52,10 @@ import pickle import six import sys -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf.internal import _parameterized from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_pb2 diff --git a/python/google/protobuf/internal/proto_builder_test.py b/python/google/protobuf/internal/proto_builder_test.py index e0467251aa..6a8644b0a1 100644 --- a/python/google/protobuf/internal/proto_builder_test.py +++ b/python/google/protobuf/internal/proto_builder_test.py @@ -37,7 +37,10 @@ try: except ImportError: from ordereddict import OrderedDict #PY26 import collections -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool from google.protobuf import proto_builder diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 6815c238c6..8621d61e6b 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -41,7 +41,10 @@ import operator import six import struct -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 @@ -1623,7 +1626,7 @@ class ReflectionTest(unittest.TestCase): self.assertFalse(proto.IsInitialized(errors)) self.assertEqual(errors, ['a', 'b', 'c']) - @test_util.skipIf( + @unittest.skipIf( api_implementation.Type() != 'cpp' or api_implementation.Version() != 2, 'Errors are only available from the most recent C++ implementation.') def testFileDescriptorErrors(self): @@ -2822,7 +2825,7 @@ class OptionsTest(unittest.TestCase): class ClassAPITest(unittest.TestCase): - @test_util.skipIf( + @unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation requires a call to MakeDescriptor()') def testMakeClassWithNestedDescriptor(self): diff --git a/python/google/protobuf/internal/service_reflection_test.py b/python/google/protobuf/internal/service_reflection_test.py index 564e2d1a39..98614b77f6 100755 --- a/python/google/protobuf/internal/service_reflection_test.py +++ b/python/google/protobuf/internal/service_reflection_test.py @@ -34,7 +34,10 @@ __author__ = 'petar@google.com (Petar Petrov)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import unittest_pb2 from google.protobuf import service_reflection from google.protobuf import service diff --git a/python/google/protobuf/internal/symbol_database_test.py b/python/google/protobuf/internal/symbol_database_test.py index 7fb4b56d62..0cb935a880 100644 --- a/python/google/protobuf/internal/symbol_database_test.py +++ b/python/google/protobuf/internal/symbol_database_test.py @@ -32,7 +32,10 @@ """Tests for google.protobuf.symbol_database.""" -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import unittest_pb2 from google.protobuf import descriptor from google.protobuf import symbol_database diff --git a/python/google/protobuf/internal/test_util.py b/python/google/protobuf/internal/test_util.py index 539236b4cd..ac88fa81d8 100755 --- a/python/google/protobuf/internal/test_util.py +++ b/python/google/protobuf/internal/test_util.py @@ -38,13 +38,6 @@ __author__ = 'robinson@google.com (Will Robinson)' import os.path -import sys -# PY2.6 compatible skipIf -if sys.version_info < (2, 7): - from unittest2 import skipIf -else: - from unittest import skipIf - from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_pb2 from google.protobuf import descriptor_pb2 diff --git a/python/google/protobuf/internal/text_encoding_test.py b/python/google/protobuf/internal/text_encoding_test.py index 9e7b9ce433..338a287b1b 100755 --- a/python/google/protobuf/internal/text_encoding_test.py +++ b/python/google/protobuf/internal/text_encoding_test.py @@ -32,7 +32,10 @@ """Tests for google.protobuf.text_encoding.""" -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import text_encoding TEST_VALUES = [ diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index fb4addeb25..cca0ee637c 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -39,7 +39,10 @@ import re import six import string -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf.internal import _parameterized from google.protobuf import map_unittest_pb2 diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index 25b447e18b..9685b8b4f0 100755 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -35,7 +35,10 @@ __author__ = 'bohdank@google.com (Bohdan Koval)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 from google.protobuf import unittest_proto3_arena_pb2 @@ -48,7 +51,7 @@ from google.protobuf.internal import type_checkers def SkipIfCppImplementation(func): - return test_util.skipIf( + return unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation does not expose unknown fields to Python')(func) diff --git a/python/google/protobuf/internal/wire_format_test.py b/python/google/protobuf/internal/wire_format_test.py index 78dc11670f..f659d18e42 100755 --- a/python/google/protobuf/internal/wire_format_test.py +++ b/python/google/protobuf/internal/wire_format_test.py @@ -34,7 +34,10 @@ __author__ = 'robinson@google.com (Will Robinson)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import message from google.protobuf.internal import wire_format