class TestGreenTestResultAdds(unittest.TestCase): def setUp(self): self.stream = StringIO() self.args = copy.deepcopy(default_args) self.args.verbose = 0 self.gtr = GreenTestResult(self.args, GreenStream(self.stream)) self.gtr._reportOutcome = MagicMock() def tearDown(self): del(self.stream) del(self.gtr) def test_addSuccess(self): """ addSuccess() makes the correct calls to other functions. """ test = MagicMock() test.shortDescription.return_value = 'a' test.__str__.return_value = 'b' test = proto_test(test) self.gtr.addSuccess(test) self.gtr._reportOutcome.assert_called_with( test, '.', self.gtr.colors.passing) def test_addError(self): """ addError() 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.addError(test, err) self.gtr._reportOutcome.assert_called_with( test, 'E', self.gtr.colors.error, err) def test_addFailure(self): """ addFailure() makes the correct calls to other functions. """ err = None try: raise Exception except: err = sys.exc_info() test = proto_test(MagicMock()) err = proto_error(err) self.gtr.addFailure(test, err) self.gtr._reportOutcome.assert_called_with( test, 'F', self.gtr.colors.failing, err) 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) def test_addSkip(self): """ addSkip() makes the correct calls to other functions. """ test = proto_test(MagicMock()) reason = 'skip reason' self.gtr.addSkip(test, reason) self.gtr._reportOutcome.assert_called_with( test, 's', self.gtr.colors.skipped, reason=reason) 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) def test_addUnexpectedSuccess(self): """ addUnexpectedSuccess() makes the correct calls to other functions. """ test = proto_test(MagicMock()) self.gtr.addUnexpectedSuccess(test) self.gtr._reportOutcome.assert_called_with( test, 'u', self.gtr.colors.unexpectedSuccess) def test_wasSuccessful(self): """ wasSuccessful returns what we expect. """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) self.assertEqual(gtr.wasSuccessful(), False) gtr.passing.append('anything') self.assertEqual(gtr.wasSuccessful(), True) gtr.all_errors.append('anything') self.assertEqual(gtr.wasSuccessful(), False) def test_wasSuccessful_expectedFailures(self): """ wasSuccessful returns what we expect when we only have expectedFailures """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.expectedFailures.append('anything') self.assertEqual(gtr.wasSuccessful(), True) def test_wasSuccessful_passing(self): """ wasSuccessful returns what we expect when we only have passing tests """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.passing.append('anything') self.assertEqual(gtr.wasSuccessful(), True) def test_wasSuccessful_skipped(self): """ wasSuccessful returns what we expect when we only have skipped tests """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.skipped.append('anything') self.assertEqual(gtr.wasSuccessful(), True) def test_wasSuccessful_unexpectedSuccesses(self): """ wasSuccessful returns what we expect when we only have unexpectedSuccesses """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.unexpectedSuccesses.append('anything') self.assertEqual(gtr.wasSuccessful(), True)
class TestGreenTestResultAdds(unittest.TestCase): def setUp(self): self.stream = StringIO() self.args = copy.deepcopy(default_args) self.args.verbose = 0 self.gtr = GreenTestResult(self.args, GreenStream(self.stream)) self.gtr._reportOutcome = MagicMock() def tearDown(self): del(self.stream) del(self.gtr) def test_addSuccess(self): """ addSuccess() makes the correct calls to other functions. """ test = MagicMock() test.shortDescription.return_value = 'a' test.__str__.return_value = 'b' test = proto_test(test) self.gtr.addSuccess(test) self.gtr._reportOutcome.assert_called_with( test, '.', self.gtr.colors.passing) def test_addError(self): """ addError() 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.addError(test, err) self.gtr._reportOutcome.assert_called_with( test, 'E', self.gtr.colors.error, err) def test_addFailure(self): """ addFailure() makes the correct calls to other functions. """ err = None try: raise Exception except: err = sys.exc_info() test = proto_test(MagicMock()) err = proto_error(err) self.gtr.addFailure(test, err) self.gtr._reportOutcome.assert_called_with( test, 'F', self.gtr.colors.failing, err) 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) def test_addSkip(self): """ addSkip() makes the correct calls to other functions. """ test = proto_test(MagicMock()) reason = 'skip reason' self.gtr.addSkip(test, reason) self.gtr._reportOutcome.assert_called_with( test, 's', self.gtr.colors.skipped, reason=reason) 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) def test_addUnexpectedSuccess(self): """ addUnexpectedSuccess() makes the correct calls to other functions. """ test = proto_test(MagicMock()) self.gtr.addUnexpectedSuccess(test) self.gtr._reportOutcome.assert_called_with( test, 'u', self.gtr.colors.unexpectedSuccess) def test_wasSuccessful(self): """ wasSuccessful returns what we expect. """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) self.assertEqual(gtr.wasSuccessful(), False) gtr.passing.append('anything') self.assertEqual(gtr.wasSuccessful(), True) gtr.all_errors.append('anything') self.assertEqual(gtr.wasSuccessful(), False)
class TestGreenTestResultAdds(unittest.TestCase): def setUp(self): self.stream = StringIO() self.gtr = GreenTestResult(GreenStream(self.stream), None, 0) self.gtr._reportOutcome = MagicMock() def tearDown(self): del(self.stream) del(self.gtr) def test_addSuccess(self): "addSuccess() makes the correct calls to other functions." test = MagicMock() test.shortDescription.return_value = 'a' test.__str__.return_value = 'b' test = proto_test(test) self.gtr.addSuccess(test) self.gtr._reportOutcome.assert_called_with( test, '.', self.gtr.colors.passing) def test_addError(self): "addError() 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.addError(test, err) self.gtr._reportOutcome.assert_called_with( test, 'E', self.gtr.colors.error, err) def test_addFailure(self): "addFailure() makes the correct calls to other functions." err = None try: raise Exception except: err = sys.exc_info() test = proto_test(MagicMock()) err = proto_error(err) self.gtr.addFailure(test, err) self.gtr._reportOutcome.assert_called_with( test, 'F', self.gtr.colors.failing, err) def test_addSkip(self): "addSkip() makes the correct calls to other functions." test = proto_test(MagicMock()) reason = 'skip reason' self.gtr.addSkip(test, reason) self.gtr._reportOutcome.assert_called_with( test, 's', self.gtr.colors.skipped, reason=reason) 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) def test_addUnexpectedSuccess(self): "addUnexpectedSuccess() makes the correct calls to other functions." test = proto_test(MagicMock()) self.gtr.addUnexpectedSuccess(test) self.gtr._reportOutcome.assert_called_with( test, 'u', self.gtr.colors.unexpectedSuccess) def test_wasSuccessful(self): "wasSuccessful returns what we expect" gtr = GreenTestResult(GreenStream(self.stream), None, 1) self.assertEqual(gtr.wasSuccessful(), True) gtr.all_errors.append('anything') self.assertEqual(gtr.wasSuccessful(), False)
class TestGreenTestResultAdds(unittest.TestCase): def setUp(self): self.stream = StringIO() self.args = copy.deepcopy(default_args) self.args.verbose = 0 self.gtr = GreenTestResult(self.args, GreenStream(self.stream)) self.gtr._reportOutcome = MagicMock() def tearDown(self): del self.stream del self.gtr def test_addSuccess(self): """ addSuccess() makes the correct calls to other functions. """ test = MagicMock() test.shortDescription.return_value = "a" test.__str__.return_value = "b" test = proto_test(test) self.gtr.addSuccess(test) self.gtr._reportOutcome.assert_called_with(test, ".", self.gtr.colors.passing) def test_addSuccess_with_test_time(self): """ addSuccess() sets test time to correct value """ test = MagicMock() test.shortDescription.return_value = "a" test.__str__.return_value = "b" test = proto_test(test) self.gtr.addSuccess(test, "0.42") self.assertEqual(test.test_time, "0.42") def test_addError(self): """ addError() 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.addError(test, err) self.gtr._reportOutcome.assert_called_with(test, "E", self.gtr.colors.error, err) 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") def test_addFailure(self): """ addFailure() makes the correct calls to other functions. """ err = None try: raise Exception except: err = sys.exc_info() test = proto_test(MagicMock()) err = proto_error(err) self.gtr.addFailure(test, err) self.gtr._reportOutcome.assert_called_with(test, "F", self.gtr.colors.failing, err) def test_addFailure_with_test_time(self): """ addFailure() makes test time the correct value """ err = None try: raise Exception except: err = sys.exc_info() test = proto_test(MagicMock()) err = proto_error(err) self.gtr.addFailure(test, err, "0.42") self.assertEqual(test.test_time, "0.42") 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) def test_addSkip(self): """ addSkip() makes the correct calls to other functions. """ test = proto_test(MagicMock()) reason = "skip reason" self.gtr.addSkip(test, reason) self.gtr._reportOutcome.assert_called_with(test, "s", self.gtr.colors.skipped, reason=reason) def test_addSkip_with_test_time(self): """ addSkip() makes test time the correct value """ test = proto_test(MagicMock()) reason = "skip reason" self.gtr.addSkip(test, reason, "0.42") self.assertEqual(test.test_time, "0.42") 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) 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") def test_addUnexpectedSuccess(self): """ addUnexpectedSuccess() makes the correct calls to other functions. """ test = proto_test(MagicMock()) self.gtr.addUnexpectedSuccess(test) self.gtr._reportOutcome.assert_called_with( test, "u", self.gtr.colors.unexpectedSuccess) def test_addUnexpectedSuccess_with_test_time(self): """ addUnexpectedSuccess() makes test time with correct value """ test = proto_test(MagicMock()) self.gtr.addUnexpectedSuccess(test, "0.42") self.assertEqual(test.test_time, "0.42") def test_wasSuccessful(self): """ wasSuccessful returns what we expect. """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) self.assertEqual(gtr.wasSuccessful(), False) gtr.passing.append("anything") self.assertEqual(gtr.wasSuccessful(), True) gtr.all_errors.append("anything") self.assertEqual(gtr.wasSuccessful(), False) def test_wasSuccessful_expectedFailures(self): """ wasSuccessful returns what we expect when we only have expectedFailures """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.expectedFailures.append("anything") self.assertEqual(gtr.wasSuccessful(), True) def test_wasSuccessful_passing(self): """ wasSuccessful returns what we expect when we only have passing tests """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.passing.append("anything") self.assertEqual(gtr.wasSuccessful(), True) def test_wasSuccessful_skipped(self): """ wasSuccessful returns what we expect when we only have skipped tests """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.skipped.append("anything") self.assertEqual(gtr.wasSuccessful(), True) def test_wasSuccessful_unexpectedSuccesses(self): """ wasSuccessful returns what we expect when we only have unexpectedSuccesses """ self.args.verbose = 1 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.unexpectedSuccesses.append("anything") self.assertEqual(gtr.wasSuccessful(), True) def test_wasSuccessful_coverageFails(self): """ wasSuccessful fails if minimum coverage is not met """ self.args.minimum_coverage = 50 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.coverage_percent = 49 self.assertEqual(gtr.wasSuccessful(), False) def test_wasSuccessful_coverageSucceeds(self): """ wasSuccessful succeds if minimum coverage is met """ self.args.minimum_coverage = 50 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.passing.append("anything") gtr.coverage_percent = 60 self.assertEqual(gtr.wasSuccessful(), True)