Пример #1
0
 def testCallingDoesNotImmediatelyExecuteFunction(self):
     try:
         calling(raise_exception)
     except AssertionError:
         self.fail()
     else:
         pass
Пример #2
0
 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))
Пример #3
0
 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),
     )
Пример #4
0
 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"),
     )
Пример #5
0
    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),
        )
Пример #6
0
 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"),
     )
Пример #7
0
 def testDoesNotMatchIfFunctionDoesNotRaiseException(self):
     self.assert_does_not_match("No exception", raises(ValueError),
                                calling(no_exception))
Пример #8
0
 def testMatchesIfFunctionRaisesASubclassOfTheExpectedBaseException(self):
     self.assert_matches("Subclassed BasedException", raises(BaseException),
                         calling(raise_baseException))
Пример #9
0
 def testMatchesIfFunctionRaisesTheExactExceptionExpected(self):
     self.assert_matches("Right exception", raises(AssertionError),
                         calling(raise_exception))
Пример #10
0
    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"})
Пример #11
0
    def testCallingWithFunctionReturnsObject(self):
        method = Callable()
        callable = calling(method)
        returned = callable.with_args(3, 1, 4, keyword1="arg1")

        self.assertEqual(returned, callable)
Пример #12
0
 def testCallingObjectCallsProvidedFunction(self):
     method = Callable()
     calling(method)()
     self.assertTrue(method.called)
Пример #13
0
def test_gives_correct_message_when_wrapped_with_is_not(expected_message):
    assert_mismatch_description(expected_message, not_(raises(AssertionError)),
                                calling(raise_exception))
Пример #14
0
 def testMachesIfRaisedExceptionMatchesAdditionalMatchers(self):
     self.assert_matches(
         "Properties",
         raises(AssertionError, matching=has_properties(prip="prop")),
         calling(raise_exception_with_properties).with_args(prip="prop"),
     )
Пример #15
0
 def testDoesNotMatchExceptionIfRegularExpressionDoesNotMatch(self):
     self.assert_does_not_match(
         "Bad regex", raises(AssertionError, "Phrase not found"), calling(raise_exception)
     )