Ejemplo n.º 1
0
    def test_addProtoTestResult(self):
        """
        addProtoTestResult adds the correct things to the correct places.
        """
        ptr = ProtoTestResult()

        err_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            err_e = proto_error(sys.exc_info())
        ptr.addError(err_t, err_e)

        ef_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            ef_e = proto_error(sys.exc_info())
        ptr.addExpectedFailure(ef_t, ef_e)

        fail_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            fail_e = proto_error(sys.exc_info())
        ptr.addFailure(fail_t, fail_e)

        pass_t = proto_test(MagicMock())
        ptr.addSuccess(pass_t)

        skip_t = proto_test(MagicMock())
        skip_r = proto_test(MagicMock())
        ptr.addSkip(skip_t, skip_r)

        us_t = proto_test(MagicMock())
        ptr.addUnexpectedSuccess(us_t)

        self.args.verbose = 0
        gtr = GreenTestResult(self.args, GreenStream(self.stream))
        gtr.addProtoTestResult(ptr)

        self.assertEqual(gtr.errors, [(err_t, err_e)])
        self.assertEqual(gtr.expectedFailures, [(ef_t, ef_e)])
        self.assertEqual(gtr.failures, [(fail_t, fail_e)])
        self.assertEqual(gtr.passing, [pass_t])
        self.assertEqual(gtr.skipped, [(skip_t, skip_r)])
        self.assertEqual(gtr.unexpectedSuccesses, [us_t])
Ejemplo n.º 2
0
    def test_addProtoTestResult(self):
        """
        addProtoTestResult adds the correct things to the correct places.
        """
        ptr = ProtoTestResult()

        err_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            err_e = proto_error(sys.exc_info())
        ptr.addError(err_t, err_e)

        ef_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            ef_e = proto_error(sys.exc_info())
        ptr.addExpectedFailure(ef_t, ef_e)

        fail_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            fail_e = proto_error(sys.exc_info())
        ptr.addFailure(fail_t, fail_e)

        pass_t = proto_test(MagicMock())
        ptr.addSuccess(pass_t)

        skip_t = proto_test(MagicMock())
        skip_r = proto_test(MagicMock())
        ptr.addSkip(skip_t, skip_r)

        us_t = proto_test(MagicMock())
        ptr.addUnexpectedSuccess(us_t)

        self.args.verbose = 0
        gtr = GreenTestResult(self.args, GreenStream(self.stream))
        gtr.addProtoTestResult(ptr)

        self.assertEqual(gtr.errors, [(err_t, err_e)])
        self.assertEqual(gtr.expectedFailures, [(ef_t, ef_e)])
        self.assertEqual(gtr.failures, [(fail_t, fail_e)])
        self.assertEqual(gtr.passing, [pass_t])
        self.assertEqual(gtr.skipped, [(skip_t, skip_r)])
        self.assertEqual(gtr.unexpectedSuccesses, [us_t])
Ejemplo n.º 3
0
 def test_addExpectedFailure(self):
     "addExpectedFailure() makes the correct calls to other functions."
     try:
         raise Exception
     except:
         err = sys.exc_info()
     test = proto_test(MagicMock())
     err = proto_error(err)
     self.gtr.addExpectedFailure(test, err)
     self.gtr._reportOutcome.assert_called_with(
             test, 'x', self.gtr.colors.expectedFailure, err)
Ejemplo n.º 4
0
 def test_addExpectedFailure(self):
     "addExpectedFailure adds a test and error correctly"
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     try:
         raise Exception
     except:
         err = proto_error(sys.exc_info())
     ptr.addExpectedFailure(test, err)
     self.assertEqual(test, ptr.expectedFailures[0][0])
     self.assertEqual(err, ptr.expectedFailures[0][1])
Ejemplo n.º 5
0
 def test_str(self):
     """
     Running a ProtoError through str() should result in a traceback string
     """
     test_str = 'noetuaoe'
     try:
         raise Exception(test_str)
     except:
         err = sys.exc_info()
     pe = proto_error(err)
     self.assertIn(test_str, str(pe))
Ejemplo n.º 6
0
 def test_str(self):
     """
     Running a ProtoError through str() should result in a traceback string
     """
     test_str = 'noetuaoe'
     try:
         raise Exception(test_str)
     except:
         err = sys.exc_info()
     pe = proto_error(err)
     self.assertIn(test_str, str(pe))
Ejemplo n.º 7
0
 def test_addExpectedFailure(self):
     """
     addExpectedFailure adds a test and error correctly
     """
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     try:
         raise Exception
     except:
         err = proto_error(sys.exc_info())
     ptr.addExpectedFailure(test, err)
     self.assertEqual(test, ptr.expectedFailures[0][0])
     self.assertEqual(err, ptr.expectedFailures[0][1])
