Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2..../unittest
File: runner.py
"""Running tests"""
[0] Fix | Delete
[1] Fix | Delete
import sys
[2] Fix | Delete
import time
[3] Fix | Delete
[4] Fix | Delete
from . import result
[5] Fix | Delete
from .signals import registerResult
[6] Fix | Delete
[7] Fix | Delete
__unittest = True
[8] Fix | Delete
[9] Fix | Delete
[10] Fix | Delete
class _WritelnDecorator(object):
[11] Fix | Delete
"""Used to decorate file-like objects with a handy 'writeln' method"""
[12] Fix | Delete
def __init__(self,stream):
[13] Fix | Delete
self.stream = stream
[14] Fix | Delete
[15] Fix | Delete
def __getattr__(self, attr):
[16] Fix | Delete
if attr in ('stream', '__getstate__'):
[17] Fix | Delete
raise AttributeError(attr)
[18] Fix | Delete
return getattr(self.stream,attr)
[19] Fix | Delete
[20] Fix | Delete
def writeln(self, arg=None):
[21] Fix | Delete
if arg:
[22] Fix | Delete
self.write(arg)
[23] Fix | Delete
self.write('\n') # text-mode streams translate to \r\n if needed
[24] Fix | Delete
[25] Fix | Delete
[26] Fix | Delete
class TextTestResult(result.TestResult):
[27] Fix | Delete
"""A test result class that can print formatted text results to a stream.
[28] Fix | Delete
[29] Fix | Delete
Used by TextTestRunner.
[30] Fix | Delete
"""
[31] Fix | Delete
separator1 = '=' * 70
[32] Fix | Delete
separator2 = '-' * 70
[33] Fix | Delete
[34] Fix | Delete
def __init__(self, stream, descriptions, verbosity):
[35] Fix | Delete
super(TextTestResult, self).__init__(stream, descriptions, verbosity)
[36] Fix | Delete
self.stream = stream
[37] Fix | Delete
self.showAll = verbosity > 1
[38] Fix | Delete
self.dots = verbosity == 1
[39] Fix | Delete
self.descriptions = descriptions
[40] Fix | Delete
[41] Fix | Delete
def getDescription(self, test):
[42] Fix | Delete
doc_first_line = test.shortDescription()
[43] Fix | Delete
if self.descriptions and doc_first_line:
[44] Fix | Delete
return '\n'.join((str(test), doc_first_line))
[45] Fix | Delete
else:
[46] Fix | Delete
return str(test)
[47] Fix | Delete
[48] Fix | Delete
def startTest(self, test):
[49] Fix | Delete
super(TextTestResult, self).startTest(test)
[50] Fix | Delete
if self.showAll:
[51] Fix | Delete
self.stream.write(self.getDescription(test))
[52] Fix | Delete
self.stream.write(" ... ")
[53] Fix | Delete
self.stream.flush()
[54] Fix | Delete
[55] Fix | Delete
def addSuccess(self, test):
[56] Fix | Delete
super(TextTestResult, self).addSuccess(test)
[57] Fix | Delete
if self.showAll:
[58] Fix | Delete
self.stream.writeln("ok")
[59] Fix | Delete
elif self.dots:
[60] Fix | Delete
self.stream.write('.')
[61] Fix | Delete
self.stream.flush()
[62] Fix | Delete
[63] Fix | Delete
def addError(self, test, err):
[64] Fix | Delete
super(TextTestResult, self).addError(test, err)
[65] Fix | Delete
if self.showAll:
[66] Fix | Delete
self.stream.writeln("ERROR")
[67] Fix | Delete
elif self.dots:
[68] Fix | Delete
self.stream.write('E')
[69] Fix | Delete
self.stream.flush()
[70] Fix | Delete
[71] Fix | Delete
def addFailure(self, test, err):
[72] Fix | Delete
super(TextTestResult, self).addFailure(test, err)
[73] Fix | Delete
if self.showAll:
[74] Fix | Delete
self.stream.writeln("FAIL")
[75] Fix | Delete
elif self.dots:
[76] Fix | Delete
self.stream.write('F')
[77] Fix | Delete
self.stream.flush()
[78] Fix | Delete
[79] Fix | Delete
def addSkip(self, test, reason):
[80] Fix | Delete
super(TextTestResult, self).addSkip(test, reason)
[81] Fix | Delete
if self.showAll:
[82] Fix | Delete
self.stream.writeln("skipped {0!r}".format(reason))
[83] Fix | Delete
elif self.dots:
[84] Fix | Delete
self.stream.write("s")
[85] Fix | Delete
self.stream.flush()
[86] Fix | Delete
[87] Fix | Delete
def addExpectedFailure(self, test, err):
[88] Fix | Delete
super(TextTestResult, self).addExpectedFailure(test, err)
[89] Fix | Delete
if self.showAll:
[90] Fix | Delete
self.stream.writeln("expected failure")
[91] Fix | Delete
elif self.dots:
[92] Fix | Delete
self.stream.write("x")
[93] Fix | Delete
self.stream.flush()
[94] Fix | Delete
[95] Fix | Delete
def addUnexpectedSuccess(self, test):
[96] Fix | Delete
super(TextTestResult, self).addUnexpectedSuccess(test)
[97] Fix | Delete
if self.showAll:
[98] Fix | Delete
self.stream.writeln("unexpected success")
[99] Fix | Delete
elif self.dots:
[100] Fix | Delete
self.stream.write("u")
[101] Fix | Delete
self.stream.flush()
[102] Fix | Delete
[103] Fix | Delete
def printErrors(self):
[104] Fix | Delete
if self.dots or self.showAll:
[105] Fix | Delete
self.stream.writeln()
[106] Fix | Delete
self.printErrorList('ERROR', self.errors)
[107] Fix | Delete
self.printErrorList('FAIL', self.failures)
[108] Fix | Delete
[109] Fix | Delete
def printErrorList(self, flavour, errors):
[110] Fix | Delete
for test, err in errors:
[111] Fix | Delete
self.stream.writeln(self.separator1)
[112] Fix | Delete
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
[113] Fix | Delete
self.stream.writeln(self.separator2)
[114] Fix | Delete
self.stream.writeln("%s" % err)
[115] Fix | Delete
[116] Fix | Delete
[117] Fix | Delete
class TextTestRunner(object):
[118] Fix | Delete
"""A test runner class that displays results in textual form.
[119] Fix | Delete
[120] Fix | Delete
It prints out the names of tests as they are run, errors as they
[121] Fix | Delete
occur, and a summary of the results at the end of the test run.
[122] Fix | Delete
"""
[123] Fix | Delete
resultclass = TextTestResult
[124] Fix | Delete
[125] Fix | Delete
def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1,
[126] Fix | Delete
failfast=False, buffer=False, resultclass=None):
[127] Fix | Delete
self.stream = _WritelnDecorator(stream)
[128] Fix | Delete
self.descriptions = descriptions
[129] Fix | Delete
self.verbosity = verbosity
[130] Fix | Delete
self.failfast = failfast
[131] Fix | Delete
self.buffer = buffer
[132] Fix | Delete
if resultclass is not None:
[133] Fix | Delete
self.resultclass = resultclass
[134] Fix | Delete
[135] Fix | Delete
def _makeResult(self):
[136] Fix | Delete
return self.resultclass(self.stream, self.descriptions, self.verbosity)
[137] Fix | Delete
[138] Fix | Delete
def run(self, test):
[139] Fix | Delete
"Run the given test case or test suite."
[140] Fix | Delete
result = self._makeResult()
[141] Fix | Delete
registerResult(result)
[142] Fix | Delete
result.failfast = self.failfast
[143] Fix | Delete
result.buffer = self.buffer
[144] Fix | Delete
startTime = time.time()
[145] Fix | Delete
startTestRun = getattr(result, 'startTestRun', None)
[146] Fix | Delete
if startTestRun is not None:
[147] Fix | Delete
startTestRun()
[148] Fix | Delete
try:
[149] Fix | Delete
test(result)
[150] Fix | Delete
finally:
[151] Fix | Delete
stopTestRun = getattr(result, 'stopTestRun', None)
[152] Fix | Delete
if stopTestRun is not None:
[153] Fix | Delete
stopTestRun()
[154] Fix | Delete
stopTime = time.time()
[155] Fix | Delete
timeTaken = stopTime - startTime
[156] Fix | Delete
result.printErrors()
[157] Fix | Delete
if hasattr(result, 'separator2'):
[158] Fix | Delete
self.stream.writeln(result.separator2)
[159] Fix | Delete
run = result.testsRun
[160] Fix | Delete
self.stream.writeln("Ran %d test%s in %.3fs" %
[161] Fix | Delete
(run, run != 1 and "s" or "", timeTaken))
[162] Fix | Delete
self.stream.writeln()
[163] Fix | Delete
[164] Fix | Delete
expectedFails = unexpectedSuccesses = skipped = 0
[165] Fix | Delete
try:
[166] Fix | Delete
results = map(len, (result.expectedFailures,
[167] Fix | Delete
result.unexpectedSuccesses,
[168] Fix | Delete
result.skipped))
[169] Fix | Delete
except AttributeError:
[170] Fix | Delete
pass
[171] Fix | Delete
else:
[172] Fix | Delete
expectedFails, unexpectedSuccesses, skipped = results
[173] Fix | Delete
[174] Fix | Delete
infos = []
[175] Fix | Delete
if not result.wasSuccessful():
[176] Fix | Delete
self.stream.write("FAILED")
[177] Fix | Delete
failed, errored = map(len, (result.failures, result.errors))
[178] Fix | Delete
if failed:
[179] Fix | Delete
infos.append("failures=%d" % failed)
[180] Fix | Delete
if errored:
[181] Fix | Delete
infos.append("errors=%d" % errored)
[182] Fix | Delete
else:
[183] Fix | Delete
self.stream.write("OK")
[184] Fix | Delete
if skipped:
[185] Fix | Delete
infos.append("skipped=%d" % skipped)
[186] Fix | Delete
if expectedFails:
[187] Fix | Delete
infos.append("expected failures=%d" % expectedFails)
[188] Fix | Delete
if unexpectedSuccesses:
[189] Fix | Delete
infos.append("unexpected successes=%d" % unexpectedSuccesses)
[190] Fix | Delete
if infos:
[191] Fix | Delete
self.stream.writeln(" (%s)" % (", ".join(infos),))
[192] Fix | Delete
else:
[193] Fix | Delete
self.stream.write("\n")
[194] Fix | Delete
return result
[195] Fix | Delete
[196] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function