summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-12-09 00:08:18 +0000
committerZac Medico <zmedico@gentoo.org>2009-12-09 00:08:18 +0000
commit3a3f1b1f3b61bda1591706d67e17daa5ca5f8d1a (patch)
treeed243b1de586e2f873ba686f4949ce9b776666b0
parentWhen temporarily replacing the sys.std* streams, use the normal open() func (diff)
downloadportage-idfetch-3a3f1b1f3b61bda1591706d67e17daa5ca5f8d1a.tar.gz
portage-idfetch-3a3f1b1f3b61bda1591706d67e17daa5ca5f8d1a.tar.bz2
portage-idfetch-3a3f1b1f3b61bda1591706d67e17daa5ca5f8d1a.zip
Use ImportError handling to import _TextTestResult which moved from
unittest to unittest.runner in python-2.7. Thanks to Arfrever for the suggestion. svn path=/main/trunk/; revision=14972
-rw-r--r--pym/portage/tests/__init__.py65
1 files changed, 8 insertions, 57 deletions
diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 0382a2fc..fec1e238 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -6,7 +6,11 @@
import sys
import time
import unittest
-from unittest import TestResult
+
+try:
+ from unittest.runner import _TextTestResult # new in python-2.7
+except ImportError:
+ from unittest import _TextTestResult
from portage import os
from portage import _encodings
@@ -70,26 +74,17 @@ def getTests(path, base_path):
result.append(unittest.TestLoader().loadTestsFromModule(mod))
return result
-class TextTestResult(TestResult):
+class TextTestResult(_TextTestResult):
"""
- We need a subclass of unittest.TestResult to handle tests with TODO
- Most of this class is copied from the unittest._TextTestResult that's
- included with python-2.6 (but not included with python-2.7).
+ We need a subclass of unittest._TextTestResult to handle tests with TODO
This just adds an addTodo method that can be used to add tests
that are marked TODO; these can be displayed later
by the test runner.
"""
- separator1 = '=' * 70
- separator2 = '-' * 70
-
def __init__(self, stream, descriptions, verbosity):
- unittest.TestResult.__init__(self)
- self.stream = stream
- self.showAll = verbosity > 1
- self.dots = verbosity == 1
- self.descriptions = descriptions
+ super(TextTestResult, self).__init__(stream, descriptions, verbosity)
self.todoed = []
def addTodo(self, test, info):
@@ -106,50 +101,6 @@ class TextTestResult(TestResult):
self.printErrorList('FAIL', self.failures)
self.printErrorList('TODO', self.todoed)
- def getDescription(self, test):
- if self.descriptions:
- return test.shortDescription() or str(test)
- else:
- return str(test)
-
- def startTest(self, test):
- TestResult.startTest(self, test)
- if self.showAll:
- self.stream.write(self.getDescription(test))
- self.stream.write(" ... ")
- self.stream.flush()
-
- def addSuccess(self, test):
- TestResult.addSuccess(self, test)
- if self.showAll:
- self.stream.writeln("ok")
- elif self.dots:
- self.stream.write('.')
- self.stream.flush()
-
- def addError(self, test, err):
- TestResult.addError(self, test, err)
- if self.showAll:
- self.stream.writeln("ERROR")
- elif self.dots:
- self.stream.write('E')
- self.stream.flush()
-
- def addFailure(self, test, err):
- TestResult.addFailure(self, test, err)
- if self.showAll:
- self.stream.writeln("FAIL")
- elif self.dots:
- self.stream.write('F')
- self.stream.flush()
-
- def printErrorList(self, flavour, errors):
- for test, err in errors:
- self.stream.writeln(self.separator1)
- self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
- self.stream.writeln(self.separator2)
- self.stream.writeln("%s" % err)
-
class TestCase(unittest.TestCase):
"""
We need a way to mark a unit test as "ok to fail"