Ejemplo n.º 8
0
 def test_addExpectedFailure(self):
     """
     addExpectedFailure() makes the correct calls to other functions.
     """
     try:
         raise Exception
     except:
         err = sys.exc_info()
     test = proto_test(MagicMock())
     err = proto_error(err)
     self.gtr.addExpectedFailure(test, err)
     self.gtr._reportOutcome.assert_called_with(
             test, 'x', self.gtr.colors.expectedFailure, err)
Ejemplo n.º 9
0
    def test_addExcepectedFailure_with_test_time(self):
        """
        addExpectedFailure() makes test time correct value
        """
        try:
            raise Exception
        except:
            err = sys.exc_info()
        test = proto_test(MagicMock())
        err = proto_error(err)
        self.gtr.addExpectedFailure(test, err, "0.42")

        self.assertEqual(test.test_time, "0.42")
Ejemplo n.º 10
0
    def test_addError_with_test_time(self):
        """
        addError() sets test time to correct value
        """
        try:
            raise Exception
        except:
            err = sys.exc_info()
        test = proto_test(MagicMock())
        err = proto_error(err)
        self.gtr.addError(test, err, '0.42')

        self.assertEqual(test.test_time, '0.42')
Ejemplo n.º 11
0
 def test_failfastAddFailure(self):
     """
     addFailure triggers failfast when it is set
     """
     self.args.failfast = True
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     self.assertEqual(gtr.failfast, True)
     try:
         raise Exception
     except:
         err = sys.exc_info()
     self.assertEqual(gtr.shouldStop, False)
     gtr.addFailure(MyProtoTest(), proto_error(err))
     self.assertEqual(gtr.shouldStop, True)
Ejemplo n.º 12
0
 def test_failfastAddFailure(self):
     """
     addFailure triggers failfast when it is set
     """
     self.args.failfast = True
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     self.assertEqual(gtr.failfast, True)
     try:
         raise Exception
     except:
         err = sys.exc_info()
     self.assertEqual(gtr.shouldStop, False)
     gtr.addFailure(MyProtoTest(), proto_error(err))
     self.assertEqual(gtr.shouldStop, True)
Ejemplo n.º 13
0
 def test_printErrorsDots(self):
     "printErrors() looks correct in verbose=1 (dots) mode"
     try:
         raise Exception
     except:
         err = sys.exc_info()
     gtr = GreenTestResult(GreenStream(self.stream), None, 1)
     test = MagicMock()
     gtr.addError(test, proto_error(err))
     gtr.printErrors()
     self.assertTrue('\n\n' in self.stream.getvalue())
     self.assertTrue('test_printErrorsDots' in self.stream.getvalue())
     self.assertTrue('raise Exception' in self.stream.getvalue())
     self.assertTrue('Error' in self.stream.getvalue())
Ejemplo n.º 14
0
 def test_printErrorsNoTracebacks(self):
     """
     printErrors() omits tracebacks for failures and errors when
     no_tracebacks is True
     """
     self.args.no_tracebacks = True
     try:
         raise Exception
     except:
         err = sys.exc_info()
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     pt = MyProtoTest()
     gtr.addError(pt, proto_error(err))
     gtr.printErrors()
     self.assertNotIn("Exception", self.stream.getvalue())
Ejemplo n.º 15
0
 def test_printErrorsVerbose2(self):
     "printErrors() looks correct in verbose=2 mode"
     try:
         raise Exception
     except:
         err = sys.exc_info()
     gtr = GreenTestResult(GreenStream(self.stream), None, 2)
     gtr.test_output_line = "   some test output"
     test = MagicMock()
     gtr.addError(test, proto_error(err))
     gtr.printErrors()
     self.assertTrue('\n\n' in self.stream.getvalue())
     self.assertTrue('test_printErrorsVerbose2' in self.stream.getvalue())
     self.assertTrue('raise Exception' in self.stream.getvalue())
     self.assertTrue('Error' in self.stream.getvalue())
Ejemplo n.º 16
0
 def test_printErrorsNoTracebacks(self):
     """
     printErrors() omits tracebacks for failures and errors when
     no_tracebacks is True
     """
     self.args.no_tracebacks = True
     try:
         raise Exception
     except:
         err = sys.exc_info()
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     pt = MyProtoTest()
     gtr.addError(pt, proto_error(err))
     gtr.printErrors()
     self.assertNotIn("Exception", self.stream.getvalue())
