def testCallingDoesNotImmediatelyExecuteFunction(self): try: calling(raise_exception) except AssertionError: self.fail() else: pass
def testDoesNotMatchIfTheWrongExceptionTypeIsRaisedPy37(self): self.assert_does_not_match("Wrong exception", raises(IOError), calling(raise_exception)) expected_message = ( "AssertionError('(){}') of type <class 'AssertionError'> was raised instead" ) self.assert_mismatch_description(expected_message, raises(TypeError), calling(raise_exception))
def testDoesNotMatchExceptionIfRegularExpressionDoesNotMatch(self): self.assert_does_not_match("Bad regex", raises(AssertionError, "Phrase not found"), calling(raise_exception)) self.assert_mismatch_description( '''Correct assertion type raised, but the expected pattern ("Phrase not found") not found. Exception message was: "(){}"''', raises(AssertionError, "Phrase not found"), calling(raise_exception), )
def testDoesNotMatchIfAdditionalMatchersDoesNotMatch(self): self.assert_does_not_match( "Bad properties", raises(AssertionError, matching=has_properties(prop="prip")), calling(raise_exception_with_properties).with_args(prip="prop"), ) self.assert_mismatch_description( '''Correct assertion type raised, but an object with a property 'prop' matching 'prip' not found. Exception message was: "boom"''', raises(AssertionError, matching=has_properties(prop="prip")), calling(raise_exception_with_properties).with_args(prip="prop"), )
def testMatchesRegularExpressionToStringifiedException(self): self.assert_matches( "Regex", raises(AssertionError, "(3, 1, 4)"), calling(raise_exception).with_args(3, 1, 4), ) self.assert_matches( "Regex", raises(AssertionError, r"([\d, ]+)"), calling(raise_exception).with_args(3, 1, 4), )
def testDoesNotMatchIfNeitherPatternOrMatcherMatch(self): self.assert_does_not_match( "Bad pattern and properties", raises(AssertionError, pattern="asdf", matching=has_properties(prop="prip")), calling(raise_exception_with_properties).with_args(prip="prop"), ) self.assert_mismatch_description( '''Correct assertion type raised, but the expected pattern ("asdf") and an object with a property 'prop' matching 'prip' not found. Exception message was: "boom"''', raises(AssertionError, pattern="asdf", matching=has_properties(prop="prip")), calling(raise_exception_with_properties).with_args(prip="prop"), )
def testDoesNotMatchIfFunctionDoesNotRaiseException(self): self.assert_does_not_match("No exception", raises(ValueError), calling(no_exception))
def testMatchesIfFunctionRaisesASubclassOfTheExpectedBaseException(self): self.assert_matches("Subclassed BasedException", raises(BaseException), calling(raise_baseException))
def testMatchesIfFunctionRaisesTheExactExceptionExpected(self): self.assert_matches("Right exception", raises(AssertionError), calling(raise_exception))
def testCallingWithFunctionSetsArgumentList(self): method = Callable() calling(method).with_args(3, 1, 4, keyword1="arg1")() self.assertEqual(method.args, (3, 1, 4)) self.assertEqual(method.kwargs, {"keyword1": "arg1"})
def testCallingWithFunctionReturnsObject(self): method = Callable() callable = calling(method) returned = callable.with_args(3, 1, 4, keyword1="arg1") self.assertEqual(returned, callable)
def testCallingObjectCallsProvidedFunction(self): method = Callable() calling(method)() self.assertTrue(method.called)
def test_gives_correct_message_when_wrapped_with_is_not(expected_message): assert_mismatch_description(expected_message, not_(raises(AssertionError)), calling(raise_exception))
def testMachesIfRaisedExceptionMatchesAdditionalMatchers(self): self.assert_matches( "Properties", raises(AssertionError, matching=has_properties(prip="prop")), calling(raise_exception_with_properties).with_args(prip="prop"), )
def testDoesNotMatchExceptionIfRegularExpressionDoesNotMatch(self): self.assert_does_not_match( "Bad regex", raises(AssertionError, "Phrase not found"), calling(raise_exception) )