本文整理汇总了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")
示例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")
示例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))