Ejemplo n.º 17
0
 def test_printErrorsVerbose3(self):
     """
     printErrors() looks correct in verbose=3 mode
     """
     try:
         raise Exception
     except:
         err = sys.exc_info()
     gtr = GreenTestResult(GreenStream(self.stream), None, 3, False, False)
     gtr.addError(MyProtoTest(), proto_error(err))
     gtr.printErrors()
     self.assertIn('\n\n', self.stream.getvalue())
     self.assertIn('my_module.MyClass.myMethod', self.stream.getvalue())
     self.assertIn('test_printErrorsVerbose3', self.stream.getvalue())
     self.assertIn('raise Exception', self.stream.getvalue())
     self.assertIn('Error', self.stream.getvalue())
Ejemplo n.º 18
0
 def test_addFailureTwistedSkip(self):
     """
     Twisted's practice of calling addFailure() with their skips is detected
     and redirected to addSkip()
     """
     err = None
     try:
         raise Exception
     except:
         err = sys.exc_info()
     test = proto_test(MagicMock())
     reason = "Twisted is odd"
     err = proto_error(err)
     err.traceback_lines = ["UnsupportedTrialFeature: ('skip', '{}')"
                            .format(reason)]
     self.gtr.addFailure(test, err)
     self.gtr._reportOutcome.assert_called_with(
             test, 's', self.gtr.colors.skipped, reason=reason)
Ejemplo n.º 19
0
 def test_printErrors_Py2Unicode(self):
     """
     printErrors() doesn't crash in Python 2 when tracebacks contain unicode
     """
     try:
         raise Exception(u'Das Böse ist immer und überall')
     except:
         err = sys.exc_info()
     self.args.verbose = 1
     self.args.termcolor = False
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     gtr.addError(MyProtoTest(), proto_error(err))
     gtr.printErrors() # We shouldn't hit an exception here
     self.assertIn('\n\n', self.stream.getvalue())
     self.assertIn('my_module.MyClass.myMethod', self.stream.getvalue())
     self.assertIn('raise Exception', self.stream.getvalue())
     self.assertIn('Error', self.stream.getvalue())
     self.assertIn('Böse', self.stream.getvalue())
Ejemplo n.º 20
0
 def test_printErrorsVerbose3(self):
     """
     printErrors() looks correct in verbose=3 mode.
     """
     try:
         raise Exception
     except:
         err = sys.exc_info()
     self.args.verbose = 3
     self.args.termcolor = False
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     gtr.addError(MyProtoTest(), proto_error(err))
     gtr.printErrors()
     self.assertIn('\n\n', self.stream.getvalue())
     self.assertIn('my_module.MyClass.myMethod', self.stream.getvalue())
     self.assertIn('test_printErrorsVerbose3', self.stream.getvalue())
     self.assertIn('raise Exception', self.stream.getvalue())
     self.assertIn('Error', self.stream.getvalue())
Ejemplo n.º 21
0
 def test_printErrors_Py2Unicode(self):
     """
     printErrors() doesn't crash in Python 2 when tracebacks contain unicode
     """
     try:
         raise Exception(u'Das Böse ist immer und überall')
     except:
         err = sys.exc_info()
     self.args.verbose = 1
     self.args.termcolor = False
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     gtr.addError(MyProtoTest(), proto_error(err))
     gtr.printErrors() # We shouldn't hit an exception here
     self.assertIn('\n\n', self.stream.getvalue())
     self.assertIn('my_module.MyClass.myMethod', self.stream.getvalue())
     self.assertIn('raise Exception', self.stream.getvalue())
     self.assertIn('Error', self.stream.getvalue())
     self.assertIn('Böse', self.stream.getvalue())
Ejemplo n.º 22
0
 def test_printErrorsDots(self):
     """
     printErrors() looks correct in verbose=1 (dots) mode.
     """
     try:
         raise Exception
     except:
         err = sys.exc_info()
     self.args.verbose = 1
     self.args.termcolor = False
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     gtr.addError(MyProtoTest(), proto_error(err))
     gtr.printErrors()
     self.assertIn("\n\n", self.stream.getvalue())
     self.assertIn("my_module.MyClass.myMethod", self.stream.getvalue())
     self.assertIn("test_printErrorsDots", self.stream.getvalue())
     self.assertIn("raise Exception", self.stream.getvalue())
     self.assertIn("Error", self.stream.getvalue())
