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


Python script_helper.assert_python_failure函数代码示例

本文整理汇总了Python中test.support.script_helper.assert_python_failure函数的典型用法代码示例。如果您正苦于以下问题:Python assert_python_failure函数的具体用法?Python assert_python_failure怎么用?Python assert_python_failure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_assert_python_failure_raises

 def test_assert_python_failure_raises(self):
     with self.assertRaises(AssertionError) as error_context:
         script_helper.assert_python_failure('-c', 'import sys; sys.exit(0)')
     error_msg = str(error_context.exception)
     self.assertIn('Process return code is 0\n', error_msg)
     self.assertIn('import sys; sys.exit(0)', error_msg,
                   msg='unexpected command line.')
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:7,代码来源:test_script_helper.py

示例2: test_run_code

 def test_run_code(self):
     # Test expected operation of the '-c' switch
     # Switch needs an argument
     assert_python_failure('-c')
     # Check we get an error for an uncaught exception
     assert_python_failure('-c', 'raise Exception')
     # All good if execution is successful
     assert_python_ok('-c', 'pass')
开发者ID:cherish3620,项目名称:cpython,代码行数:8,代码来源:test_cmd_line.py

示例3: test_crashers_crash

 def test_crashers_crash(self):
     for fname in glob.glob(CRASHER_FILES):
         if os.path.basename(fname) in infinite_loops:
             continue
         # Some "crashers" only trigger an exception rather than a
         # segfault. Consider that an acceptable outcome.
         if test.support.verbose:
             print("Checking crasher:", fname)
         assert_python_failure(fname)
开发者ID:10sr,项目名称:cpython,代码行数:9,代码来源:test_crashers.py

示例4: test_bad_traverse

 def test_bad_traverse(self):
     ''' Issue #32374: Test that traverse fails when accessing per-module
         state before Py_mod_exec was executed.
         (Multiphase initialization modules only)
     '''
     script = """if True:
             import importlib.util as util
             spec = util.find_spec('_testmultiphase')
             spec.name = '_testmultiphase_with_bad_traverse'
             m = spec.loader.create_module(spec)"""
     assert_python_failure("-c", script)
开发者ID:andportnoy,项目名称:cpython,代码行数:11,代码来源:test_loader.py

示例5: test_run_profile_as_module

    def test_run_profile_as_module(self):
        # Test that -m switch needs an argument
        assert_python_failure('-m', self.profilermodule.__name__, '-m')

        # Test failure for not-existent module
        assert_python_failure('-m', self.profilermodule.__name__,
                              '-m', 'random_module_xyz')

        # Test successful run
        assert_python_ok('-m', self.profilermodule.__name__,
                         '-m', 'timeit', '-n', '1')
开发者ID:Eyepea,项目名称:cpython,代码行数:11,代码来源:test_profile.py

示例6: test_module_path_option

    def test_module_path_option(self):
        # Test -m switch with modules

        # Test that -m switch needs an argument
        assert_python_failure('-m', 'cProfile', '-m')

        # Test failure for not-existent module
        assert_python_failure('-m', 'cProfile', '-m', 'random_module_xyz')

        # Test successful run
        assert_python_ok('-m', 'cProfile', '-m', 'timeit', '-n', '1')
开发者ID:1st1,项目名称:cpython,代码行数:11,代码来源:test_cprofile.py

示例7: test_return_null_without_error

    def test_return_null_without_error(self):
        # Issue #23571: A function must not return NULL without setting an
        # error
        if Py_DEBUG:
            code = textwrap.dedent("""
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            """)
            rc, out, err = assert_python_failure('-c', code)
            self.assertRegex(err.replace(b'\r', b''),
                             br'Fatal Python error: a function returned NULL '
                                br'without setting an error\n'
                             br'SystemError: <built-in function '
                                 br'return_null_without_error> returned NULL '
                                 br'without setting an error\n'
                             br'\n'
                             br'Current thread.*:\n'
                             br'  File .*", line 6 in <module>')
        else:
            with self.assertRaises(SystemError) as cm:
                _testcapi.return_null_without_error()
            self.assertRegex(str(cm.exception),
                             'return_null_without_error.* '
                             'returned NULL without setting an error')
开发者ID:lupulin,项目名称:cpython,代码行数:27,代码来源:test_capi.py

示例8: test_finalize_runnning_thread

    def test_finalize_runnning_thread(self):
        # Issue 1402: the PyGILState_Ensure / _Release functions may be called
        # very late on python exit: on deallocation of a running thread for
        # example.
        import_module("ctypes")

        rc, out, err = assert_python_failure("-c", """if 1:
            import ctypes, sys, time, _thread

            # This lock is used as a simple event variable.
            ready = _thread.allocate_lock()
            ready.acquire()

            # Module globals are cleared before __del__ is run
            # So we save the functions in class dict
            class C:
                ensure = ctypes.pythonapi.PyGILState_Ensure
                release = ctypes.pythonapi.PyGILState_Release
                def __del__(self):
                    state = self.ensure()
                    self.release(state)

            def waitingThread():
                x = C()
                ready.release()
                time.sleep(100)

            _thread.start_new_thread(waitingThread, ())
            ready.acquire()  # Be sure the other thread is waiting.
            sys.exit(42)
            """)
        self.assertEqual(rc, 42)
