当前位置: 首页>>代码示例>>Python>>正文


Python script_helper.assert_python_ok方法代码示例

本文整理汇总了Python中test.script_helper.assert_python_ok方法的典型用法代码示例。如果您正苦于以下问题:Python script_helper.assert_python_ok方法的具体用法?Python script_helper.assert_python_ok怎么用?Python script_helper.assert_python_ok使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在test.script_helper的用法示例。


在下文中一共展示了script_helper.assert_python_ok方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dummy_thread_after_fork

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_dummy_thread_after_fork(self):
        # Issue #14308: a dummy thread in the active list doesn't mess up
        # the after-fork mechanism.
        code = """if 1:
            import thread, threading, os, time

            def background_thread(evt):
                # Creates and registers the _DummyThread instance
                threading.current_thread()
                evt.set()
                time.sleep(10)

            evt = threading.Event()
            thread.start_new_thread(background_thread, (evt,))
            evt.wait()
            assert threading.active_count() == 2, threading.active_count()
            if os.fork() == 0:
                assert threading.active_count() == 1, threading.active_count()
                os._exit(0)
            else:
                os.wait()
        """
        _, out, err = assert_python_ok("-c", code)
        self.assertEqual(out, '')
        self.assertEqual(err, '') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_threading.py

示例2: test_print_exception

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_print_exception(self):
        script = r"""if 1:
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1.0/0.0
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            running = False
            t.join()
            """
        rc, out, err = assert_python_ok("-c", script)
        self.assertEqual(out, '')
        self.assertIn("Exception in thread", err)
        self.assertIn("Traceback (most recent call last):", err)
        self.assertIn("ZeroDivisionError", err)
        self.assertNotIn("Unhandled exception", err) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_threading.py

示例3: test_print_exception_stderr_is_none_2

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_print_exception_stderr_is_none_2(self):
        script = r"""if 1:
            import sys
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1.0/0.0
            sys.stderr = None
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            running = False
            t.join()
            """
        rc, out, err = assert_python_ok("-c", script)
        self.assertEqual(out, '')
        self.assertNotIn("Unhandled exception", err) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_threading.py

