Пример #1
0
    def test_tryRecordingStdoutStderr(self):
        """
        Recording stdout and stderr works correctly.
        """
        gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
        gtr.recordStdout = MagicMock()
        gtr.recordStderr = MagicMock()

        output = 'apple'
        test1 = MagicMock()
        ptr1 = MagicMock()
        ptr1.stdout_output = {test1:output}
        ptr1.stderr_errput = {}

        errput = 'banana'
        test2 = MagicMock()
        ptr2 = MagicMock()
        ptr2.stdout_output = {}
        ptr2.stderr_errput = {test2:errput}


        gtr.tryRecordingStdoutStderr(test1, ptr1)
        gtr.recordStdout.assert_called_with(test1, output)
        gtr.tryRecordingStdoutStderr(test2, ptr2)
        gtr.recordStderr.assert_called_with(test2, errput)
Пример #2
0
 def test_reportOutcome(self):
     """
     _reportOutcome contains output we expect
     """
     self.args.verbose = 1
     gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
     gtr._reportOutcome(None, '.', lambda x: x)
     self.assertIn('.', self.stream.getvalue())
Пример #3
0
 def test_wasSuccessful(self):
     """
     wasSuccessful returns what we expect
     """
     self.args.verbose = 1
     gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
     self.assertEqual(gtr.wasSuccessful(), True)
     gtr.all_errors.append('anything')
     self.assertEqual(gtr.wasSuccessful(), False)
Пример #4
0
 def test_failfastAddUnexpectedSuccess(self):
     """
     addUnexpectedSuccess triggers failfast when it is set
     """
     self.args.failfast = True
     gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
     self.assertEqual(gtr.failfast, True)
     self.assertEqual(gtr.shouldStop, False)
     gtr.addUnexpectedSuccess(MyProtoTest())
     self.assertEqual(gtr.shouldStop, True)
Пример #5
0
 def test_printErrorsSkipreport(self):
     """
     printErrors() prints the skip report
     """
     self.args.verbose = 1
     gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
     pt = MyProtoTest()
     reason = "dog ate homework"
     gtr.addSkip(pt, reason)
     gtr.printErrors()
     self.assertIn(reason, self.stream.getvalue())
Пример #6
0
 def test_printErrorsStdout(self):
     """
     printErrors() prints out the captured stdout
     """
     self.args.verbose = 1
     self.args.termcolor = False
     gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
     pt = MyProtoTest()
     output = 'this is what the test spit out to stdout'
     gtr.recordStdout(pt, output)
     gtr.addSuccess(pt)
     gtr.printErrors()
     self.assertIn(output, self.stream.getvalue())
Пример #7
0
 def _outputFromVerboseTest(self):
     """
     Start a test with verbose = 2 and get its output.
     """
     class FakeCase(unittest.TestCase):
         def runTest(self):
             pass
     self.args.verbose = 2
     gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
     tc = FakeCase()
     gtr.startTest(tc)
     output = self.stream.getvalue()
     return output.split('\n')
Пример #8
0
 def test_failfastAddFailure(self):
     """
     addFailure triggers failfast when it is set
     """
     self.args.failfast = True
     gtr = fetchdataTestResult(self.args, fetchdataStream(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)
Пример #9
0
 def test_reportOutcomeVerbose(self):
     """
     _reportOutcome contains output we expect in verbose mode
     """
     self.args.verbose = 2
     def isatty():
         return True
     gs = fetchdataStream(self.stream)
     gs.isatty = isatty
     gtr = fetchdataTestResult(self.args, gs)
     r = 'a fake reason'
     t = MagicMock()
     t.__str__.return_value = 'junk'
     gtr._reportOutcome(t, '.', lambda x: x, None, r)
     self.assertIn(r, self.stream.getvalue())
Пример #10
0
 def test_reportOutcomeCursorUp(self):
     """
     _reportOutcome moves the cursor up when it needs to
     """
     self.args.verbose = 2
     def isatty():
         return True
     gs = fetchdataStream(self.stream)
     gs.isatty = isatty
     gtr = fetchdataTestResult(self.args, gs)
     r = 'a fake reason'
     t = MagicMock()
     t.__str__.return_value = 'x' * 1000
     gtr._reportOutcome(t, '.', lambda x: x, None, r)
     self.assertIn(r, self.stream.getvalue())
     self.assertLess(len(self.stream.getvalue()), 2000)
Пример #11
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 = fetchdataTestResult(self.args, fetchdataStream(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])
Пример #12
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 = fetchdataTestResult(self.args, fetchdataStream(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())
Пример #13
0
    def test_stopTestRun(self, mock_printErrors):
        """
        We ignore coverage's error about not having anything to cover.
        """
        try:
            from coverage.misc import CoverageException
        except:
            self.skipTest("Coverage needs to be installed for this test.")
        self.args.cov = MagicMock()
        self.args.cov.stop = MagicMock(
                side_effect=CoverageException('Different Exception'))
        self.args.run_coverage = True
        gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
        gtr.startTestRun()
        self.assertRaises(CoverageException, gtr.stopTestRun)

        self.args.cov.stop = MagicMock(
                side_effect=CoverageException('No data to report'))
Пример #14
0
 def setUp(self):
     self.stream = StringIO()
     self.args = copy.deepcopy(default_args)
     self.args.verbose = 0
     self.gtr = fetchdataTestResult(self.args, fetchdataStream(self.stream))
     self.gtr._reportOutcome = MagicMock()