예제 #1
0
    def test_should_raise_exception_if_exception_argument_is_not_exception(
            self):
        # when
        with self.assertRaises(ValueError) as ctx:
            MainThreadActionResult(exception=list())

        # then
        self.assertEqual('Argument `exception` must be an exception.',
                         str(ctx.exception))
예제 #2
0
    def test_should_raise_exception_if_both_arguments_provided(self):
        # when
        with self.assertRaises(ValueError) as ctx:
            MainThreadActionResult(result=list(), exception=RuntimeError())

        # then
        self.assertEqual(
            'Either `result` or `exception` argument must be provided.',
            str(ctx.exception))
예제 #3
0
    def test_should_return_result_if_not_exception(self):
        # given
        action_result = MainThreadActionResult(result='success')

        # when
        result = action_result.result

        # then
        self.assertEqual('success', result)
예제 #4
0
    def test_should_reraise_exception(self):
        # given
        action_result = MainThreadActionResult(
            exception=Exception('action error'))

        # then
        with self.assertRaises(Exception) as ctx:
            _result = action_result.result
        self.assertEqual('action error', str(ctx.exception))
예제 #5
0
    def test_should_return_true_if_exception(self):
        # given
        action_result = MainThreadActionResult(exception=RuntimeError())

        # then
        self.assertTrue(action_result.is_exception)
예제 #6
0
    def test_should_return_false_if_not_exception(self):
        # given
        action_result = MainThreadActionResult(result=list())

        # then
        self.assertFalse(action_result.is_exception)