Python sys.exitfunc() Examples

The following are code examples for showing how to use sys.exitfunc(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: pyblish-win   Author: pyblish   File: test_fixers.py    GNU Lesser General Public License v3.0 7 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 2
Project: NiujiaoDebugger   Author: MrSrc   File: test_fixers.py    GNU General Public License v3.0 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 3
Project: ironpython2   Author: IronLanguages   File: test_fixers.py    Apache License 2.0 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 4
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_fixers.py    GNU General Public License v3.0 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 5
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_fixers.py    GNU General Public License v2.0 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 6
Project: aws-lambda-runtime-pypy   Author: uscheller   File: test_fixers.py    Apache License 2.0 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 7
Project: Computable   Author: ktraunmueller   File: test_fixers.py    MIT License 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 8
Project: oss-ftp   Author: aliyun   File: test_fixers.py    MIT License 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 9
Project: setup   Author: mindbender-studio   File: test_fixers.py    MIT License 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 10
Project: django-drf-filepond   Author: ImperialCollegeLondon   File: runner.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def start(argv=None):
    sys.exitfunc = lambda: sys.stderr.write("Shutting down...\n")

    if argv is None:
        argv = [
            "nosetests", "--cover-branches", "--with-coverage",
            "--cover-erase", "--verbose",
            "--cover-package=django_drf_filepond",
        ]
#        argv = [
#            "nosetests", "--cover-branches", "--verbose",
#            "--cover-package=django_drf_filepond",
#        ]

    nose.run_exit(argv=argv,
                  defaultTest=os.path.abspath(os.path.dirname(__file__))) 
Example 11
Project: Hot   Author: dsolimando   File: test_atexit.py    GNU General Public License v3.0 6 votes vote down vote up
def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        s = StringIO.StringIO()
        sys.stdout = sys.stderr = s
        save_handlers = atexit._exithandlers
        atexit._exithandlers = []
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.stdout = sys.__stdout__
            sys.stderr = sys.__stderr__
            atexit._exithandlers = save_handlers
            sys.exitfunc = exfunc
        self.assertEqual(s.getvalue(), "h2\nh1\n") 
Example 12
Project: uv-align-distribute   Author: c30ra   File: test_fixers.py    GNU General Public License v3.0 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 13
Project: docker   Author: getavalon   File: test_fixers.py    MIT License 6 votes vote down vote up
def test_comments(self):
        b = """
            import sys # Foo
            sys.exitfunc = f # Blah
            """
        a = """
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            """
        self.check(b, a)

        b = """
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            """
        a = """
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            """
        self.check(b, a) 
Example 14
Project: pyblish-win   Author: pyblish   File: test_fixers.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 15
Project: pyblish-win   Author: pyblish   File: test_fixers.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 16
Project: pyblish-win   Author: pyblish   File: test_fixers.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 17
Project: pyblish-win   Author: pyblish   File: test_fixers.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 18
Project: pyblish-win   Author: pyblish   File: test_fixers.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 19
Project: pyblish-win   Author: pyblish   File: test_atexit.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n") 
Example 20
Project: pyblish-win   Author: pyblish   File: run.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    capture_warnings(False)
    sys.exit(0) 
Example 21
Project: mealpy   Author: edmundmok   File: venv_update.py    MIT License 5 votes vote down vote up
def exec_(argv):  # never returns
    """Wrapper to os.execv which shows the command and runs any atexit handlers (for coverage's sake).
    Like os.execv, this function never returns.
    """
    # info('EXEC' + colorize(argv))  # TODO: debug logging by environment variable

    # in python3, sys.exitfunc has gone away, and atexit._run_exitfuncs seems to be the only pubic-ish interface
    #   https://hg.python.org/cpython/file/3.4/Modules/atexitmodule.c#l289
    import atexit
    atexit._run_exitfuncs()

    from os import execv
    execv(argv[0], argv) 
Example 22
Project: NiujiaoDebugger   Author: MrSrc   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 23
Project: NiujiaoDebugger   Author: MrSrc   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 24
Project: NiujiaoDebugger   Author: MrSrc   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 25
Project: NiujiaoDebugger   Author: MrSrc   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 26
Project: NiujiaoDebugger   Author: MrSrc   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 27
Project: ironpython2   Author: IronLanguages   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 28
Project: ironpython2   Author: IronLanguages   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 29
Project: ironpython2   Author: IronLanguages   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 30
Project: ironpython2   Author: IronLanguages   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 31
Project: ironpython2   Author: IronLanguages   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 32
Project: ironpython2   Author: IronLanguages   File: test_atexit.py    Apache License 2.0 5 votes vote down vote up
def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n") 
Example 33
Project: ironpython2   Author: IronLanguages   File: test_thread.py    Apache License 2.0 5 votes vote down vote up
def test_threading_waits_for_thread_exit(self):
        import os
        f = file('temp.py', 'w+')
        try:
            f.write("""
import sys
def f():
    print 'bye bye'

def f(*args):
    print 'bye bye'

sys.exitfunc = f
from threading import Thread
def count(n):
    while n > 0:
            n -= 1
    print 'done'

t1 = Thread(target=count, args=(50000000,))
t1.start()
    """)
            f.close()
            stdin, stdout = os.popen2(sys.executable +  ' temp.py')
            self.assertTrue('bye bye\n' in list(stdout))
        finally:
            os.unlink('temp.py') 
Example 34
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 35
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 36
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 37
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 38
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 39
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_fixers.py    GNU General Public License v2.0 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 40
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_fixers.py    GNU General Public License v2.0 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 41
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_fixers.py    GNU General Public License v2.0 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 42
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_fixers.py    GNU General Public License v2.0 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 43
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_fixers.py    GNU General Public License v2.0 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 44
Project: aws-lambda-runtime-pypy   Author: uscheller   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 45
Project: aws-lambda-runtime-pypy   Author: uscheller   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 46
Project: aws-lambda-runtime-pypy   Author: uscheller   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 47
Project: aws-lambda-runtime-pypy   Author: uscheller   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 48
Project: aws-lambda-runtime-pypy   Author: uscheller   File: test_fixers.py    Apache License 2.0 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 49
Project: Computable   Author: ktraunmueller   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 50
Project: Computable   Author: ktraunmueller   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 51
Project: Computable   Author: ktraunmueller   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 52
Project: Computable   Author: ktraunmueller   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 53
Project: Computable   Author: ktraunmueller   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 54
Project: oss-ftp   Author: aliyun   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 55
Project: oss-ftp   Author: aliyun   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 56
Project: oss-ftp   Author: aliyun   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 57
Project: oss-ftp   Author: aliyun   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 58
Project: oss-ftp   Author: aliyun   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 59
Project: oss-ftp   Author: aliyun   File: test_atexit.py    MIT License 5 votes vote down vote up
def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n") 
Example 60
Project: oss-ftp   Author: aliyun   File: run.py    MIT License 5 votes vote down vote up
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    capture_warnings(False)
    sys.exit(0) 
Example 61
Project: REST_ARCH   Author: MrKiven   File: shell.py    MIT License 5 votes vote down vote up
def shell(host, port, rpc, profile):
    """
    # run a client in ipython
    """
    user_ns = __main__.__dict__
    c = Client(host, port)

    def embed_with_cli(client):
        import IPython
        del sys.exitfunc
        user_ns.update(dict(c=client))
        IPython.embed(user_ns=user_ns)
    embed_with_cli(c) 
Example 62
Project: setup   Author: mindbender-studio   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 63
Project: setup   Author: mindbender-studio   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 64
Project: setup   Author: mindbender-studio   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 65
Project: setup   Author: mindbender-studio   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 66
Project: setup   Author: mindbender-studio   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 67
Project: bib   Author: fuzz-productions   File: runtests.py    MIT License 5 votes vote down vote up
def start(argv=None):
    sys.exitfunc = lambda: sys.stderr.write("Shutting down...\n")

    if argv is None:
        argv = [
            "nosetests", "--cover-branches", "--with-coverage",
            "--cover-erase", "--verbose",
            "--cover-package=bib",
        ]

    nose.run_exit(argv=argv, defaultTest=os.path.abspath(os.path.dirname(__file__))) 
Example 68
Project: uv-align-distribute   Author: c30ra   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 69
Project: uv-align-distribute   Author: c30ra   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 70
Project: uv-align-distribute   Author: c30ra   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 71
Project: uv-align-distribute   Author: c30ra   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 72
Project: uv-align-distribute   Author: c30ra   File: test_fixers.py    GNU General Public License v3.0 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 73
Project: kkFileView   Author: kekingcn   File: run.py    Apache License 2.0 5 votes vote down vote up
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    capture_warnings(False)
    sys.exit(0) 
Example 74
Project: docker   Author: getavalon   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_simple(self):
        b = """
            import sys
            sys.exitfunc = my_atexit
            """
        a = """
            import sys
            import atexit
            atexit.register(my_atexit)
            """
        self.check(b, a) 
Example 75
Project: docker   Author: getavalon   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_names_import(self):
        b = """
            import sys, crumbs
            sys.exitfunc = my_func
            """
        a = """
            import sys, crumbs, atexit
            atexit.register(my_func)
            """
        self.check(b, a) 
Example 76
Project: docker   Author: getavalon   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_complex_expression(self):
        b = """
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            """
        a = """
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            """
        self.check(b, a) 
Example 77
Project: docker   Author: getavalon   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_in_a_function(self):
        b = """
            import sys
            def f():
                sys.exitfunc = func
            """
        a = """
            import sys
            import atexit
            def f():
                atexit.register(func)
             """
        self.check(b, a) 
Example 78
Project: docker   Author: getavalon   File: test_fixers.py    MIT License 5 votes vote down vote up
def test_unchanged(self):
        s = """f(sys.exitfunc)"""
        self.unchanged(s) 
Example 79
Project: Splunking-Crime   Author: nccgroup   File: run.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    capture_warnings(False)
    sys.exit(0) 
Example 80
Project: ironpython2   Author: IronLanguages   File: test_interactive.py    Apache License 2.0 4 votes vote down vote up
def test_sys_exitfunc():
    import clr
        
    inputScript = testpath.test_inputs_dir + "\\exitFuncRuns.py"
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs + " \"" + inputScript + "\"")
    (result, output, output2, exitCode) = ipi.StartAndRunToCompletion()
    AreEqual(exitCode, 0)
    AreEqual(output.find('hello world') > -1, True)
    ipi.End()
    
    args = extraArgs
    
    if clr.GetCurrentRuntime().Configuration.DebugMode:
        args = "-D " + args

    inputScript = testpath.test_inputs_dir + "\\exitFuncRaises.py"
    ipi = IronPythonInstance(executable, exec_prefix, args + " \"" + inputScript + "\"")
    (result, output, output2, exitCode) = ipi.StartAndRunToCompletion()
    AreEqual(exitCode, 0)
    AreEqual(output2.find('Error in sys.exitfunc:') > -1, True)
    
    AreEqual(output2.find('exitFuncRaises.py", line 19, in foo') > -1, True)
        
    ipi.End()
    
    # verify sys.exit(True) and sys.exit(False) return 1 and 0
    
    ipi = IronPythonInstance(executable, exec_prefix, '-c "import sys; sys.exit(False)"')
    res = ipi.StartAndRunToCompletion()
    AreEqual(res[0], True)  # should have started
    AreEqual(res[1], '')    # no std out
    AreEqual(res[2], '')    # no std err
    AreEqual(res[3], 0)     # should return 0

    ipi = IronPythonInstance(executable, exec_prefix, '-c "import sys; sys.exit(True)"')
    res = ipi.StartAndRunToCompletion()
    AreEqual(res[0], True)  # should have started
    AreEqual(res[1], '')    # no std out
    AreEqual(res[2], '')    # no std err
    AreEqual(res[3], 1)     # should return 0
    
    # and verify it works at the interactive console as well
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    
    # parameterless exception
    ipi.ExecuteLine("import sys")
    AreEqual(ipi.ExecuteAndExit("sys.exit(False)"), 0)

    # and verify it works at the interactive console as well
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    
    # parameterless exception
    ipi.ExecuteLine("import sys")
    AreEqual(ipi.ExecuteAndExit("sys.exit(True)"), 1)


#############################################################################
# verify we need to dedent to a previous valid indentation level