def __init__(self): TestResult.__init__(self) self.start_at = time.time() self.testSuccess = [] self.all_tests = {} self.results_log = {} self.note_log = []
def addError(self, test, err): TestResult.addError(self, test, err) err = self.formatErr(err) self.messages.testFailed(self.getTestName(test), message='Error', details=err)
def addError(self, test, err): testname = test.id().split(".")[-1] tb = err[2] stack = traceback.extract_tb(tb) for frame in stack: fname = frame[2] if fname == testname: if self._logging: self._writeToStream("\tResult: ") self._writeToStream("Test ERROR", eColors.Yellow) break if fname == "setUp": if self._logging: self._writeToStream("\tResult: ") self._writeToStream("SetUp ERROR", eColors.Yellow) break if fname == "tearDown": #If test succeded but tear down failed the result should #still be that the test failed. So it's my resposibility #to display thet only the 'test' part of the test passed. (Confused yet?) faults = chain(self.failures, self.errors) testFaults = ifilter(lambda item: item[0] == test, faults) hasFailed = (sum(1 for u in testFaults) > 0) if not hasFailed: if self._logging: self._writeToStream("\tResult: ") self._writeToStream("PASSED", eColors.Green) self._writeToStream(", ") self._writeToStream("Tear Down ERROR", eColors.Yellow) break TestResult.addError(self, test, err)
def addError(self, test, err): TestResult.addError(self, test, err) err = self._exc_info_to_string(err, test) self.messages.testError(self.getTestName(test), message='Error', details=err)
def addFailure(self, test, err, *k): TestResult.addFailure(self, test, err) err = self.formatErr(err) self.messages.testFailed(self.getTestName(test), message='Failure', details=err)
def addSkip(self, test, reason): TestResult.addSkip(self, test, reason) if self.verbose: self.stream.write("SKIPPED: %s [%s]%s" % (test, reason, os.linesep)) self.stream.flush() self.countcall()
def stopTest(self, test): stopTime = time.time() deltaTime = stopTime - self._startTime TestResult.stopTest(self, test) self.stream.write(' time="%.3f"' % deltaTime) self.stream.write('>') if self._lastWas != 'success': if self._lastWas == 'error': self.stream.write(self._errorsAndFailures) elif self._lastWas == 'failure': self.stream.write(self._errorsAndFailures) else: assert(False) seen = {} for assertion in test._extraAssertions: if not seen.has_key(assertion): self._addAssertion(assertion[:110]) # :110 avoids tl;dr TODO use a lexical truncator seen[assertion] = True self.stream.write('</testcase>') self._errorsAndFailures = "" if test._extraXML != '': self.stream.write(test._extraXML)
def stopTest(self, test): """Called when the given test has been run. If the stop flag was raised beforehand, will broadcast to raise flags for global stop.""" stop_flags = np.empty(self.comm.size, dtype=bool) self.comm.all_gather(np.array([self.shouldStop]), stop_flags) self.shouldStop = stop_flags.any() TestResult.stopTest(self, test)
def addFailure(self, test, err): location = self.init_suite(test) self.current_failed = True TestResult.addFailure(self, test, err) error_value = smart_str(err[1]) if not len(error_value): # means it's test function and we have to extract value from traceback error_value = self.find_error_value(err[2]) self_find_first = self.find_first(error_value) self_find_second = self.find_second(error_value) quotes = ["'", '"'] if ( self_find_first[0] == self_find_first[-1] and self_find_first[0] in quotes and self_find_second[0] == self_find_second[-1] and self_find_second[0] in quotes ): # let's unescape strings to show sexy multiline diff in PyCharm. # By default all caret return chars are escaped by testing framework first = self._unescape(self_find_first) second = self._unescape(self_find_second) else: first = second = "" err = self._exc_info_to_string(err, test) self.messages.testStarted(self.getTestName(test), location=location) duration = self.__getDuration(test) self.messages.testFailed( self.getTestName(test), message="Failure", details=err, expected=first, actual=second, duration=duration )
def addFailure(self, test, err): TestResult.addFailure(self, test, err) if self.showAll: self.stream.writeln("FAIL") elif self.dots: self.printError('FAIL', err, test) self.stream.flush()
def __init__(self, stream=sys.stdout): TestResult.__init__(self) self.output = stream self.test_started_datetime = None self.test_name = None self.createMessages()
def startTest(self, test): "Called before execute each test method." self.start_time = time.time() TestResult.startTest(self, test) if self.showAll: self.stream.write(' ' + self.getDescription(test)) self.stream.write(" ... ")
def addSkip(self, test, reason): """Called when a test is skipped.""" TestResult.addSkip(self, test, reason) if self.verbose: self.stream.write('skipped (%s)\n' % reason) else: self.stream.write('s') self.stream.flush()
def addError(self, test, err): """Called when an error has occurred.""" TestResult.addError(self, test, err) if self.verbose: self.stream.write('ERROR\n') else: self.stream.write('E') self.stream.flush()
def __init__(self, comm=None): if comm is None: comm = world self.comm = comm self.outcomes = [] self.last_errors = np.empty(self.comm.size, dtype=bool) self.last_failed = np.empty(self.comm.size, dtype=bool) TestResult.__init__(self)
def addFailure(self, test, err): TestResult.addFailure(self, test, err) exctype, value, dummy_tb = err error_xml = self.xml.createElement('failure') error_xml.setAttribute('type', '%s' % exctype) message_xml = self.xml.createTextNode('%s' % value) error_xml.appendChild(message_xml) self._testcase_xml.appendChild(error_xml)
def __init__(self, parent): """ Constructor @param parent The parent widget. """ TestResult.__init__(self) self.parent = parent
def addSuccess(self, test): "Called when a test has completed successfully" TestResult.addSuccess(self, test) if self.verbose: self.stream.write('ok\n') else: self.stream.write('.') self.stream.flush()
def __init__(self, stream=sys.stdout, *args, **kwargs): TestResult.__init__(self) for arg, value in kwargs.items(): setattr(self, arg, value) self.output = stream self.messages = TeamcityServiceMessages(self.output, prepend_linebreak=True) self.messages.testMatrixEntered() self.current_suite = None
def addError(self, test, err): location = self.init_suite(test) self.current_failed = True TestResult.addError(self, test, err) err = self._exc_info_to_string(err, test) self.messages.testStarted(self.getTestName(test), location=location) self.messages.testError(self.getTestName(test), message="Error", details=err, duration=self.__getDuration(test))
def __init__(self, xml, descriptions, verbosity): TestResult.__init__(self) self.xml = xml self.showAll = verbosity > 1 self.dots = verbosity == 1 self.descriptions = descriptions self._testsuites = {} self._testsuite_xml = None self._testcase_xml = None
def __init__(self, stream, descriptions, verbosity): TestResult.__init__(self) self.stream = _WritelnDecorator(stream) self.showAll = verbosity > 1 self.descriptions = descriptions self._lastWas = 'success' self._errorsAndFailures = "" self._startTime = 0.0 self.params=""
def startTest(self, test): """ Method called at the start of a test. @param test Reference to the test object """ TestResult.startTest(self, test) self.parent.write('%s%s\n' % (ResponseUTStartTest, unicode((unicode(test), test.shortDescription()))))
def startTest(self, test): """ Method called at the start of a test. @param test Reference to the test object """ TestResult.startTest(self, test) self.parent.write('{0}{1}\n'.format(ResponseUTStartTest, str((str(test), test.shortDescription()))))
def startTest(self, test): TestResult.startTest(self, test) # just one buffer for both stdout and stderr stdout_redirector.fp = self.outputBuffer stderr_redirector.fp = self.outputBuffer self.stdout0 = sys.stdout self.stderr0 = sys.stderr sys.stdout = stdout_redirector sys.stderr = stderr_redirector
def __init__(self): buildstep.LogLineObserver.__init__(self) TestResult.__init__(self) try: from subunit import TestProtocolServer except ImportError: raise ImportError("subunit is not importable, but is required for " "SubunitLogObserver support.") self.protocol = TestProtocolServer(self, DiscardStream())
def addUnexpectedSuccess(self, test): """ Public method called if a test succeeded expectedly. @param test reference to the test object """ TestResult.addUnexpectedSuccess(self, test) self.parent.write('{0}{1}\n'.format( ResponseUTTestSucceededUnexpected, str((str(test), test.id()))))
def addError(self, test, err): TestResult.addError(self, test, err) if err[0] is KeyboardInterrupt: self.shouldStop = 1 self._lastWas = 'error' self._errorsAndFailures += '<error type="%s">' % err[0].__name__ for line in apply(traceback.format_exception, err): for l in string.split(line,"\n")[:-1]: self._errorsAndFailures += "%s" % l self._errorsAndFailures += "</error>"
def __init__(self, result): """Constructor. @param result: TestResult The wrapped object """ assert isinstance(result, TestResult); TestResult.__init__(self); self._result = result;
def addFailure(self, test, err): TestResult.addFailure(self, test, err) if err[0] is KeyboardInterrupt: self.shouldStop = 1 self._lastWas = 'failure' self._errorsAndFailures += '<failure type="%s">' % err[0].__name__ for line in apply(traceback.format_exception, err): for l in line.split("\n")[:-1]: self._errorsAndFailures += escape(l) self._errorsAndFailures += "</failure>"
def addFailure(self, test, err): TestResult.addFailure(self, test, err) self.issue()
def __init__(self, stream, descriptions): _TestResult.__init__(self) self.stream = stream self.descriptions = descriptions
def addSkip(self, test, reason): TestResult.addSkip(self, test, reason) self.stream.writeln(hilite("skipped: %s" % reason, BROWN))
def addSuccess(self, test): _TestResult.addSuccess(self, test) self.printStatus('TEST-PASS', test)
def addError(self, test, err): TestResult.addError(self, test, err) self.issue()
def addFailure(self, test, err): _TestResult.addFailure(self, test, err) self.printFail(test, err) self.stream.writeln("FAIL: {0}".format(self.getDescription(test))) self.stream.writeln(self.failures[-1][1])
def startTest(self, test): UnitTestResult.startTest(self, test) if self.showAll: self._errWrite(str(test)) self._errWrite(' ... ')
def addExpectedFailure(self, test, err): _TestResult.addExpectedFailure(self, test, err) self.printStatus('TEST-KNOWN-FAIL', test)
def addError(self, test, err): TestResult.addError(self, test, err) self.stream.writeln(hilite("ERROR", RED, bold=True))
def addSuccess(self, test): TestResult.addSuccess(self, test)
def addUnexpectedSuccess(self, test): _TestResult.addUnexpectedSuccess(self, test) self.printStatus('TEST-UNEXPECTED-PASS', test)
def addSuccess(self, test, *k): TestResult.addSuccess(self, test) self.output.write("ok\n")
def addSuccess(self, test): TestResult.addSuccess(self, test) self._color_print("OK", GREEN)
def addFailure(self, test, err): TestResult.addFailure(self, test, err) self.stream.writeln(hilite("FAIL", RED))
def addSkip(self, test, reason): _TestResult.addSkip(self, test, reason) self.printStatus('TEST-SKIP', test)
def run_test_case_tests(test_case_class): test_suite = defaultTestLoader.loadTestsFromTestCase(test_case_class) test_result = TestResult() test_suite.run(test_result) return test_result
def addSkip(self, test, detail): if hasattr(TestResult, 'addSkip'): TestResult.addSkip(self, test, detail) else: self.skips.append((test, detail)) self.addAResult(test, SKIPPED, 'SKIPPED', detail)
def addError(self, test, err): _TestResult.addError(self, test, err) self.printFail(test, err) self.stream.writeln("ERROR: {0}".format(self.getDescription(test))) self.stream.writeln(self.errors[-1][1])
def addSuccess(self, test): TestResult.addSuccess(self, test) self.stream.writeln(hilite("OK", GREEN))
def addError(self, test, err): TestResult.addError(self, test, err) self._color_print("ERROR", RED, bold=True)
def run_module_tests(module): test_suite = defaultTestLoader.loadTestsFromModule(module) test_result = TestResult() test_suite.run(test_result) return test_result
def addSuccess(self, test): UnitTestResult.addSuccess(self, test) if self.showAll: self._errWrite('ok\n') elif self.dots: self._errWrite('.')
def _fail_into_result(self, result: unittest.TestResult, msg): """Include error with the traceback into `TestResult`""" try: raise RuntimeError(msg) except RuntimeError: result.addFailure(self, sys.exc_info())
def addFailure(self, test, err): UnitTestResult.addFailure(self, test, err) if self.showAll: self._errWrite('FAIL\n') elif self.dots: self._errWrite('F')
def __init__(self, stream=stdout, errStream=stderr, verbosity=1): UnitTestResult.__init__(self) self.showAll = verbosity > 1 self.dots = verbosity == 1 self._errStream = errStream self._stream = stream
def addError(self, test, err): UnitTestResult.addError(self, test, err) if self.showAll: self._errWrite('ERROR\n') elif self.dots: self._errWrite('E')
def addSuccess(self, test): TestResult.addSuccess(self, test) self.addAResult(test, SUCCESS, 'SUCCESS')
def startTest(self, test): TestResult.startTest(self, test) self.step.setProgress('tests', self.testsRun)
def __init__(self, stream=sys.stdout): TestResult.__init__(self) self.output = stream self.createMessages()
"EXTENSION": { "dir0": {".nest"} }, "DIRECTORY": { "dir1": {"dir0"}, "dir2": {"dir1"}, "dir3": {"dir2"}, "dir4": {"dir3"}, "dir5": {"dir4"} } } generate_files(self.testPath, "nestFile", extension="nest") def test_categorize_nested(self): categorize(self.testPath, self.testPath, config_dict=self.config) path = os.path.join(self.testPath, *["dir"+str(i) for i in range(5, -1, -1)]) self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.isdir(path)) def tearDown(self): shutil.rmtree(self.testPath) if __name__ == "__main__": suite = TestSuite() result =TestResult() suite.addTest(makeSuite(UtilityFunctionTest)) suite.addTest(makeSuite(CatergorizeSingleFileCase)) suite.addTest(makeSuite(CategorizeMultipleFileCase)) suite.addTest(makeSuite(CategorizeNestedDirectoryCase)) print(TextTestRunner().run(suite))