Exemplo n.º 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, "")
Exemplo n.º 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:]
Exemplo n.º 3
0
def _():
    with raises(ValueError) as ctx:
        raise ValueError("xyz")
    assert "y" in str(ctx.raised)
Exemplo n.º 4
0
def _():
    err = ValueError("x")
    with raises(ValueError) as ctx:
        raise err
    assert ctx.raised is err
Exemplo n.º 5
0
def _():
    with raises(ValueError):
        raise ValueError
Exemplo n.º 6
0
def _():
    with raises(AssertionError):
        with raises(ValueError):
            raise RuntimeError
Exemplo n.º 7
0
def _():
    class SubClass(ValueError):
        pass

    with raises(ValueError):
        raise SubClass()
Exemplo n.º 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
Exemplo n.º 9
0
def _():
    with raises(ValueError):
        pass