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