[Lldb-commits] [lldb] r251983 - Python 3 - Fix checking of string types in unittest2 module.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 3 13:37:43 PST 2015


Author: zturner
Date: Tue Nov  3 15:37:42 2015
New Revision: 251983

URL: http://llvm.org/viewvc/llvm-project?rev=251983&view=rev
Log:
Python 3 - Fix checking of string types in unittest2 module.

This patch actually introduces a dependency from unittest2 to
six.  This should be ok since both packages are in our own
repo, and we assume a sys.path of the top-level script that
can find the third party packages.  So unittest2 should be
able to find six.

Modified:
    lldb/trunk/third_party/Python/module/unittest2/unittest2/case.py
    lldb/trunk/third_party/Python/module/unittest2/unittest2/main.py
    lldb/trunk/third_party/Python/module/unittest2/unittest2/suite.py
    lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_case.py
    lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_functiontestcase.py

Modified: lldb/trunk/third_party/Python/module/unittest2/unittest2/case.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/third_party/Python/module/unittest2/unittest2/case.py?rev=251983&r1=251982&r2=251983&view=diff
==============================================================================
--- lldb/trunk/third_party/Python/module/unittest2/unittest2/case.py (original)
+++ lldb/trunk/third_party/Python/module/unittest2/unittest2/case.py Tue Nov  3 15:37:42 2015
@@ -7,6 +7,8 @@ import re
 import unittest
 import warnings
 
+import six
+
 from unittest2 import result
 from unittest2.util import (
     safe_repr, safe_str, strclass,
@@ -137,7 +139,7 @@ class _AssertRaisesContext(object):
             return True
 
         expected_regexp = self.expected_regexp
-        if isinstance(expected_regexp, basestring):
+        if isinstance(expected_regexp, six.string_types):
             expected_regexp = re.compile(expected_regexp)
         if not expected_regexp.search(str(exc_value)):
             raise self.failureException('"%s" does not match "%s"' %
@@ -156,7 +158,7 @@ class _TypeEqualityDict(object):
     
     def __getitem__(self, key):
         value = self._store[key]
-        if isinstance(value, basestring):
+        if isinstance(value, six.string_types):
             return getattr(self.testcase, value)
         return value
     
@@ -940,9 +942,9 @@ class TestCase(unittest.TestCase):
 
     def assertMultiLineEqual(self, first, second, msg=None):
         """Assert that two multi-line strings are equal."""
-        self.assert_(isinstance(first, basestring), (
+        self.assert_(isinstance(first, six.string_types), (
                 'First argument is not a string'))
-        self.assert_(isinstance(second, basestring), (
+        self.assert_(isinstance(second, six.string_types), (
                 'Second argument is not a string'))
 
         if first != second:
@@ -1018,7 +1020,7 @@ class TestCase(unittest.TestCase):
         try:
             callable_obj(*args, **kwargs)
         except expected_exception as exc_value:
-            if isinstance(expected_regexp, basestring):
+            if isinstance(expected_regexp, six.string_types):
                 expected_regexp = re.compile(expected_regexp)
             if not expected_regexp.search(str(exc_value)):
                 raise self.failureException('"%s" does not match "%s"' %
@@ -1033,7 +1035,7 @@ class TestCase(unittest.TestCase):
 
     def assertRegexpMatches(self, text, expected_regexp, msg=None):
         """Fail the test unless the text matches the regular expression."""
-        if isinstance(expected_regexp, basestring):
+        if isinstance(expected_regexp, six.string_types):
             expected_regexp = re.compile(expected_regexp)
         if not expected_regexp.search(text):
             msg = msg or "Regexp didn't match"
@@ -1042,7 +1044,7 @@ class TestCase(unittest.TestCase):
 
     def assertNotRegexpMatches(self, text, unexpected_regexp, msg=None):
         """Fail the test if the text matches the regular expression."""
-        if isinstance(unexpected_regexp, basestring):
+        if isinstance(unexpected_regexp, six.string_types):
             unexpected_regexp = re.compile(unexpected_regexp)
         match = unexpected_regexp.search(text)
         if match:

Modified: lldb/trunk/third_party/Python/module/unittest2/unittest2/main.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/third_party/Python/module/unittest2/unittest2/main.py?rev=251983&r1=251982&r2=251983&view=diff
==============================================================================
--- lldb/trunk/third_party/Python/module/unittest2/unittest2/main.py (original)
+++ lldb/trunk/third_party/Python/module/unittest2/unittest2/main.py Tue Nov  3 15:37:42 2015
@@ -3,6 +3,7 @@
 import sys
 import os
 import types
+import six
 
 from unittest2 import loader, runner
 try:
@@ -76,7 +77,7 @@ class TestProgram(object):
                  argv=None, testRunner=None,
                  testLoader=loader.defaultTestLoader, exit=True,
                  verbosity=1, failfast=None, catchbreak=None, buffer=None):
-        if isinstance(module, basestring):
+        if isinstance(module, six.string_types):
             self.module = __import__(module)
             for part in module.split('.')[1:]:
                 self.module = getattr(self.module, part)

Modified: lldb/trunk/third_party/Python/module/unittest2/unittest2/suite.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/third_party/Python/module/unittest2/unittest2/suite.py?rev=251983&r1=251982&r2=251983&view=diff
==============================================================================
--- lldb/trunk/third_party/Python/module/unittest2/unittest2/suite.py (original)
+++ lldb/trunk/third_party/Python/module/unittest2/unittest2/suite.py Tue Nov  3 15:37:42 2015
@@ -3,6 +3,7 @@
 import sys
 import unittest
 from unittest2 import case, util
+import six
 
 __unittest = True
 
@@ -48,7 +49,7 @@ class BaseTestSuite(unittest.TestSuite):
         self._tests.append(test)
 
     def addTests(self, tests):
-        if isinstance(tests, basestring):
+        if isinstance(tests, six.string_types):
             raise TypeError("tests must be an iterable of tests, not a string")
         for test in tests:
             self.addTest(test)

Modified: lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_case.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_case.py?rev=251983&r1=251982&r2=251983&view=diff
==============================================================================
--- lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_case.py (original)
+++ lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_case.py Tue Nov  3 15:37:42 2015
@@ -1,6 +1,7 @@
 import difflib
 import pprint
 import re
+import six
 
 from copy import deepcopy
 
@@ -502,7 +503,7 @@ class Test_TestCase(unittest2.TestCase,
             def runTest(self):
                 pass
 
-        self.assertIsInstance(Foo().id(), basestring)
+        self.assertIsInstance(Foo().id(), six.string_types)
 
     # "If result is omitted or None, a temporary result object is created
     # and used, but is not made available to the caller. As TestCase owns the

Modified: lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_functiontestcase.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_functiontestcase.py?rev=251983&r1=251982&r2=251983&view=diff
==============================================================================
--- lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_functiontestcase.py (original)
+++ lldb/trunk/third_party/Python/module/unittest2/unittest2/test/test_functiontestcase.py Tue Nov  3 15:37:42 2015
@@ -1,4 +1,5 @@
 import unittest2
+import six
 
 from unittest2.test.support import LoggingResult
 
@@ -124,7 +125,7 @@ class Test_FunctionTestCase(unittest2.Te
     def test_id(self):
         test = unittest2.FunctionTestCase(lambda: None)
 
-        self.assertIsInstance(test.id(), basestring)
+        self.assertIsInstance(test.id(), six.string_types)
 
     # "Returns a one-line description of the test, or None if no description
     # has been provided. The default implementation of this method returns




More information about the lldb-commits mailing list