提交 e0c489fd 编写于 作者: A Antoine Pitrou

Fix error in coverage runs under Py3 with a C locale

上级 9bdc3176
...@@ -6,8 +6,8 @@ import traceback ...@@ -6,8 +6,8 @@ import traceback
from tornado.escape import utf8, native_str, to_unicode from tornado.escape import utf8, native_str, to_unicode
from tornado.template import Template, DictLoader, ParseError, Loader from tornado.template import Template, DictLoader, ParseError, Loader
from tornado.test.util import unittest from tornado.test.util import unittest, is_coverage_running
from tornado.util import ObjectDict, unicode_type from tornado.util import ObjectDict, unicode_type, PY3
class TemplateTest(unittest.TestCase): class TemplateTest(unittest.TestCase):
...@@ -175,6 +175,11 @@ try{% set y = 1/x %} ...@@ -175,6 +175,11 @@ try{% set y = 1/x %}
self.assertEqual(template.generate(), '0') self.assertEqual(template.generate(), '0')
def test_non_ascii_name(self): def test_non_ascii_name(self):
if PY3 and is_coverage_running():
try:
os.fsencode(u"t\u00e9st.html")
except UnicodeEncodeError:
self.skipTest("coverage tries to access unencodable filename")
loader = DictLoader({u"t\u00e9st.html": "hello"}) loader = DictLoader({u"t\u00e9st.html": "hello"})
self.assertEqual(loader.load(u"t\u00e9st.html").generate(), b"hello") self.assertEqual(loader.load(u"t\u00e9st.html").generate(), b"hello")
......
...@@ -76,3 +76,21 @@ def exec_test(caller_globals, caller_locals, s): ...@@ -76,3 +76,21 @@ def exec_test(caller_globals, caller_locals, s):
local_namespace = {} local_namespace = {}
exec(textwrap.dedent(s), global_namespace, local_namespace) exec(textwrap.dedent(s), global_namespace, local_namespace)
return local_namespace return local_namespace
def is_coverage_running():
"""Return whether coverage is currently running.
"""
if 'coverage' not in sys.modules:
return False
tracer = sys.gettrace()
if tracer is None:
return False
try:
mod = tracer.__module__
except AttributeError:
try:
mod = tracer.__class__.__module__
except AttributeError:
return False
return mod.startswith('coverage')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册