Beispiel #1
0
def _(
    func=each(
        assert_equal,
        assert_not_equal,
        assert_in,
        assert_not_in,
        assert_less_than,
        assert_less_than_equal_to,
        assert_greater_than,
        assert_greater_than_equal_to,
    ),
    lhs=each(1, 1, "a", "a", 2, 2, 1, 1),
    rhs=each(2, 1, "b", "a", 1, 1, 2, 2),
):
    with raises(TestFailure):
        func(lhs, rhs, "")
Beispiel #2
0
def _():
    import traceback

    def raising():
        raise ValueError

    def dangerous():
        raising()

    try:
        dangerous()
    except ValueError as err:
        try_tb = traceback.extract_tb(err.__traceback__)

    with raises(ValueError) as ctx:
        dangerous()
    raises_tb = traceback.extract_tb(ctx.raised.__traceback__)

    assert try_tb[1:] == raises_tb[1:]
Beispiel #3
0
def _():
    with raises(ValueError) as ctx:
        raise ValueError("xyz")
    assert "y" in str(ctx.raised)
Beispiel #4
0
def _():
    err = ValueError("x")
    with raises(ValueError) as ctx:
        raise err
    assert ctx.raised is err
Beispiel #5
0
def _():
    with raises(ValueError):
        raise ValueError
Beispiel #6
0
def _():
    with raises(AssertionError):
        with raises(ValueError):
            raise RuntimeError
Beispiel #7
0
def _():
    class SubClass(ValueError):
        pass

    with raises(ValueError):
        raise SubClass()
Beispiel #8
0
def _():
    assert_lineno = inspect.currentframe().f_lineno + 2
    with raises(TestFailure) as ctx:
        assert_equal(0, 1, "msg")
    assert ctx.raised.error_line == assert_lineno
Beispiel #9
0
def _():
    with raises(ValueError):
        pass