Make makepyfile accept UTF-8 so a few cookie tests in test_assertrewrite.py
don't need to be dedented. --HG-- branch : makepyfile_utf8
This commit is contained in:
parent
e061ace099
commit
f47ae74981
|
@ -246,8 +246,14 @@ class TmpTestdir:
|
||||||
ret = None
|
ret = None
|
||||||
for name, value in items:
|
for name, value in items:
|
||||||
p = self.tmpdir.join(name).new(ext=ext)
|
p = self.tmpdir.join(name).new(ext=ext)
|
||||||
source = py.builtin._totext(py.code.Source(value)).strip()
|
source = py.code.Source(value)
|
||||||
content = source.encode("utf-8") # + "\n"
|
def my_totext(s, encoding="utf-8"):
|
||||||
|
if py.builtin._isbytes(s):
|
||||||
|
s = py.builtin._totext(s, encoding=encoding)
|
||||||
|
return s
|
||||||
|
source_unicode = "\n".join([my_totext(line) for line in source.lines])
|
||||||
|
source = py.builtin._totext(source_unicode)
|
||||||
|
content = source.strip().encode("utf-8") # + "\n"
|
||||||
#content = content.rstrip() + "\n"
|
#content = content.rstrip() + "\n"
|
||||||
p.write(content, "wb")
|
p.write(content, "wb")
|
||||||
if ret is None:
|
if ret is None:
|
||||||
|
|
|
@ -458,28 +458,29 @@ class TestAssertionRewriteHookDetails(object):
|
||||||
|
|
||||||
@pytest.mark.skipif("sys.version_info[0] >= 3")
|
@pytest.mark.skipif("sys.version_info[0] >= 3")
|
||||||
def test_detect_coding_cookie(self, testdir):
|
def test_detect_coding_cookie(self, testdir):
|
||||||
testdir.tmpdir.join("test_cookie.py").write("""# -*- coding: utf-8 -*-
|
testdir.makepyfile(test_cookie=u"""
|
||||||
u"St\xc3\xa4d"
|
# -*- coding: utf-8 -*-
|
||||||
def test_rewritten():
|
u"St\xc3\xa4d"
|
||||||
assert "@py_builtins" in globals()""", "wb")
|
def test_rewritten():
|
||||||
|
assert "@py_builtins" in globals()""".encode('utf-8'))
|
||||||
assert testdir.runpytest().ret == 0
|
assert testdir.runpytest().ret == 0
|
||||||
|
|
||||||
@pytest.mark.skipif("sys.version_info[0] >= 3")
|
@pytest.mark.skipif("sys.version_info[0] >= 3")
|
||||||
def test_detect_coding_cookie_second_line(self, testdir):
|
def test_detect_coding_cookie_second_line(self, testdir):
|
||||||
testdir.tmpdir.join("test_cookie.py").write("""#!/usr/bin/env python
|
testdir.makepyfile(test_cookie=u"""
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
u"St\xc3\xa4d"
|
u"St\xc3\xa4d"
|
||||||
def test_rewritten():
|
def test_rewritten():
|
||||||
assert "@py_builtins" in globals()""", "wb")
|
assert "@py_builtins" in globals()""".encode('utf-8'))
|
||||||
assert testdir.runpytest().ret == 0
|
assert testdir.runpytest().ret == 0
|
||||||
|
|
||||||
@pytest.mark.skipif("sys.version_info[0] >= 3")
|
@pytest.mark.skipif("sys.version_info[0] >= 3")
|
||||||
def test_detect_coding_cookie_crlf(self, testdir):
|
def test_detect_coding_cookie_crlf(self, testdir):
|
||||||
testdir.tmpdir.join("test_cookie.py").write("""#!/usr/bin/env python
|
testdir.makepyfile(test_cookie=u"""
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
u"St\xc3\xa4d"
|
u"St\xc3\xa4d"
|
||||||
def test_rewritten():
|
def test_rewritten():
|
||||||
assert "@py_builtins" in globals()""".replace("\n", "\r\n"), "wb")
|
assert "@py_builtins" in globals()""".encode('utf-8'))
|
||||||
assert testdir.runpytest().ret == 0
|
assert testdir.runpytest().ret == 0
|
||||||
|
|
||||||
def test_sys_meta_path_munged(self, testdir):
|
def test_sys_meta_path_munged(self, testdir):
|
||||||
|
|
Loading…
Reference in New Issue