diff options
Diffstat (limited to 'python/google/protobuf/internal/_parameterized.py')
-rwxr-xr-x | python/google/protobuf/internal/_parameterized.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/python/google/protobuf/internal/_parameterized.py b/python/google/protobuf/internal/_parameterized.py index 400b2216..3821b916 100755 --- a/python/google/protobuf/internal/_parameterized.py +++ b/python/google/protobuf/internal/_parameterized.py @@ -149,9 +149,14 @@ import collections import functools import re import types -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest import uuid +import six + ADDR_RE = re.compile(r'\<([a-zA-Z0-9_\-\.]+) object at 0x[a-fA-F0-9]+\>') _SEPARATOR = uuid.uuid1().hex _FIRST_ARG = object() @@ -170,13 +175,13 @@ def _StrClass(cls): def _NonStringIterable(obj): return (isinstance(obj, collections.Iterable) and not - isinstance(obj, basestring)) + isinstance(obj, six.string_types)) def _FormatParameterList(testcase_params): if isinstance(testcase_params, collections.Mapping): return ', '.join('%s=%s' % (argname, _CleanRepr(value)) - for argname, value in testcase_params.iteritems()) + for argname, value in testcase_params.items()) elif _NonStringIterable(testcase_params): return ', '.join(map(_CleanRepr, testcase_params)) else: @@ -258,7 +263,9 @@ def _ModifyClass(class_object, testcases, naming_type): 'Cannot add parameters to %s,' ' which already has parameterized methods.' % (class_object,)) class_object._id_suffix = id_suffix = {} - for name, obj in class_object.__dict__.items(): + # We change the size of __dict__ while we iterate over it, + # which Python 3.x will complain about, so use copy(). + for name, obj in class_object.__dict__.copy().items(): if (name.startswith(unittest.TestLoader.testMethodPrefix) and isinstance(obj, types.FunctionType)): delattr(class_object, name) @@ -266,7 +273,7 @@ def _ModifyClass(class_object, testcases, naming_type): _UpdateClassDictForParamTestCase( methods, id_suffix, name, _ParameterizedTestIter(obj, testcases, naming_type)) - for name, meth in methods.iteritems(): + for name, meth in methods.items(): setattr(class_object, name, meth) |