2 new commits in pytest: https://bitbucket.org/hpk42/pytest/commits/b04d97dfa5e2/ Changeset: b04d97dfa5e2 User: gutworth Date: 2013-10-05 21:16:08 Summary: fix detection of the coding cookie when it is on the second line of the file (fixes #330) Affected #: 3 files
diff -r 95fc848e108a9917b2261593e8b3ca26147b42db -r b04d97dfa5e2dea918a83c907c4d836053f18d75 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -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 ----------------------------------- diff -r 95fc848e108a9917b2261593e8b3ca26147b42db -r b04d97dfa5e2dea918a83c907c4d836053f18d75 _pytest/assertion/rewrite.py --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -221,7 +221,7 @@ 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 diff -r 95fc848e108a9917b2261593e8b3ca26147b42db -r b04d97dfa5e2dea918a83c907c4d836053f18d75 testing/test_assertrewrite.py --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -451,7 +451,16 @@ @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") https://bitbucket.org/hpk42/pytest/commits/f71c46c34d48/ Changeset: f71c46c34d48 User: gutworth Date: 2013-10-05 21:20:32 Summary: add test for detecting coding cookie with CRLF newlines Affected #: 1 file diff -r b04d97dfa5e2dea918a83c907c4d836053f18d75 -r f71c46c34d4879fd13d2f30ba22e18f6c604bc91 testing/test_assertrewrite.py --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -466,6 +466,15 @@ assert "@py_builtins" in globals()""", "wb") assert testdir.runpytest().ret == 0 + @pytest.mark.skipif("sys.version_info[0] >= 3") + def test_detect_coding_cookie_crlf(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()""".replace("\n", "\r\n"), "wb") + assert testdir.runpytest().ret == 0 + def test_write_pyc(self, testdir, tmpdir, monkeypatch): from _pytest.assertion.rewrite import _write_pyc from _pytest.assertion import AssertionState Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit