Example #1
0
 def test_success(self):
     """
     A test run is still successful even if there are expected failures.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo('todo!'))
     self.assertEqual(True, self.result.wasSuccessful())
Example #2
0
 def test_success(self):
     """
     A test run is still successful even if there are expected failures.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo('todo!'))
     self.assertEqual(True, self.result.wasSuccessful())
Example #3
0
 def test_accumulation(self):
     """
     L{reporter.Reporter} accumulates the expected failures that it
     is notified of.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo('todo!'))
     self.assertEqual(self._getTodos(self.result), 1)
Example #4
0
 def test_booleanTodo(self):
     """
     Booleans CAN'T be used as the value of a todo. Maybe this sucks. This
     is a test for current behavior, not a requirement.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo(True))
     self.assertRaises(Exception, self.result.done)
Example #5
0
 def test_booleanTodo(self):
     """
     Booleans CAN'T be used as the value of a todo. Maybe this sucks. This
     is a test for current behavior, not a requirement.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo(True))
     self.assertRaises(Exception, self.result.done)
Example #6
0
 def test_accumulation(self):
     """
     L{reporter.Reporter} accumulates the expected failures that it
     is notified of.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo('todo!'))
     self.assertEqual(self._getTodos(self.result), 1)
Example #7
0
 def test_unexpectedSuccess(self):
     """
     A test which is marked as todo but succeeds will have an unexpected
     success reported to its result. A test run is still successful even
     when this happens.
     """
     self.result.addUnexpectedSuccess(self.test, makeTodo("Heya!"))
     self.assertEqual(True, self.result.wasSuccessful())
     self.assertEqual(self._getUnexpectedSuccesses(self.result), 1)
Example #8
0
 def test_unexpectedSuccess(self):
     """
     A test which is marked as todo but succeeds will have an unexpected
     success reported to its result. A test run is still successful even
     when this happens.
     """
     self.result.addUnexpectedSuccess(self.test, makeTodo("Heya!"))
     self.assertEqual(True, self.result.wasSuccessful())
     self.assertEqual(self._getUnexpectedSuccesses(self.result), 1)
Example #9
0
 def test_basicErrors(self):
     """
     The reporter's L{printErrors} method should include the value of the
     Todo.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo('some reason'))
     self.result.done()
     output = self.stream.getvalue().splitlines()[4].strip()
     self.assertEqual(output, "Reason: 'some reason'")
Example #10
0
 def test_basicErrors(self):
     """
     The reporter's L{printErrors} method should include the value of the
     Todo.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo('some reason'))
     self.result.done()
     output = self.stream.getvalue().splitlines()[4].strip()
     self.assertEqual(output, "Reason: 'some reason'")
