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


Python support.captured_stdin方法代码示例

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


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

示例1: test_captured_stdin

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stdin [as 别名]
def test_captured_stdin(self):
        with support.captured_stdin() as stdin:
            stdin.write('hello\n')
            stdin.seek(0)
            # call test code that consumes from sys.stdin
            captured = raw_input()
        self.assertEqual(captured, "hello") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_test_support.py

示例2: test_captured_stdin

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stdin [as 别名]
def test_captured_stdin(self):
        with support.captured_stdin() as stdin:
            stdin.write('hello\n')
            stdin.seek(0)
            # call test code that consumes from sys.stdin
            captured = input()
        self.assertEqual(captured, "hello") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_support.py

示例3: test_cgi_xmlrpc_response

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import captured_stdin [as 别名]
def test_cgi_xmlrpc_response(self):
        data = """<?xml version='1.0'?>
        <methodCall>
            <methodName>test_method</methodName>
            <params>
                <param>
                    <value><string>foo</string></value>
                </param>
                <param>
                    <value><string>bar</string></value>
                </param>
            </params>
        </methodCall>
        """

        with support.EnvironmentVarGuard() as env, \
             captured_stdout(encoding=self.cgi.encoding) as data_out, \
             support.captured_stdin() as data_in:
            data_in.write(data)
            data_in.seek(0)
            env['CONTENT_LENGTH'] = str(len(data))
            self.cgi.handle_request()
        data_out.seek(0)

        # will respond exception, if so, our goal is achieved ;)
        handle = data_out.read()

        # start with 44th char so as not to get http header, we just
        # need only xml
        self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, handle[44:])

        # Also test the content-length returned  by handle_request
        # Using the same test method inorder to avoid all the datapassing
        # boilerplate code.
        # Test for bug: http://bugs.python.org/issue5040

        content = handle[handle.find("<?xml"):]

        self.assertEqual(
            int(re.search('Content-Length: (\d+)', handle).group(1)),
            len(content)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:43,代码来源:test_xmlrpc.py


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