fix detection of the coding cookie when it is on the second line of the file (fixes #330)
This commit is contained in:
parent
33b663e03d
commit
56e6ae567c
|
@ -1,7 +1,8 @@
|
|||
Changes between 2.4.2 and 2.4.3
|
||||
-----------------------------------
|
||||
|
||||
- In assertion rewriting mode on Python 2, fix the detection of coding cookies.
|
||||
- In assertion rewriting mode on Python 2, fix the detection of coding
|
||||
cookies. See issue #330.
|
||||
|
||||
Changes between 2.4.1 and 2.4.2
|
||||
-----------------------------------
|
||||
|
|
|
@ -221,7 +221,7 @@ def _rewrite_test(state, fn):
|
|||
end2 = source.find("\n", end1 + 1)
|
||||
if (not source.startswith(BOM_UTF8) and
|
||||
cookie_re.match(source[0:end1]) is None and
|
||||
cookie_re.match(source[end1:end2]) is None):
|
||||
cookie_re.match(source[end1 + 1:end2]) is None):
|
||||
if hasattr(state, "_indecode"):
|
||||
return None # encodings imported us again, we don't rewrite
|
||||
state._indecode = True
|
||||
|
|
|
@ -451,7 +451,16 @@ class TestAssertionRewriteHookDetails(object):
|
|||
|
||||
@pytest.mark.skipif("sys.version_info[0] >= 3")
|
||||
def test_detect_coding_cookie(self, testdir):
|
||||
testdir.tmpdir.join("test_utf8.py").write("""# -*- coding: utf-8 -*-
|
||||
testdir.tmpdir.join("test_cookie.py").write("""# -*- coding: utf-8 -*-
|
||||
u"St\xc3\xa4d"
|
||||
def test_rewritten():
|
||||
assert "@py_builtins" in globals()""", "wb")
|
||||
assert testdir.runpytest().ret == 0
|
||||
|
||||
@pytest.mark.skipif("sys.version_info[0] >= 3")
|
||||
def test_detect_coding_cookie_second_line(self, testdir):
|
||||
testdir.tmpdir.join("test_cookie.py").write("""#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
u"St\xc3\xa4d"
|
||||
def test_rewritten():
|
||||
assert "@py_builtins" in globals()""", "wb")
|
||||
|
|
Loading…
Reference in New Issue