Esempio n. 1
0
 def __init__(self):
     TestResult.__init__(self)
     self.start_at = time.time()
     self.testSuccess = []
     self.all_tests = {}
     self.results_log = {}
     self.note_log = []
Esempio n. 2
0
 def addError(self, test, err):
     TestResult.addError(self, test, err)
     
     err = self.formatErr(err)
     
     self.messages.testFailed(self.getTestName(test),
         message='Error', details=err)
Esempio n. 3
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
    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
        )
Esempio n. 10
0
 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()
Esempio n. 11
0
    def __init__(self, stream=sys.stdout):
        TestResult.__init__(self)

        self.output = stream
        self.test_started_datetime = None
        self.test_name = None

        self.createMessages()
Esempio n. 12
0
 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(" ... ")
Esempio n. 13
0
 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()
Esempio n. 14
0
 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()
Esempio n. 15
0
 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)
Esempio n. 17
0
 def __init__(self, parent):
     """
     Constructor
     
     @param parent The parent widget.
     """
     TestResult.__init__(self)
     self.parent = parent
Esempio n. 18
0
 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()
Esempio n. 19
0
 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
Esempio n. 20
0
    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
Esempio n. 22
0
 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=""
Esempio n. 23
0
 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()))))
Esempio n. 25
0
 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
Esempio n. 26
0
 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())
Esempio n. 27
0
 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()))))
Esempio n. 28
0
 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>"
Esempio n. 29
0
    def __init__(self, result):
        """Constructor.

        @param result: TestResult The wrapped object
        """
        assert isinstance(result, TestResult);

        TestResult.__init__(self);

        self._result = result;
Esempio n. 30
0
 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>"
Esempio n. 31
0
 def addFailure(self, test, err):
     TestResult.addFailure(self, test, err)
     self.issue()
Esempio n. 32
0
 def __init__(self, stream, descriptions):
     _TestResult.__init__(self)
     self.stream = stream
     self.descriptions = descriptions
Esempio n. 33
0
 def addSkip(self, test, reason):
     TestResult.addSkip(self, test, reason)
     self.stream.writeln(hilite("skipped: %s" % reason, BROWN))
Esempio n. 34
0
 def addSuccess(self, test):
     _TestResult.addSuccess(self, test)
     self.printStatus('TEST-PASS', test)
Esempio n. 35
0
 def addError(self, test, err):
     TestResult.addError(self, test, err)
     self.issue()
Esempio n. 36
0
 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])
Esempio n. 37
0
 def startTest(self, test):
     UnitTestResult.startTest(self, test)
     if self.showAll:
         self._errWrite(str(test))
         self._errWrite(' ... ')
Esempio n. 38
0
 def addExpectedFailure(self, test, err):
     _TestResult.addExpectedFailure(self, test, err)
     self.printStatus('TEST-KNOWN-FAIL', test)
Esempio n. 39
0
 def addError(self, test, err):
     TestResult.addError(self, test, err)
     self.stream.writeln(hilite("ERROR", RED, bold=True))
Esempio n. 40
0
 def addSuccess(self, test):
     TestResult.addSuccess(self, test)
Esempio n. 41
0
 def addUnexpectedSuccess(self, test):
     _TestResult.addUnexpectedSuccess(self, test)
     self.printStatus('TEST-UNEXPECTED-PASS', test)
Esempio n. 42
0
    def addSuccess(self, test, *k):
        TestResult.addSuccess(self, test)

        self.output.write("ok\n")
Esempio n. 43
0
 def addSuccess(self, test):
     TestResult.addSuccess(self, test)
     self._color_print("OK", GREEN)
Esempio n. 44
0
 def addFailure(self, test, err):
     TestResult.addFailure(self, test, err)
     self.stream.writeln(hilite("FAIL", RED))
Esempio n. 45
0
 def addSkip(self, test, reason):
     _TestResult.addSkip(self, test, reason)
     self.printStatus('TEST-SKIP', test)
Esempio n. 46
0
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
Esempio n. 47
0
 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)
Esempio n. 48
0
 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])
Esempio n. 49
0
 def addSuccess(self, test):
     TestResult.addSuccess(self, test)
     self.stream.writeln(hilite("OK", GREEN))
Esempio n. 50
0
 def addError(self, test, err):
     TestResult.addError(self, test, err)
     self._color_print("ERROR", RED, bold=True)
Esempio n. 51
0
def run_module_tests(module):
    test_suite = defaultTestLoader.loadTestsFromModule(module)
    test_result = TestResult()
    test_suite.run(test_result)
    return test_result
Esempio n. 52
0
 def addSuccess(self, test):
     UnitTestResult.addSuccess(self, test)
     if self.showAll:
         self._errWrite('ok\n')
     elif self.dots:
         self._errWrite('.')
Esempio n. 53
0
 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())
Esempio n. 54
0
 def addFailure(self, test, err):
     UnitTestResult.addFailure(self, test, err)
     if self.showAll:
         self._errWrite('FAIL\n')
     elif self.dots:
         self._errWrite('F')
Esempio n. 55
0
 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
Esempio n. 56
0
 def addError(self, test, err):
     UnitTestResult.addError(self, test, err)
     if self.showAll:
         self._errWrite('ERROR\n')
     elif self.dots:
         self._errWrite('E')
Esempio n. 57
0
 def addSuccess(self, test):
     TestResult.addSuccess(self, test)
     self.addAResult(test, SUCCESS, 'SUCCESS')
Esempio n. 58
0
 def startTest(self, test):
     TestResult.startTest(self, test)
     self.step.setProgress('tests', self.testsRun)
Esempio n. 59
0
    def __init__(self, stream=sys.stdout):
        TestResult.__init__(self)

        self.output = stream

        self.createMessages()
Esempio n. 60
0
            "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))