def mismatches_when_unexpected_exception_is_raised():
    def raise_key_error():
        raise KeyError()

    matcher = raises(is_instance(ValueError))
    result = matcher.match(raise_key_error)
    assert not result.is_match
    assert _normalise_newlines(result.explanation).startswith(
        "exception did not match: had type KeyError\n\nTraceback (most recent call last):\n",
    )
示例#2
0
def mismatches_when_unexpected_exception_is_raised():
    def raise_key_error():
        raise KeyError()

    matcher = raises(is_instance(ValueError))
    result = matcher.match(raise_key_error)
    assert not result.is_match
    assert _normalise_newlines(result.explanation).startswith(
        "exception did not match: had type KeyError\n\nTraceback (most recent call last):\n",
    )
示例#3
0
def matches_when_expected_exception_is_raised():
    def raise_key_error():
        raise KeyError()

    matcher = raises(is_instance(KeyError))
    assert_equal(matched(), matcher.match(raise_key_error))
示例#4
0
def description_includes_description_of_exception():
    matcher = raises(is_instance(ValueError))
    assert_equal("a callable raising: is instance of ValueError",
                 matcher.describe())
示例#5
0
def mismatches_when_value_is_not_callable():
    matcher = raises(is_instance(ValueError))
    assert_equal(unmatched("was not callable"), matcher.match(42))
示例#6
0
def mismatches_when_no_exception_is_raised():
    matcher = raises(is_instance(KeyError))
    assert_equal(unmatched("did not raise exception"),
                 matcher.match(lambda: None))
def matches_when_expected_exception_is_raised():
    def raise_key_error():
        raise KeyError()

    matcher = raises(is_instance(KeyError))
    assert_equal(matched(), matcher.match(raise_key_error))
def description_includes_description_of_exception():
    matcher = raises(is_instance(ValueError))
    assert_equal("a callable raising: is instance of ValueError", matcher.describe())
def mismatches_when_value_is_not_callable():
    matcher = raises(is_instance(ValueError))
    assert_equal(unmatched("was not callable"), matcher.match(42))
示例#10
0
def mismatches_when_no_exception_is_raised():
    matcher = raises(is_instance(KeyError))
    assert_equal(unmatched("did not raise exception"), matcher.match(lambda: None))