test_wsgi.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码
def test_wsgiErrorsExpectsOnlyNativeStringsInPython2(self):
        """
        The C{'wsgi.errors'} file-like object from the C{environ} C{dict}
        expects writes of only native strings in Python 2. Some existing WSGI
        applications may write non-native (i.e. C{unicode}) strings so, for
        compatibility, these elicit only a warning in Python 2.
        """
        if _PY3:
            raise SkipTest("Not relevant in Python 3")

        request, result = self.prepareRequest()
        request.requestReceived()
        environ, _ = self.successResultOf(result)
        errors = environ["wsgi.errors"]

        with warnings.catch_warnings(record=True) as caught:
            errors.write(u"fred")
        self.assertEqual(1, len(caught))
        self.assertEqual(UnicodeWarning, caught[0].category)
        self.assertEqual(
            "write() argument should be str, not u'fred' (unicode)",
            str(caught[0].message))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号