File: apptest_exceptions.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (74 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pytest

def test_yield_in_nested_try_excepts():
    #Issue #25612
    class MainError(Exception):
        pass

    class SubError(Exception):
        pass

    def main():
        try:
            raise MainError()
        except MainError:
            try:
                yield
            except SubError:
                pass
            raise

    coro = main()
    coro.send(None)
    with pytest.raises(MainError):
        coro.throw(SubError())

def test_generator_doesnt_retain_old_exc2():
    # Issue bpo 28884#msg282532
    # Fixed in CPython via https://github.com/python/cpython/pull/1773
    import sys
    def g():
        try:
            raise ValueError
        except ValueError:
            yield 1
        assert sys.exc_info() == (None, None, None)
        yield 2

    gen = g()

    try:
        raise IndexError
    except IndexError:
        assert next(gen) == 1
    assert next(gen) == 2

def test_raise_in_generator():
    #Issue 25612#msg304117
    def g():
        yield 1
        raise
        yield 2

    with pytest.raises(ZeroDivisionError):
        i = g()
        try:
            1/0
        except:
            next(i)
            next(i)

def test_assertion_error_global_ignored():
    if hasattr(pytest, 'py3k_skip'):
        pytest.py3k_skip('only untranslated')
    global AssertionError

    class Foo(Exception):
        pass
    OrigAssertionError = AssertionError
    AssertionError = Foo
    try:
        with pytest.raises(OrigAssertionError): # not Foo!
            exec("assert 0") # to stop the pytest ast rewriting from touching it
    finally:
        AssertionError = OrigAssertionError