Fix _is_setup_py for files encoded differently than locale

This commit is contained in:
Anthony Sottile
2020-05-07 13:14:58 -07:00
parent de556f895f
commit b238845d0f
3 changed files with 31 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import pytest
from _pytest.compat import MODULE_NOT_FOUND_ERROR
from _pytest.doctest import _get_checker
from _pytest.doctest import _is_mocked
from _pytest.doctest import _is_setup_py
from _pytest.doctest import _patch_unwrap_mock_aware
from _pytest.doctest import DoctestItem
from _pytest.doctest import DoctestModule
@@ -1487,3 +1488,27 @@ def test_warning_on_unwrap_of_broken_object(stop):
with pytest.raises(KeyError):
inspect.unwrap(bad_instance, stop=stop)
assert inspect.unwrap.__module__ == "inspect"
def test_is_setup_py_not_named_setup_py(tmpdir):
not_setup_py = tmpdir.join("not_setup.py")
not_setup_py.write('from setuptools import setup; setup(name="foo")')
assert not _is_setup_py(not_setup_py)
@pytest.mark.parametrize("mod", ("setuptools", "distutils.core"))
def test_is_setup_py_is_a_setup_py(tmpdir, mod):
setup_py = tmpdir.join("setup.py")
setup_py.write('from {} import setup; setup(name="foo")'.format(mod))
assert _is_setup_py(setup_py)
@pytest.mark.parametrize("mod", ("setuptools", "distutils.core"))
def test_is_setup_py_different_encoding(tmpdir, mod):
setup_py = tmpdir.join("setup.py")
contents = (
"# -*- coding: cp1252 -*-\n"
'from {} import setup; setup(name="foo", description="")\n'.format(mod)
)
setup_py.write_binary(contents.encode("cp1252"))
assert _is_setup_py(setup_py)