Example #11
0
 def test_summary(self):
     """
     The reporter's C{printSummary} method should print the number of
     expected failures that occured.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo('some reason'))
     self.result.done()
     output = self.stream.getvalue().splitlines()[-1]
     prefix = 'PASSED '
     self.failUnless(output.startswith(prefix))
     self.assertEqual(output[len(prefix):].strip(), '(expectedFailures=1)')
Example #12
0
 def test_summary(self):
     """
     The reporter's C{printSummary} method should print the number of
     expected failures that occured.
     """
     self.result.addExpectedFailure(self.test, Failure(Exception()),
                                    makeTodo('some reason'))
     self.result.done()
     output = self.stream.getvalue().splitlines()[-1]
     prefix = 'PASSED '
     self.failUnless(output.startswith(prefix))
     self.assertEqual(output[len(prefix):].strip(),
                      '(expectedFailures=1)')
Example #13
0
def _makeTodo(value):
    """
    Return a L{Todo} object built from C{value}.

    This is a synonym for L{twisted.trial.unittest.makeTodo}, but imported
    locally to avoid circular imports.

    @param value: A string or a tuple of C{(errors, reason)}, where C{errors}
    is either a single exception class or an iterable of exception classes.

    @return: A L{Todo} object.
    """
    from twisted.trial.unittest import makeTodo
    return makeTodo(value)
Example #14
0
    def addUnexpectedSuccess(self, test, todo=None):
        """
        Report that the given test succeeded against expectations.

        In Trial, tests can be marked 'todo'. That is, they are expected to
        fail.  When a test that is expected to fail instead succeeds, it should
        call this method to report the unexpected success.

        @type test: L{pyunit.TestCase}
        @type todo: L{unittest.Todo}, or L{None}, in which case a default todo
            message is provided.
        """
        if todo is None:
            todo = makeTodo(self._DEFAULT_TODO)
        self.unexpectedSuccesses.append((test, todo))
Example #15
0
    def addExpectedFailure(self, test, error, todo=None):
        """
        Report that the given test failed, and was expected to do so.

        In Trial, tests can be marked 'todo'. That is, they are expected to
        fail.

        @type test: L{pyunit.TestCase}
        @type error: L{Failure}
        @type todo: L{unittest.Todo}, or L{None}, in which case a default todo
            message is provided.
        """
        if todo is None:
            todo = makeTodo(self._DEFAULT_TODO)
        self.expectedFailures.append((test, error, todo))
Example #16
0
    def addExpectedFailure(self, test, error, todo=None):
        """
        Report that the given test failed, and was expected to do so.

        In Trial, tests can be marked 'todo'. That is, they are expected to
        fail.

        @type test: L{pyunit.TestCase}
        @type error: L{Failure}
        @type todo: L{unittest.Todo}, or L{None}, in which case a default todo
            message is provided.
        """
        if todo is None:
            todo = makeTodo(self._DEFAULT_TODO)
        self.expectedFailures.append((test, error, todo))
Example #17
0
    def addUnexpectedSuccess(self, test, todo=None):
        """
        Report that the given test succeeded against expectations.

        In Trial, tests can be marked 'todo'. That is, they are expected to
        fail.  When a test that is expected to fail instead succeeds, it should
        call this method to report the unexpected success.

        @type test: L{pyunit.TestCase}
        @type todo: L{unittest.Todo}, or L{None}, in which case a default todo
            message is provided.
        """
        if todo is None:
            todo = makeTodo(self._DEFAULT_TODO)
        self.unexpectedSuccesses.append((test, todo))
Example #18
0
 def _ebDeferTestMethod(self, f, result):
     if f.check(TodoTest):
         result.addExpectedFailure(self, f, unittest.makeTodo(f.getErrorMessage()))
     else:
         return unittest.TestCase._ebDeferTestMethod(self, f, result)
Example #19
0
 def _ebDeferTestMethod(self, f, result):
     if f.check(TodoTest):
         result.addExpectedFailure(self, f,
                                   unittest.makeTodo(f.getErrorMessage()))
     else:
         return unittest.TestCase._ebDeferTestMethod(self, f, result)
Example #20
0
class TodoTest(unittest.TestCase):
    """
    Tests for L{reporter.Reporter}'s handling of todos.
    """
    def setUp(self):
        from twisted.trial.test import sample
        self.stream = StringIO.StringIO()
        self.result = reporter.Reporter(self.stream)
        self.test = sample.FooTest('test_foo')

    def _getTodos(self, result):
        """
        Get the number of todos that happened to a reporter.
        """
        return len(result.expectedFailures)

    def _getUnexpectedSuccesses(self, result):
        """
        Get the number of unexpected successes that happened to a reporter.
        """
        return len(result.unexpectedSuccesses)

    def test_accumulation(self):
        """
        L{reporter.Reporter} accumulates the expected failures that it
        is notified of.
        """
        self.result.addExpectedFailure(self.test, Failure(Exception()),
                                       makeTodo('todo!'))
        self.assertEqual(self._getTodos(self.result), 1)

    def test_success(self):
        """
        A test run is still successful even if there are expected failures.
        """
        self.result.addExpectedFailure(self.test, Failure(Exception()),
                                       makeTodo('todo!'))
        self.assertEqual(True, self.result.wasSuccessful())

    def test_unexpectedSuccess(self):
        """
        A test which is marked as todo but succeeds will have an unexpected
        success reported to its result. A test run is still successful even
        when this happens.
        """
        self.result.addUnexpectedSuccess(self.test, makeTodo("Heya!"))
        self.assertEqual(True, self.result.wasSuccessful())
        self.assertEqual(self._getUnexpectedSuccesses(self.result), 1)

    def test_summary(self):
        """
        The reporter's C{printSummary} method should print the number of
        expected failures that occured.
        """
        self.result.addExpectedFailure(self.test, Failure(Exception()),
                                       makeTodo('some reason'))
        self.result.done()
        output = self.stream.getvalue().splitlines()[-1]
        prefix = 'PASSED '
        self.failUnless(output.startswith(prefix))
        self.assertEqual(output[len(prefix):].strip(), '(expectedFailures=1)')

    def test_basicErrors(self):
        """
        The reporter's L{printErrors} method should include the value of the
        Todo.
        """
        self.result.addExpectedFailure(self.test, Failure(Exception()),
                                       makeTodo('some reason'))
        self.result.done()
        output = self.stream.getvalue().splitlines()[4].strip()
        self.assertEqual(output, "Reason: 'some reason'")

    def test_booleanTodo(self):
        """
        Booleans CAN'T be used as the value of a todo. Maybe this sucks. This
        is a test for current behavior, not a requirement.
        """
        self.result.addExpectedFailure(self.test, Failure(Exception()),
                                       makeTodo(True))
        self.assertRaises(Exception, self.result.done)

    def test_exceptionTodo(self):
        """
        The exception for expected failures should be shown in the
        C{printErrors} output.
        """
        try:
            1 / 0
        except Exception, e:
            error = e
        self.result.addExpectedFailure(self.test, Failure(error),
                                       makeTodo("todo!"))
        self.result.done()
        output = '\n'.join(self.stream.getvalue().splitlines()[3:]).strip()
        self.assertTrue(str(e) in output)