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(self):
     """
     addUnexpectedSuccess adds a test correctly
     """
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     ptr.addUnexpectedSuccess(test)
     self.assertEqual(test, ptr.unexpectedSuccesses[0])
 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(self):
     """
     addSkip adds a test and reason correctly
     """
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     reason = "some plausible reason"
     ptr.addSkip(test, reason)
     self.assertEqual(test, ptr.skipped[0][0])
     self.assertEqual(reason, ptr.skipped[0][1])
 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_newlineDocstring(self):
     """
     Docstrings starting with a newline are properly handled.
     """
     class MyTests(unittest.TestCase):
         def test_stuff(self):
             """
             tricky
             """
             pass
     test = proto_test(MyTests('test_stuff'))
     self.assertIn('tricky', test.getDescription(3))
 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_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])
    def test_multilineDocstring(self):
        """
        The description includes all of docstring until the first blank line.
        """
        class LongDocs(unittest.TestCase):
            def test_long(self):
                """First line is
                tricky!

                garbage
                """
                pass
        test = proto_test(LongDocs('test_long'))
        self.assertIn('tricky', test.getDescription(3))
        self.assertNotIn('garbage', test.getDescription(3))
Exemple #10
0
    def test_getDescription(self):
        """
        getDescription() returns what we expect for all verbose levels
        """
        # With a docstring
        class Fruit(unittest.TestCase):
            def test_stuff(self):
                'apple'
                pass
        t = proto_test(Fruit('test_stuff'))
        self.assertEqual(t.getDescription(1), '')
        self.assertEqual(t.getDescription(2), 'test_stuff')
        self.assertEqual(t.getDescription(3), 'apple')
        self.assertEqual(t.getDescription(4), 'apple')

        # Without a docstring
        class Vegetable(unittest.TestCase):
            def test_stuff(self):
                pass
        t = proto_test(Vegetable('test_stuff'))
        self.assertEqual(t.getDescription(1), '')
        self.assertEqual(t.getDescription(2), 'test_stuff')
        self.assertEqual(t.getDescription(3), 'test_stuff')
        self.assertEqual(t.getDescription(4), 'test_stuff')
Exemple #11
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)
Exemple #12
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])