开发者ID:cpcloud,项目名称:cpython,代码行数:32,代码来源:test_threading.py

示例9: test_trigger_memory_error

 def test_trigger_memory_error(self):
     e = self._nested_expression(100)
     rc, out, err = assert_python_failure('-c', e)
     # parsing the expression will result in an error message
     # followed by a MemoryError (see #11963)
     self.assertIn(b's_push: parser stack overflow', err)
     self.assertIn(b'MemoryError', err)
开发者ID:M31MOTH,项目名称:cpython,代码行数:7,代码来源:test_parser.py

示例10: test_return_result_with_error

    def test_return_result_with_error(self):
        # Issue #23571: A function must not return a result with an error set
        if Py_DEBUG:
            code = textwrap.dedent("""
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            """)
            rc, out, err = assert_python_failure('-c', code)
            self.assertRegex(err.replace(b'\r', b''),
                             br'Fatal Python error: a function returned a '
                                br'result with an error set\n'
                             br'ValueError\n'
                             br'\n'
                             br'During handling of the above exception, '
                                br'another exception occurred:\n'
                             br'\n'
                             br'SystemError: <built-in '
                                br'function return_result_with_error> '
                                br'returned a result with an error set\n'
                             br'\n'
                             br'Current thread.*:\n'
                             br'  File .*, line 6 in <module>')
        else:
            with self.assertRaises(SystemError) as cm:
                _testcapi.return_result_with_error()
            self.assertRegex(str(cm.exception),
                             'return_result_with_error.* '
                             'returned a result with an error set')
开发者ID:lupulin,项目名称:cpython,代码行数:31,代码来源:test_capi.py

示例11: test_return_result_with_error

    def test_return_result_with_error(self):
        # Issue #23571: A function must not return a result with an error set
        if Py_DEBUG:
            code = textwrap.dedent(
                """
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            """
            )
            rc, out, err = assert_python_failure("-c", code)
            self.assertRegex(
                err.replace(b"\r", b""),
                br"Fatal Python error: a function returned a "
                br"result with an error set\n"
                br"ValueError\n"
                br"\n"
                br"During handling of the above exception, "
                br"another exception occurred:\n"
                br"\n"
                br"SystemError: <built-in "
                br"function return_result_with_error> "
                br"returned a result with an error set\n"
                br"\n"
                br"Current thread.*:\n"
                br"  File .*, line 6 in <module>",
            )
        else:
            with self.assertRaises(SystemError) as cm:
                _testcapi.return_result_with_error()
            self.assertRegex(str(cm.exception), "return_result_with_error.* " "returned a result with an error set")
开发者ID:HelioCampos,项目名称:cpython,代码行数:33,代码来源:test_capi.py

示例12: test_syntaxerror_unindented_caret_position

 def test_syntaxerror_unindented_caret_position(self):
     script = "1 + 1 = 2\n"
     with support.temp_dir() as script_dir:
         script_name = _make_test_script(script_dir, 'script', script)
         exitcode, stdout, stderr = assert_python_failure(script_name)
         text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
         # Confirm that the caret is located under the first 1 character
         self.assertIn("\n    1 + 1 = 2\n    ^", text)
开发者ID:Daetalus,项目名称:cpython,代码行数:8,代码来源:test_cmd_line_script.py

示例13: test_unknown_options

 def test_unknown_options(self):
     rc, out, err = assert_python_failure('-E', '-z')
     self.assertIn(b'Unknown option: -z', err)
     self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1)
     self.assertEqual(b'', out)
     # Add "without='-E'" to prevent _assert_python to append -E
     # to env_vars and change the output of stderr
     rc, out, err = assert_python_failure('-z', without='-E')
     self.assertIn(b'Unknown option: -z', err)
     self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1)
     self.assertEqual(b'', out)
     rc, out, err = assert_python_failure('-a', '-z', without='-E')
     self.assertIn(b'Unknown option: -a', err)
     # only the first unknown option is reported
     self.assertNotIn(b'Unknown option: -z', err)
     self.assertEqual(err.splitlines().count(b'Unknown option: -a'), 1)
     self.assertEqual(b'', out)
开发者ID:cherish3620,项目名称:cpython,代码行数:17,代码来源:test_cmd_line.py

示例14: _check_import_error

 def _check_import_error(self, script_name, expected_msg, *cmd_line_switches):
     run_args = cmd_line_switches + (script_name,)
     rc, out, err = assert_python_failure(*run_args)
     if verbose > 1:
         print("Output from test script %r:" % script_name)
         print(repr(err))
         print("Expected output: %r" % expected_msg)
     self.assertIn(expected_msg.encode("utf-8"), err)
开发者ID:wdv4758h,项目名称:cpython,代码行数:8,代码来源:test_cmd_line_script.py

示例15: get_output

 def get_output(self, *args, failure=False, **kw):
     kw = dict(self.DEFAULT_ENV, **kw)
     if failure:
         out = assert_python_failure(*args, **kw)
         out = out[2]
     else:
         out = assert_python_ok(*args, **kw)
         out = out[1]
     return out.decode().rstrip("\n\r")
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:9,代码来源:test_utf8_mode.py


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