示例4: test_lll_multiple_dirs

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_lll_multiple_dirs(self):
        dir1 = tempfile.mkdtemp()
        dir2 = tempfile.mkdtemp()
        self.addCleanup(test_support.rmtree, dir1)
        self.addCleanup(test_support.rmtree, dir2)
        fn1 = os.path.join(dir1, 'foo1')
        fn2 = os.path.join(dir2, 'foo2')
        for fn, dir in (fn1, dir1), (fn2, dir2):
            open(fn, 'w').close()
            os.symlink(fn, os.path.join(dir, 'symlink'))

        rc, out, err = assert_python_ok(self.script, dir1, dir2)
        self.assertEqual(out,
            '{dir1}:\n'
            'symlink -> {fn1}\n'
            '\n'
            '{dir2}:\n'
            'symlink -> {fn2}\n'
            .format(dir1=dir1, fn1=fn1, dir2=dir2, fn2=fn2)
        ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_tools.py

示例5: test_print_exception

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_print_exception(self):
        script = r"""if 1:
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1/0
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            running = False
            t.join()
            """
        rc, out, err = assert_python_ok("-c", script)
        self.assertEqual(out, '')
        self.assertIn("Exception in thread", err)
        self.assertIn("Traceback (most recent call last):", err)
        self.assertIn("ZeroDivisionError", err)
        self.assertNotIn("Unhandled exception", err) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:27,代码来源:test_threading.py

示例6: test_print_exception_stderr_is_none_2

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_print_exception_stderr_is_none_2(self):
        script = r"""if 1:
            import sys
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1/0
            sys.stderr = None
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            running = False
            t.join()
            """
        rc, out, err = assert_python_ok("-c", script)
        self.assertEqual(out, '')
        self.assertNotIn("Unhandled exception", err) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:26,代码来源:test_threading.py

示例7: test_env_var_debug

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_env_var_debug(self):
        code = '\n'.join((
            'import asyncio',
            'loop = asyncio.get_event_loop()',
            'print(loop.get_debug())'))

        # Test with -E to not fail if the unit test was run with
        # PYTHONASYNCIODEBUG set to a non-empty string
        sts, stdout, stderr = assert_python_ok('-E', '-c', code)
        self.assertEqual(stdout.rstrip(), b'False')

        sts, stdout, stderr = assert_python_ok('-c', code,
                                               PYTHONASYNCIODEBUG='')
        self.assertEqual(stdout.rstrip(), b'False')

        sts, stdout, stderr = assert_python_ok('-c', code,
                                               PYTHONASYNCIODEBUG='1')
        self.assertEqual(stdout.rstrip(), b'True')

        sts, stdout, stderr = assert_python_ok('-E', '-c', code,
                                               PYTHONASYNCIODEBUG='1')
        self.assertEqual(stdout.rstrip(), b'False') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_base_events.py

示例8: _check_create_at_shutdown

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def _check_create_at_shutdown(self, **kwargs):
        # Issue #20037: creating a TextIOWrapper at shutdown
        # shouldn't crash the interpreter.
        iomod = self.io.__name__
        code = """if 1:
            import codecs
            import {iomod} as io

            # Avoid looking up codecs at shutdown
            codecs.lookup('utf-8')

            class C:
                def __init__(self):
                    self.buf = io.BytesIO()
                def __del__(self):
                    io.TextIOWrapper(self.buf, **{kwargs})
                    print("ok")
            c = C()
            """.format(iomod=iomod, kwargs=kwargs)
        return assert_python_ok("-c", code) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:22,代码来源:test_io.py

示例9: test_finalize_with_trace

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_finalize_with_trace(self):
        # Issue1733757
        # Avoid a deadlock when sys.settrace steps into threading._shutdown
        assert_python_ok("-c", """if 1:
            import sys, threading

            # A deadlock-killer, to prevent the
            # testsuite to hang forever
            def killer():
                import os, time
                time.sleep(2)
                print('program blocked; aborting')
                os._exit(2)
            t = threading.Thread(target=killer)
            t.daemon = True
            t.start()

            # This is the trace function
            def func(frame, event, arg):
                threading.current_thread()
                return func

            sys.settrace(func)
            """) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:26,代码来源:test_threading.py

示例10: test_join_nondaemon_on_shutdown

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_join_nondaemon_on_shutdown(self):
        # Issue 1722344
        # Raising SystemExit skipped threading._shutdown
        rc, out, err = assert_python_ok("-c", """if 1:
                import threading
                from time import sleep

                def child():
                    sleep(1)
                    # As a non-daemon thread we SHOULD wake up and nothing
                    # should be torn down yet
                    print("Woke up, sleep function is:", sleep)

                threading.Thread(target=child).start()
                raise SystemExit
            """)
        self.assertEqual(out.strip(),
            b"Woke up, sleep function is: <built-in function sleep>")
        self.assertEqual(err, b"") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:21,代码来源:test_threading.py

示例11: test_dummy_thread_after_fork

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_dummy_thread_after_fork(self):
        # Issue #14308: a dummy thread in the active list doesn't mess up
        # the after-fork mechanism.
        code = """if 1:
            import _thread, threading, os, time

            def background_thread(evt):
                # Creates and registers the _DummyThread instance
                threading.current_thread()
                evt.set()
                time.sleep(10)

            evt = threading.Event()
            _thread.start_new_thread(background_thread, (evt,))
            evt.wait()
            assert threading.active_count() == 2, threading.active_count()
            if os.fork() == 0:
                assert threading.active_count() == 1, threading.active_count()
                os._exit(0)
            else:
                os.wait()
        """
        _, out, err = assert_python_ok("-c", code)
        self.assertEqual(out, b'')
        self.assertEqual(err, b'') 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:27,代码来源:test_threading.py

示例12: test_main_thread_after_fork_from_nonmain_thread

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_main_thread_after_fork_from_nonmain_thread(self):
        code = """if 1:
            import os, threading, sys

            def f():
                pid = os.fork()
                if pid == 0:
                    main = threading.main_thread()
                    print(main.name)
                    print(main.ident == threading.current_thread().ident)
                    print(main.ident == threading.get_ident())
                    # stdout is fully buffered because not a tty,
                    # we have to flush before exit.
                    sys.stdout.flush()
                else:
                    os.waitpid(pid, 0)

            th = threading.Thread(target=f)
            th.start()
            th.join()
        """
        _, out, err = assert_python_ok("-c", code)
        data = out.decode().replace('\r', '')
        self.assertEqual(err, b"")
        self.assertEqual(data, "Thread-1\nTrue\nTrue\n") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:27,代码来源:test_threading.py

示例13: _run_and_join

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def _run_and_join(self, script):
        script = """if 1:
            import sys, os, time, threading

            # a thread, which waits for the main program to terminate
            def joiningfunc(mainthread):
                mainthread.join()
                print('end of thread')
                # stdout is fully buffered because not a tty, we have to flush
                # before exit.
                sys.stdout.flush()
        \n""" + script

        rc, out, err = assert_python_ok("-c", script)
        data = out.decode().replace('\r', '')
        self.assertEqual(data, "end of main\nend of thread\n") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:18,代码来源:test_threading.py

示例14: test_infile_stdout

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_infile_stdout(self):
        infile = self._create_infile()
        rc, out, err = assert_python_ok('-m', 'json.tool', infile)
        self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
        self.assertEqual(err, b'') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_tool.py

示例15: test_infile_outfile

# 需要导入模块: from test import script_helper [as 别名]
# 或者: from test.script_helper import assert_python_ok [as 别名]
def test_infile_outfile(self):
        infile = self._create_infile()
        outfile = test_support.TESTFN + '.out'
        rc, out, err = assert_python_ok('-m', 'json.tool', infile, outfile)
        self.addCleanup(os.remove, outfile)
        with open(outfile, "r") as fp:
            self.assertEqual(fp.read(), self.expect)
        self.assertEqual(out, b'')
        self.assertEqual(err, b'') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_tool.py


注:本文中的test.script_helper.assert_python_ok方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。