diff options
author | Zachary Turner <zturner@google.com> | 2015-11-03 21:02:00 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2015-11-03 21:02:00 +0000 |
commit | 234860133b202479d03e34d67eeb7b0e9df92250 (patch) | |
tree | 9f871cb5a4c04e6f19faf42141b12a515768aebf /lldb/third_party/Python | |
parent | 9618980a19d4234d93dd69f92f6b875e72b89a1b (diff) | |
download | llvm-234860133b202479d03e34d67eeb7b0e9df92250.tar.gz |
Python 3 - Fix some issues in unittest2.
unittest2 was using print statements in a few places, and also
using the `cmp` function (which is removed in Python 3). Again,
we need to stop using unittest2 and using unittest instead, but
this seems like an easier route for now.
llvm-svn: 251978
Diffstat (limited to 'lldb/third_party/Python')
4 files changed, 22 insertions, 12 deletions
diff --git a/lldb/third_party/Python/module/unittest2/unittest2/__init__.py b/lldb/third_party/Python/module/unittest2/unittest2/__init__.py index 11cbadc87c46..7f12a9979e59 100644 --- a/lldb/third_party/Python/module/unittest2/unittest2/__init__.py +++ b/lldb/third_party/Python/module/unittest2/unittest2/__init__.py @@ -26,6 +26,14 @@ AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. """ +import sys + +if sys.version_info[0] >= 3: + # Python 3 doesn't have the builtin `cmp` function anymore + cmp_ = lambda x, y: (x > y) - (x < y) +else: + cmp_ = cmp + __all__ = ['TestResult', 'TestCase', 'TestSuite', 'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main', 'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless', @@ -65,4 +73,4 @@ else: # deprecated _TextTestResult = TextTestResult -__unittest = True
\ No newline at end of file +__unittest = True diff --git a/lldb/third_party/Python/module/unittest2/unittest2/loader.py b/lldb/third_party/Python/module/unittest2/unittest2/loader.py index f5ca4aa970e1..6fbafb7a17eb 100644 --- a/lldb/third_party/Python/module/unittest2/unittest2/loader.py +++ b/lldb/third_party/Python/module/unittest2/unittest2/loader.py @@ -9,7 +9,7 @@ import unittest from fnmatch import fnmatch -from unittest2 import case, suite +from unittest2 import case, suite, cmp_ try: from os.path import relpath @@ -61,7 +61,7 @@ class TestLoader(unittest.TestLoader): and returning them wrapped in a TestSuite """ testMethodPrefix = 'test' - sortTestMethodsUsing = cmp + sortTestMethodsUsing = cmp_ suiteClass = suite.TestSuite _top_level_dir = None @@ -310,13 +310,13 @@ def _makeLoader(prefix, sortUsing, suiteClass=None): loader.suiteClass = suiteClass return loader -def getTestCaseNames(testCaseClass, prefix, sortUsing=cmp): +def getTestCaseNames(testCaseClass, prefix, sortUsing=cmp_): return _makeLoader(prefix, sortUsing).getTestCaseNames(testCaseClass) -def makeSuite(testCaseClass, prefix='test', sortUsing=cmp, +def makeSuite(testCaseClass, prefix='test', sortUsing=cmp_, suiteClass=suite.TestSuite): return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromTestCase(testCaseClass) -def findTestCases(module, prefix='test', sortUsing=cmp, +def findTestCases(module, prefix='test', sortUsing=cmp_, suiteClass=suite.TestSuite): return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromModule(module) diff --git a/lldb/third_party/Python/module/unittest2/unittest2/main.py b/lldb/third_party/Python/module/unittest2/unittest2/main.py index a2675ad45489..c0b71ef6b831 100644 --- a/lldb/third_party/Python/module/unittest2/unittest2/main.py +++ b/lldb/third_party/Python/module/unittest2/unittest2/main.py @@ -99,7 +99,7 @@ class TestProgram(object): def usageExit(self, msg=None): if msg: - print msg + print(msg) usage = {'progName': self.progName, 'catchbreak': '', 'failfast': '', 'buffer': ''} if self.failfast != False: @@ -108,7 +108,7 @@ class TestProgram(object): usage['catchbreak'] = CATCHBREAK if self.buffer != False: usage['buffer'] = BUFFEROUTPUT - print self.USAGE % usage + print(self.USAGE % usage) sys.exit(2) def parseArgs(self, argv): diff --git a/lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py b/lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py index a6dc16cf792c..69b31d542eae 100644 --- a/lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py +++ b/lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import sys import textwrap from StringIO import StringIO @@ -342,8 +344,8 @@ class TestOutputBuffering(unittest2.TestCase): result._original_stdout = StringIO() result._original_stderr = StringIO() - print 'foo' - print >> sys.stderr, 'bar' + print('foo') + print('bar', file=sys.stderr) self.assertEqual(out_stream.getvalue(), 'foo\n') self.assertEqual(err_stream.getvalue(), 'bar\n') @@ -381,9 +383,9 @@ class TestOutputBuffering(unittest2.TestCase): result._original_stderr = StringIO() result._original_stdout = StringIO() - print >> sys.stdout, 'foo' + print('foo') if include_error: - print >> sys.stderr, 'bar' + print('bar', file=sys.stderr) addFunction = getattr(result, add_attr) addFunction(self, (None, None, None)) |