File: test_atexit.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (27 lines) | stat: -rw-r--r-- 819 bytes parent folder | download
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
class AppTestAtexit:

    def test_args(self):
        import atexit
        import io
        import sys
        stdout, stderr = sys.stdout, sys.stderr
        try:
            sys.stdout = sys.stderr = capture = io.StringIO()
            def h1():
                print("h1")
            def h2():
                print("h2")
            atexit.register(h1)
            atexit.register(h2)
            assert atexit._ncallbacks() == 2
            atexit._run_exitfuncs()
            assert atexit._ncallbacks() == 0
            assert capture.getvalue() == 'h2\nh1\n'
        finally:
            sys.stdout = stdout
            sys.stderr = stderr

    def test_badargs(self):
        import atexit
        atexit.register(lambda: 1, 0, 0, (x for x in (1,2)), 0, 0)
        raises(TypeError, atexit._run_exitfuncs)