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


Python StringIO.getvalue方法代码示例

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


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

示例1: test_log_view_exception

# 需要导入模块: from flask._compat import StringIO [as 别名]
# 或者: from flask._compat.StringIO import getvalue [as 别名]
def test_log_view_exception(app, client):
    @app.route('/')
    def index():
        raise Exception('test')

    app.testing = False
    stream = StringIO()
    rv = client.get('/', errors_stream=stream)
    assert rv.status_code == 500
    assert rv.data
    err = stream.getvalue()
    assert 'Exception on / [GET]' in err
    assert 'Exception: test' in err
开发者ID:AEliu,项目名称:flask,代码行数:15,代码来源:test_logging.py

示例2: test_wsgi_errors_stream

# 需要导入模块: from flask._compat import StringIO [as 别名]
# 或者: from flask._compat.StringIO import getvalue [as 别名]
def test_wsgi_errors_stream(app, client):
    @app.route('/')
    def index():
        app.logger.error('test')
        return ''

    stream = StringIO()
    client.get('/', errors_stream=stream)
    assert 'ERROR in test_logging: test' in stream.getvalue()

    assert wsgi_errors_stream._get_current_object() is sys.stderr

    with app.test_request_context(errors_stream=stream):
        assert wsgi_errors_stream._get_current_object() is stream
开发者ID:AEliu,项目名称:flask,代码行数:16,代码来源:test_logging.py

示例3: test_exception_logging

# 需要导入模块: from flask._compat import StringIO [as 别名]
# 或者: from flask._compat.StringIO import getvalue [as 别名]
    def test_exception_logging(self):
        out = StringIO()
        app = flask.Flask(__name__)
        app.logger_name = 'flask_tests/test_exception_logging'
        app.logger.addHandler(StreamHandler(out))

        @app.route('/')
        def index():
            1 // 0

        rv = app.test_client().get('/')
        self.assert_equal(rv.status_code, 500)
        self.assert_in(b'Internal Server Error', rv.data)

        err = out.getvalue()
        self.assert_in('Exception on / [GET]', err)
        self.assert_in('Traceback (most recent call last):', err)
        self.assert_in('1 // 0', err)
        self.assert_in('ZeroDivisionError:', err)
开发者ID:lebseu,项目名称:VAMK-HELP,代码行数:21,代码来源:helpers.py

示例4: test_suppressed_exception_logging

# 需要导入模块: from flask._compat import StringIO [as 别名]
# 或者: from flask._compat.StringIO import getvalue [as 别名]
def test_suppressed_exception_logging():
    class SuppressedFlask(flask.Flask):
        def log_exception(self, exc_info):
            pass

    out = StringIO()
    app = SuppressedFlask(__name__)
    app.logger_name = 'flask_tests/test_suppressed_exception_logging'
    app.logger.addHandler(StreamHandler(out))

    @app.route('/')
    def index():
        1 // 0

    rv = app.test_client().get('/')
    assert rv.status_code == 500
    assert b'Internal Server Error' in rv.data

    err = out.getvalue()
    assert err == ''
开发者ID:0x78kiki,项目名称:flask,代码行数:22,代码来源:test_subclassing.py

示例5: test_exception_logging

# 需要导入模块: from flask._compat import StringIO [as 别名]
# 或者: from flask._compat.StringIO import getvalue [as 别名]
    def test_exception_logging(self, app, client):
        out = StringIO()
        app.config['LOGGER_HANDLER_POLICY'] = 'never'
        app.logger_name = 'flask_tests/test_exception_logging'
        app.logger.addHandler(StreamHandler(out))
        app.testing = False

        @app.route('/')
        def index():
            1 // 0

        rv = client.get('/')
        assert rv.status_code == 500
        assert b'Internal Server Error' in rv.data

        err = out.getvalue()
        assert 'Exception on / [GET]' in err
        assert 'Traceback (most recent call last):' in err
        assert '1 // 0' in err
        assert 'ZeroDivisionError:' in err
开发者ID:s-block,项目名称:flask,代码行数:22,代码来源:test_helpers.py


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