浏览代码

Revert back changes to import unittest2 for py26

Jisi Liu 10 年之前
父节点
当前提交
dbea00ae88

+ 4 - 1
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

+ 4 - 1
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

+ 5 - 2
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):

+ 4 - 1
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

+ 4 - 1
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
 

+ 4 - 1
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

+ 4 - 1
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

+ 4 - 1
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

+ 6 - 3
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):

+ 4 - 1
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

+ 4 - 1
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

+ 0 - 7
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

+ 4 - 1
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 = [

+ 4 - 1
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

+ 5 - 2
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)
 

+ 4 - 1
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