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


Python support.captured_stderr方法代码示例

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


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

示例1: test_sni_callback_wrong_return_type

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_sni_callback_wrong_return_type(self):
            # Returning the wrong return type terminates the TLS connection
            # with an internal error alert.
            server_context, other_context, client_context = self.sni_contexts()

            def cb_wrong_return_type(ssl_sock, server_name, initial_context):
                return "foo"
            server_context.set_servername_callback(cb_wrong_return_type)

            with self.assertRaises(ssl.SSLError) as cm, \
                 support.captured_stderr() as stderr:
                stats = server_params_test(client_context, server_context,
                                           chatty=False,
                                           sni_name='supermessage')
            self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_INTERNAL_ERROR')
            self.assertIn("TypeError", stderr.getvalue()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_ssl.py

示例2: test_error_handling

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_error_handling(self):
        h = TestStreamHandler(BadStream())
        r = logging.makeLogRecord({})
        old_raise = logging.raiseExceptions

        try:
            h.handle(r)
            self.assertIs(h.error_record, r)

            h = logging.StreamHandler(BadStream())
            with support.captured_stderr() as stderr:
                h.handle(r)
                msg = '\nRuntimeError: deliberate mistake\n'
                self.assertIn(msg, stderr.getvalue())

            logging.raiseExceptions = False
            with support.captured_stderr() as stderr:
                h.handle(r)
                self.assertEqual('', stderr.getvalue())
        finally:
            logging.raiseExceptions = old_raise

# -- The following section could be moved into a server_helper.py module
# -- if it proves to be of wider utility than just test_logging 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_logging.py

示例3: test_delegation_of_close_to_non_generator

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_delegation_of_close_to_non_generator(self):
        """
        Test delegation of close() to non-generator
        """
        trace = []
        def g():
            try:
                trace.append("starting g")
                yield from range(3)
                trace.append("g should not be here")
            finally:
                trace.append("finishing g")
        gi = g()
        next(gi)
        with captured_stderr() as output:
            gi.close()
        self.assertEqual(output.getvalue(), '')
        self.assertEqual(trace,[
            "starting g",
            "finishing g",
        ]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_pep380.py

示例4: test_error_after_default

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_error_after_default(self):
        with original_warnings.catch_warnings(module=self.module) as w:
            self.module.resetwarnings()
            message = "FilterTests.test_ignore_after_default"
            def f():
                self.module.warn(message, UserWarning)

            with support.captured_stderr() as stderr:
                f()
            stderr = stderr.getvalue()
            self.assertIn("UserWarning: FilterTests.test_ignore_after_default",
                          stderr)
            self.assertIn("self.module.warn(message, UserWarning)",
                          stderr)

            self.module.filterwarnings("error", category=UserWarning)
            self.assertRaises(UserWarning, f) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:19,代码来源:__init__.py

示例5: run_script

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def run_script(self, input="", *, args=("-",), substfile="xx yy\n"):
        substfilename = support.TESTFN + ".subst"
        with open(substfilename, "w") as file:
            file.write(substfile)
        self.addCleanup(support.unlink, substfilename)

        argv = ["fixcid.py", "-s", substfilename] + list(args)
        script = os.path.join(scriptsdir, "fixcid.py")
        with support.swap_attr(sys, "argv", argv), \
                support.swap_attr(sys, "stdin", StringIO(input)), \
                support.captured_stdout() as output, \
                support.captured_stderr():
            try:
                runpy.run_path(script, run_name="__main__")
            except SystemExit as exit:
                self.assertEqual(exit.code, 0)
        return output.getvalue() 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:19,代码来源:test_fixcid.py

示例6: test_captured_stderr

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_captured_stderr(self):
        with support.captured_stderr() as stderr:
            print >>sys.stderr, "hello"
        self.assertEqual(stderr.getvalue(), "hello\n") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_test_support.py

示例7: test_command_line_handling_do_discovery_too_many_arguments

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_command_line_handling_do_discovery_too_many_arguments(self):
        program = TestableTestProgram()
        program.testLoader = None

        with support.captured_stderr() as stderr, \
             self.assertRaises(SystemExit) as cm:
            # too many args
            program._do_discovery(['one', 'two', 'three', 'four'])
        self.assertEqual(cm.exception.args, (2,))
        self.assertIn('usage:', stderr.getvalue()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_discovery.py

示例8: assertNoStderr

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def assertNoStderr(self):
        with captured_stderr() as buf:
            yield
        self.assertEqual(buf.getvalue(), "") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_case.py

示例9: testBufferCatchFailfast

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def testBufferCatchFailfast(self):
        program = self.program
        for arg, attr in (('buffer', 'buffer'), ('failfast', 'failfast'),
                      ('catch', 'catchbreak')):
            if attr == 'catch' and not hasInstallHandler:
                continue

            setattr(program, attr, None)
            program.parseArgs([None])
            self.assertIs(getattr(program, attr), False)

            false = []
            setattr(program, attr, false)
            program.parseArgs([None])
            self.assertIs(getattr(program, attr), false)

            true = [42]
            setattr(program, attr, true)
            program.parseArgs([None])
            self.assertIs(getattr(program, attr), true)

            short_opt = '-%s' % arg[0]
            long_opt = '--%s' % arg
            for opt in short_opt, long_opt:
                setattr(program, attr, None)
                program.parseArgs([None, opt])
                self.assertIs(getattr(program, attr), True)

                setattr(program, attr, False)
                with support.captured_stderr() as stderr, \
                    self.assertRaises(SystemExit) as cm:
                    program.parseArgs([None, opt])
                self.assertEqual(cm.exception.args, (2,))

                setattr(program, attr, True)
                with support.captured_stderr() as stderr, \
                    self.assertRaises(SystemExit) as cm:
                    program.parseArgs([None, opt])
                self.assertEqual(cm.exception.args, (2,)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:41,代码来源:test_program.py

示例10: test_send_error

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_send_error(self):
        # Use a subprocess to have only one thread.
        if os.name == 'nt':
            action = 'send'
        else:
            action = 'write'
        code = """if 1:
        import errno
        import signal
        import socket
        import sys
        import time
        import _testcapi
        from test.support import captured_stderr

        signum = signal.SIGINT

        def handler(signum, frame):
            pass

        signal.signal(signum, handler)

        read, write = socket.socketpair()
        read.setblocking(False)
        write.setblocking(False)

        signal.set_wakeup_fd(write.fileno())

        # Close sockets: send() will fail
        read.close()
        write.close()

        with captured_stderr() as err:
            _testcapi.raise_signal(signum)

        err = err.getvalue()
        if ('Exception ignored when trying to {action} to the signal wakeup fd'
            not in err):
            raise AssertionError(err)
        """.format(action=action)
        assert_python_ok('-c', code) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:43,代码来源:test_signal.py

示例11: test_main_exception

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_main_exception(self):
        with captured_stderr() as error_stringio:
            s = self.run_main(switches=['1/0'])
        self.assert_exc_string(error_stringio.getvalue(), 'ZeroDivisionError') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_timeit.py

示例12: test_main_exception_fixed_reps

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_main_exception_fixed_reps(self):
        with captured_stderr() as error_stringio:
            s = self.run_main(switches=['-n1', '1/0'])
        self.assert_exc_string(error_stringio.getvalue(), 'ZeroDivisionError') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_timeit.py

示例13: test_debuglevel

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_debuglevel(self):
        mock_socket.reply_with(b"220 Hello world")
        smtp = smtplib.SMTP()
        smtp.set_debuglevel(1)
        with support.captured_stderr() as stderr:
            smtp.connect(HOST, self.port)
        smtp.close()
        expected = re.compile(r"^connect:", re.MULTILINE)
        self.assertRegex(stderr.getvalue(), expected) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_smtplib.py

示例14: test_debuglevel_2

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_debuglevel_2(self):
        mock_socket.reply_with(b"220 Hello world")
        smtp = smtplib.SMTP()
        smtp.set_debuglevel(2)
        with support.captured_stderr() as stderr:
            smtp.connect(HOST, self.port)
        smtp.close()
        expected = re.compile(r"^\d{2}:\d{2}:\d{2}\.\d{6} connect: ",
                              re.MULTILINE)
        self.assertRegex(stderr.getvalue(), expected)


# Test server thread using the specified SMTP server class 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_smtplib.py

示例15: test_captured_stderr

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stderr [as 别名]
def test_captured_stderr(self):
        with support.captured_stderr() as stderr:
            print("hello", file=sys.stderr)
        self.assertEqual(stderr.getvalue(), "hello\n") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_support.py


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