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))
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))
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)
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))
def test_should_return_true_if_exception(self): # given action_result = MainThreadActionResult(exception=RuntimeError()) # then self.assertTrue(action_result.is_exception)
def test_should_return_false_if_not_exception(self): # given action_result = MainThreadActionResult(result=list()) # then self.assertFalse(action_result.is_exception)