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 testDoesNotMatchTypeErrorIfActualIsNotCallable(self): self.assert_does_not_match("Not callable", raises(TypeError), 23)
def testMatchesIfFunctionRaisesTheExactExceptionExpected(self): self.assert_matches("Right exception", raises(AssertionError), calling(raise_exception))
def test_gives_correct_message_when_wrapped_with_is_not(expected_message): assert_mismatch_description(expected_message, not_(raises(AssertionError)), calling(raise_exception))
def testDescribeMismatchWillCallItemIfNotTheOriginalMatch(self): function = Callable() matcher = raises(AssertionError) matcher.describe_mismatch(function, object()) self.assertTrue(function.called)
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) )