Ejemplo n.º 23
0
 def test_printErrorsVerbose2(self):
     """
     printErrors() looks correct in verbose=2 mode.
     """
     try:
         raise Exception
     except:
         err = sys.exc_info()
     self.args.verbose = 2
     self.args.termcolor = False
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     gtr.addError(MyProtoTest(), proto_error(err))
     gtr.printErrors()
     self.assertIn('\n\n', self.stream.getvalue())
     self.assertIn('my_module.MyClass.myMethod', self.stream.getvalue())
     self.assertIn('test_printErrorsVerbose2', self.stream.getvalue())
     self.assertIn('raise Exception', self.stream.getvalue())
     self.assertIn('Error', self.stream.getvalue())
Ejemplo n.º 24
0
 def test_addFailureTwistedSkip(self):
     """
     Twisted's practice of calling addFailure() with their skips is detected
     and redirected to addSkip()
     """
     err = None
     try:
         raise Exception
     except:
         err = sys.exc_info()
     test = proto_test(MagicMock())
     reason = "Twisted is odd"
     err = proto_error(err)
     err.traceback_lines = ["UnsupportedTrialFeature: ('skip', '{}')"
                            .format(reason)]
     self.gtr.addFailure(test, err)
     self.gtr._reportOutcome.assert_called_with(
             test, 's', self.gtr.colors.skipped, reason=reason)
Ejemplo n.º 25
0
 def test_printErrorsStdoutQuietStdoutOnError(self):
     """
     printErrors() prints out the captured stdout
     except when quiet_stdout is set to True
     for successful tests, but here we are on a
     failing test.
     """
     self.args.quiet_stdout = True
     try:
         raise Exception
     except:
         err = sys.exc_info()
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     pt = MyProtoTest()
     output = 'this is what the test should spit out to stdout'
     gtr.recordStdout(pt, output)
     gtr.addError(pt, proto_error(err))
     gtr.printErrors()
     self.assertIn(output, self.stream.getvalue())
Ejemplo n.º 26
0
 def test_printErrorsStdoutQuietStdoutOnError(self):
     """
     printErrors() prints out the captured stdout
     except when quiet_stdout is set to True
     for successful tests, but here we are on a
     failling test.
     """
     self.args.quiet_stdout = True
     try:
         raise Exception
     except:
         err = sys.exc_info()
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     pt = MyProtoTest()
     output = 'this is what the test should spit out to stdout'
     gtr.recordStdout(pt, output)
     gtr.addError(pt, proto_error(err))
     gtr.printErrors()
     self.assertIn(output, self.stream.getvalue())
Ejemplo n.º 27
0
 def test_printErrorsZHTML(self):
     "printErrors() looks correct in html mode"
     try:
         raise Exception
     except:
         err = sys.exc_info()
     gtr = GreenTestResult(GreenStream(self.stream), None, 4)
     gtr.colors.html = True
     gtr.test_output_line = "   some test output"
     test = MagicMock()
     gtr.addError(test, proto_error(err))
     gtr.printErrors()
     self.assertTrue('\n\n' in self.stream.getvalue())
     self.assertTrue('(most recent call last)' in self.stream.getvalue())
     self.assertTrue('test_printErrorsZHTML' in self.stream.getvalue())
     self.assertTrue('raise Exception' in self.stream.getvalue())
     self.assertTrue('Error' in self.stream.getvalue())
     self.assertTrue('<span' in self.stream.getvalue())
     self.assertTrue('color: rgb(' in self.stream.getvalue())
Ejemplo n.º 28
0
 def test_printErrorsZHTML(self):
     """
     printErrors() looks correct in html mode
     """
     try:
         raise Exception
     except:
         err = sys.exc_info()
     self.args.verbose = 4
     gtr = GreenTestResult(self.args, GreenStream(self.stream))
     gtr.colors.html = True
     test = MagicMock()
     gtr.addError(test, proto_error(err))
     gtr.printErrors()
     self.assertIn('\n\n', self.stream.getvalue())
     self.assertIn('(most recent call last)', self.stream.getvalue())
     self.assertIn('test_printErrorsZHTML', self.stream.getvalue())
     self.assertIn('raise Exception', self.stream.getvalue())
     self.assertIn('Error', self.stream.getvalue())
     self.assertIn('<span', self.stream.getvalue())
     self.assertIn('color: rgb(', self.stream.getvalue())
Ejemplo n.º 29
0
 def _record_failure(self, test):
     try:
         raise ValueError("Wrong value")
     except:
         error = proto_error(exc_info())
     self._test_results.addFailure(test, error)
Ejemplo n.º 30
0
 def _record_error(self, test):
     try:
         raise ValueError("Wrong value")
     except:
         error = proto_error(exc_info())
     self._test_results.addError(test, error)