aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-03-07 16:50:43 -0500
committerJason R. Coombs <jaraco@jaraco.com>2020-03-07 16:50:43 -0500
commit278e027348f52fc0dfc7ac6046fd169632922bb1 (patch)
treeab7a3b10c25421a3a040b0fa2c163e4fa380767f /setuptools/tests
parentc5958f26680b8bfad10d0ec03a613725c9a4c580 (diff)
parent25edd1951d8d44c34578c926f5c20ed3d452587b (diff)
downloadexternal_python_setuptools-278e027348f52fc0dfc7ac6046fd169632922bb1.tar.gz
external_python_setuptools-278e027348f52fc0dfc7ac6046fd169632922bb1.tar.bz2
external_python_setuptools-278e027348f52fc0dfc7ac6046fd169632922bb1.zip
Merge branch 'master' into patch-1
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/__init__.py2
-rw-r--r--setuptools/tests/requirements.txt12
-rw-r--r--setuptools/tests/server.py19
-rw-r--r--setuptools/tests/test_bdist_egg.py17
-rw-r--r--setuptools/tests/test_build_clib.py3
-rw-r--r--setuptools/tests/test_build_meta.py50
-rw-r--r--setuptools/tests/test_config.py6
-rw-r--r--setuptools/tests/test_develop.py4
-rw-r--r--setuptools/tests/test_dist.py14
-rw-r--r--setuptools/tests/test_easy_install.py316
-rw-r--r--setuptools/tests/test_egg_info.py224
-rw-r--r--setuptools/tests/test_glibc.py52
-rw-r--r--setuptools/tests/test_integration.py2
-rw-r--r--setuptools/tests/test_msvc14.py84
-rw-r--r--setuptools/tests/test_pep425tags.py170
-rw-r--r--setuptools/tests/test_register.py43
-rw-r--r--setuptools/tests/test_sdist.py122
-rw-r--r--setuptools/tests/test_setopt.py2
-rw-r--r--setuptools/tests/test_setuptools.py13
-rw-r--r--setuptools/tests/test_test.py2
-rw-r--r--setuptools/tests/test_upload.py211
-rw-r--r--setuptools/tests/test_virtualenv.py42
-rw-r--r--setuptools/tests/test_wheel.py50
23 files changed, 869 insertions, 591 deletions
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index 5f4a1c29..9c77b51f 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -6,7 +6,7 @@ from setuptools.extern.six import PY2, PY3
__all__ = [
- 'fail_on_ascii', 'py2_only', 'py3_only'
+ 'fail_on_ascii', 'py2_only', 'py3_only'
]
diff --git a/setuptools/tests/requirements.txt b/setuptools/tests/requirements.txt
new file mode 100644
index 00000000..19bf5aef
--- /dev/null
+++ b/setuptools/tests/requirements.txt
@@ -0,0 +1,12 @@
+mock
+pytest-flake8
+flake8-2020; python_version>="3.6"
+virtualenv>=13.0.0
+pytest-virtualenv>=1.2.7
+pytest>=3.7
+wheel
+coverage>=4.5.1
+pytest-cov>=2.5.1
+paver; python_version>="3.6"
+futures; python_version=="2.7"
+pip>=19.1 # For proper file:// URLs support.
diff --git a/setuptools/tests/server.py b/setuptools/tests/server.py
index fc3a5975..8b17b081 100644
--- a/setuptools/tests/server.py
+++ b/setuptools/tests/server.py
@@ -1,10 +1,13 @@
"""Basic http server for tests to simulate PyPI or custom indexes
"""
+import os
import time
import threading
from setuptools.extern.six.moves import BaseHTTPServer, SimpleHTTPServer
+from setuptools.extern.six.moves.urllib_parse import urljoin
+from setuptools.extern.six.moves.urllib.request import pathname2url
class IndexServer(BaseHTTPServer.HTTPServer):
@@ -70,5 +73,19 @@ class MockServer(BaseHTTPServer.HTTPServer, threading.Thread):
self.serve_forever()
@property
+ def netloc(self):
+ return 'localhost:%s' % self.server_port
+
+ @property
def url(self):
- return 'http://localhost:%(server_port)s/' % vars(self)
+ return 'http://%s/' % self.netloc
+
+
+def path_to_url(path, authority=None):
+ """ Convert a path to a file: URL. """
+ path = os.path.normpath(os.path.abspath(path))
+ base = 'file:'
+ if authority is not None:
+ base += '//' + authority
+ url = urljoin(base, pathname2url(path))
+ return url
diff --git a/setuptools/tests/test_bdist_egg.py b/setuptools/tests/test_bdist_egg.py
index 54742aa6..8760ea30 100644
--- a/setuptools/tests/test_bdist_egg.py
+++ b/setuptools/tests/test_bdist_egg.py
@@ -7,6 +7,7 @@ import zipfile
import pytest
from setuptools.dist import Distribution
+from setuptools import SetuptoolsDeprecationWarning
from . import contexts
@@ -42,7 +43,7 @@ class Test:
# let's see if we got our egg link at the right place
[content] = os.listdir('dist')
- assert re.match(r'foo-0.0.0-py[23].\d.egg$', content)
+ assert re.match(r'foo-0.0.0-py[23].\d+.egg$', content)
@pytest.mark.xfail(
os.environ.get('PYTHONDONTWRITEBYTECODE'),
@@ -64,3 +65,17 @@ class Test:
names = list(zi.filename for zi in zip.filelist)
assert 'hi.pyc' in names
assert 'hi.py' not in names
+
+ def test_eggsecutable_warning(self, setup_context, user_override):
+ dist = Distribution(dict(
+ script_name='setup.py',
+ script_args=['bdist_egg'],
+ name='foo',
+ py_modules=['hi'],
+ entry_points={
+ 'setuptools.installation':
+ ['eggsecutable = my_package.some_module:main_func']},
+ ))
+ dist.parse_command_line()
+ with pytest.warns(SetuptoolsDeprecationWarning):
+ dist.run_commands()
diff --git a/setuptools/tests/test_build_clib.py b/setuptools/tests/test_build_clib.py
index 3779e679..48bea2b4 100644
--- a/setuptools/tests/test_build_clib.py
+++ b/setuptools/tests/test_build_clib.py
@@ -8,8 +8,7 @@ from setuptools.dist import Distribution
class TestBuildCLib:
@mock.patch(
- 'setuptools.command.build_clib.newer_pairwise_group'
- )
+ 'setuptools.command.build_clib.newer_pairwise_group')
def test_build_libraries(self, mock_newer):
dist = Distribution()
cmd = build_clib(dist)
diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py
index e1efe561..8fcf3055 100644
--- a/setuptools/tests/test_build_meta.py
+++ b/setuptools/tests/test_build_meta.py
@@ -23,6 +23,7 @@ class BuildBackendBase:
self.env = env
self.backend_name = backend_name
+
class BuildBackend(BuildBackendBase):
"""PEP 517 Build Backend"""
@@ -262,6 +263,27 @@ class TestBuildMetaBackend:
assert os.path.isfile(
os.path.join(os.path.abspath("out_sdist"), sdist_name))
+ def test_build_sdist_pyproject_toml_exists(self, tmpdir_cwd):
+ files = {
+ 'setup.py': DALS("""
+ __import__('setuptools').setup(
+ name='foo',
+ version='0.0.0',
+ py_modules=['hello']
+ )"""),
+ 'hello.py': '',
+ 'pyproject.toml': DALS("""
+ [build-system]
+ requires = ["setuptools", "wheel"]
+ build-backend = "setuptools.build_meta
+ """),
+ }
+ build_files(files)
+ build_backend = self.get_build_backend()
+ targz_path = build_backend.build_sdist("temp")
+ with tarfile.open(os.path.join("temp", targz_path)) as tar:
+ assert any('pyproject.toml' in name for name in tar.getnames())
+
def test_build_sdist_setup_py_exists(self, tmpdir_cwd):
# If build_sdist is called from a script other than setup.py,
# ensure setup.py is included
@@ -385,6 +407,28 @@ class TestBuildMetaBackend:
assert expected == sorted(actual)
+ _sys_argv_0_passthrough = {
+ 'setup.py': DALS("""
+ import os
+ import sys
+
+ __import__('setuptools').setup(
+ name='foo',
+ version='0.0.0',
+ )
+
+ sys_argv = os.path.abspath(sys.argv[0])
+ file_path = os.path.abspath('setup.py')
+ assert sys_argv == file_path
+ """)
+ }
+
+ def test_sys_argv_passthrough(self, tmpdir_cwd):
+ build_files(self._sys_argv_0_passthrough)
+ build_backend = self.get_build_backend()
+ with pytest.raises(AssertionError):
+ build_backend.build_sdist("temp")
+
class TestBuildMetaLegacyBackend(TestBuildMetaBackend):
backend_name = 'setuptools.build_meta:__legacy__'
@@ -396,3 +440,9 @@ class TestBuildMetaLegacyBackend(TestBuildMetaBackend):
build_backend = self.get_build_backend()
build_backend.build_sdist("temp")
+
+ def test_sys_argv_passthrough(self, tmpdir_cwd):
+ build_files(self._sys_argv_0_passthrough)
+
+ build_backend = self.get_build_backend()
+ build_backend.build_sdist("temp")
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py
index 69d8d00d..2fa0b374 100644
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -695,7 +695,7 @@ class TestOptions:
)
with get_dist(tmpdir) as dist:
assert set(dist.packages) == set(
- ['fake_package', 'fake_package.sub_two'])
+ ['fake_package', 'fake_package.sub_two'])
@py2_only
def test_find_namespace_directive_fails_on_py2(self, tmpdir):
@@ -748,7 +748,7 @@ class TestOptions:
)
with get_dist(tmpdir) as dist:
assert set(dist.packages) == {
- 'fake_package', 'fake_package.sub_two'
+ 'fake_package', 'fake_package.sub_two'
}
def test_extras_require(self, tmpdir):
@@ -881,7 +881,7 @@ class TestExternalSetters:
return None
@patch.object(_Distribution, '__init__', autospec=True)
- def test_external_setters(self, mock_parent_init, tmpdir):
+ def test_external_setters(self, mock_parent_init, tmpdir):
mock_parent_init.side_effect = self._fake_distribution_init
dist = Distribution(attrs={
diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py
index 00d4bd9a..792975fd 100644
--- a/setuptools/tests/test_develop.py
+++ b/setuptools/tests/test_develop.py
@@ -95,7 +95,7 @@ class TestDevelop:
with io.open(fn) as init_file:
init = init_file.read().strip()
- expected = 'print("foo")' if six.PY3 else 'print "foo"'
+ expected = 'print "foo"' if six.PY2 else 'print("foo")'
assert init == expected
def test_console_scripts(self, tmpdir):
@@ -161,7 +161,7 @@ class TestNamespaces:
reason="https://github.com/pypa/setuptools/issues/851",
)
@pytest.mark.skipif(
- platform.python_implementation() == 'PyPy' and six.PY3,
+ platform.python_implementation() == 'PyPy' and not six.PY2,
reason="https://github.com/pypa/setuptools/issues/1202",
)
def test_namespace_package_importable(self, tmpdir):
diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py
index 36237f24..6e8c45fd 100644
--- a/setuptools/tests/test_dist.py
+++ b/setuptools/tests/test_dist.py
@@ -61,7 +61,8 @@ def test_dist_fetch_build_egg(tmpdir):
dist.fetch_build_egg(r)
for r in reqs
]
- assert [dist.key for dist in resolved_dists if dist] == reqs
+ # noqa below because on Python 2 it causes flakes
+ assert [dist.key for dist in resolved_dists if dist] == reqs # noqa
def test_dist__get_unpatched_deprecated():
@@ -284,7 +285,7 @@ def test_provides_extras_deterministic_order():
dist = Distribution(attrs)
assert dist.metadata.provides_extras == ['b', 'a']
-
+
CHECK_PACKAGE_DATA_TESTS = (
# Valid.
({
@@ -309,7 +310,8 @@ CHECK_PACKAGE_DATA_TESTS = (
({
'hello': str('*.msg'),
}, (
- "\"values of 'package_data' dict\" must be a list of strings (got '*.msg')"
+ "\"values of 'package_data' dict\" "
+ "must be a list of strings (got '*.msg')"
)),
# Invalid value type (generators are single use)
({
@@ -321,10 +323,12 @@ CHECK_PACKAGE_DATA_TESTS = (
)
-@pytest.mark.parametrize('package_data, expected_message', CHECK_PACKAGE_DATA_TESTS)
+@pytest.mark.parametrize(
+ 'package_data, expected_message', CHECK_PACKAGE_DATA_TESTS)
def test_check_package_data(package_data, expected_message):
if expected_message is None:
assert check_package_data(None, 'package_data', package_data) is None
else:
- with pytest.raises(DistutilsSetupError, match=re.escape(expected_message)):
+ with pytest.raises(
+ DistutilsSetupError, match=re.escape(expected_message)):
check_package_data(None, str('package_data'), package_data)
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index c3fd1c6e..534392b9 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -15,28 +15,29 @@ import distutils.errors
import io
import zipfile
import mock
-from setuptools.command.easy_install import (
- EasyInstallDeprecationWarning, ScriptWriter, WindowsScriptWriter,
-)
import time
+
from setuptools.extern import six
-from setuptools.extern.six.moves import urllib
import pytest
from setuptools import sandbox
from setuptools.sandbox import run_setup
import setuptools.command.easy_install as ei
-from setuptools.command.easy_install import PthDistributions
+from setuptools.command.easy_install import (
+ EasyInstallDeprecationWarning, ScriptWriter, PthDistributions,
+ WindowsScriptWriter,
+)
from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
from pkg_resources import normalize_path, working_set
from pkg_resources import Distribution as PRDistribution
-import setuptools.tests.server
+from setuptools.tests.server import MockServer, path_to_url
from setuptools.tests import fail_on_ascii
import pkg_resources
from . import contexts
+from .files import build_files
from .textwrap import DALS
__metaclass__ = type
@@ -440,35 +441,40 @@ def distutils_package():
yield
+@pytest.fixture
+def mock_index():
+ # set up a server which will simulate an alternate package index.
+ p_index = MockServer()
+ if p_index.server_port == 0:
+ # Some platforms (Jython) don't find a port to which to bind,
+ # so skip test for them.
+ pytest.skip("could not find a valid port")
+ p_index.start()
+ return p_index
+
+
class TestDistutilsPackage:
def test_bdist_egg_available_on_distutils_pkg(self, distutils_package):
run_setup('setup.py', ['bdist_egg'])
class TestSetupRequires:
- def test_setup_requires_honors_fetch_params(self):
+
+ def test_setup_requires_honors_fetch_params(self, mock_index, monkeypatch):
"""
When easy_install installs a source distribution which specifies
setup_requires, it should honor the fetch parameters (such as
- allow-hosts, index-url, and find-links).
+ index-url, and find-links).
"""
- # set up a server which will simulate an alternate package index.
- p_index = setuptools.tests.server.MockServer()
- p_index.start()
- netloc = 1
- p_index_loc = urllib.parse.urlparse(p_index.url)[netloc]
- if p_index_loc.endswith(':0'):
- # Some platforms (Jython) don't find a port to which to bind,
- # so skip this test for them.
- return
+ monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
+ monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
with contexts.quiet():
# create an sdist that has a build-time dependency.
with TestSetupRequires.create_sdist() as dist_file:
with contexts.tempdir() as temp_install_dir:
with contexts.environment(PYTHONPATH=temp_install_dir):
ei_params = [
- '--index-url', p_index.url,
- '--allow-hosts', p_index_loc,
+ '--index-url', mock_index.url,
'--exclude-scripts',
'--install-dir', temp_install_dir,
dist_file,
@@ -478,10 +484,8 @@ class TestSetupRequires:
# fail because it doesn't exist.
with pytest.raises(SystemExit):
easy_install_pkg.main(ei_params)
- # there should have been two or three requests to the server
- # (three happens on Python 3.3a)
- assert 2 <= len(p_index.requests) <= 3
- assert p_index.requests[0].path == '/does-not-exist/'
+ # there should have been one requests to the server
+ assert [r.path for r in mock_index.requests] == ['/does-not-exist/']
@staticmethod
@contextlib.contextmanager
@@ -500,7 +504,9 @@ class TestSetupRequires:
version="1.0",
setup_requires = ['does-not-exist'],
)
- """))])
+ """)),
+ ('setup.cfg', ''),
+ ])
yield dist_path
use_setup_cfg = (
@@ -623,7 +629,7 @@ class TestSetupRequires:
test_pkg = create_setup_requires_package(
temp_dir, setup_attrs=dict(version='attr: foobar.version'),
make_package=make_dependency_sdist,
- use_setup_cfg=use_setup_cfg+('version',),
+ use_setup_cfg=use_setup_cfg + ('version',),
)
test_setup_py = os.path.join(test_pkg, 'setup.py')
with contexts.quiet() as (stdout, stderr):
@@ -632,6 +638,208 @@ class TestSetupRequires:
assert len(lines) > 0
assert lines[-1].strip() == '42'
+ def test_setup_requires_honors_pip_env(self, mock_index, monkeypatch):
+ monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
+ monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
+ monkeypatch.setenv(str('PIP_INDEX_URL'), mock_index.url)
+ with contexts.save_pkg_resources_state():
+ with contexts.tempdir() as temp_dir:
+ test_pkg = create_setup_requires_package(
+ temp_dir, 'python-xlib', '0.19',
+ setup_attrs=dict(dependency_links=[]))
+ test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
+ with open(test_setup_cfg, 'w') as fp:
+ fp.write(DALS(
+ '''
+ [easy_install]
+ index_url = https://pypi.org/legacy/
+ '''))
+ test_setup_py = os.path.join(test_pkg, 'setup.py')
+ with pytest.raises(distutils.errors.DistutilsError):
+ run_setup(test_setup_py, [str('--version')])
+ assert len(mock_index.requests) == 1
+ assert mock_index.requests[0].path == '/python-xlib/'
+
+ def test_setup_requires_with_pep508_url(self, mock_index, monkeypatch):
+ monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
+ monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
+ monkeypatch.setenv(str('PIP_INDEX_URL'), mock_index.url)
+ with contexts.save_pkg_resources_state():
+ with contexts.tempdir() as temp_dir:
+ dep_sdist = os.path.join(temp_dir, 'dep.tar.gz')
+ make_trivial_sdist(dep_sdist, 'dependency', '42')
+ dep_url = path_to_url(dep_sdist, authority='localhost')
+ test_pkg = create_setup_requires_package(
+ temp_dir,
+ # Ignored (overriden by setup_attrs)
+ 'python-xlib', '0.19',
+ setup_attrs=dict(
+ setup_requires='dependency @ %s' % dep_url))
+ test_setup_py = os.path.join(test_pkg, 'setup.py')
+ run_setup(test_setup_py, [str('--version')])
+ assert len(mock_index.requests) == 0
+
+ def test_setup_requires_with_allow_hosts(self, mock_index):
+ ''' The `allow-hosts` option in not supported anymore. '''
+ with contexts.save_pkg_resources_state():
+ with contexts.tempdir() as temp_dir:
+ test_pkg = os.path.join(temp_dir, 'test_pkg')
+ test_setup_py = os.path.join(test_pkg, 'setup.py')
+ test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
+ os.mkdir(test_pkg)
+ with open(test_setup_py, 'w') as fp:
+ fp.write(DALS(
+ '''
+ from setuptools import setup
+ setup(setup_requires='python-xlib')
+ '''))
+ with open(test_setup_cfg, 'w') as fp:
+ fp.write(DALS(
+ '''
+ [easy_install]
+ allow_hosts = *
+ '''))
+ with pytest.raises(distutils.errors.DistutilsError):
+ run_setup(test_setup_py, [str('--version')])
+ assert len(mock_index.requests) == 0
+
+ def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir):
+ ''' Check `python_requires` is honored. '''
+ monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
+ monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
+ monkeypatch.setenv(str('PIP_NO_INDEX'), str('1'))
+ monkeypatch.setenv(str('PIP_VERBOSE'), str('1'))
+ dep_1_0_sdist = 'dep-1.0.tar.gz'
+ dep_1_0_url = path_to_url(str(tmpdir / dep_1_0_sdist))
+ dep_1_0_python_requires = '>=2.7'
+ make_python_requires_sdist(
+ str(tmpdir / dep_1_0_sdist), 'dep', '1.0', dep_1_0_python_requires)
+ dep_2_0_sdist = 'dep-2.0.tar.gz'
+ dep_2_0_url = path_to_url(str(tmpdir / dep_2_0_sdist))
+ dep_2_0_python_requires = '!=' + '.'.join(
+ map(str, sys.version_info[:2])) + '.*'
+ make_python_requires_sdist(
+ str(tmpdir / dep_2_0_sdist), 'dep', '2.0', dep_2_0_python_requires)
+ index = tmpdir / 'index.html'
+ index.write_text(DALS(
+ '''
+ <!DOCTYPE html>
+ <html><head><title>Links for dep</title></head>
+ <body>
+ <h1>Links for dep</h1>
+ <a href="{dep_1_0_url}" data-requires-python="{dep_1_0_python_requires}">{dep_1_0_sdist}</a><br/>
+ <a href="{dep_2_0_url}" data-requires-python="{dep_2_0_python_requires}">{dep_2_0_sdist}</a><br/>
+ </body>
+ </html>
+ ''').format( # noqa
+ dep_1_0_url=dep_1_0_url,
+ dep_1_0_sdist=dep_1_0_sdist,
+ dep_1_0_python_requires=dep_1_0_python_requires,
+ dep_2_0_url=dep_2_0_url,
+ dep_2_0_sdist=dep_2_0_sdist,
+ dep_2_0_python_requires=dep_2_0_python_requires,
+ ), 'utf-8')
+ index_url = path_to_url(str(index))
+ with contexts.save_pkg_resources_state():
+ test_pkg = create_setup_requires_package(
+ str(tmpdir),
+ 'python-xlib', '0.19', # Ignored (overriden by setup_attrs).
+ setup_attrs=dict(
+ setup_requires='dep', dependency_links=[index_url]))
+ test_setup_py = os.path.join(test_pkg, 'setup.py')
+ run_setup(test_setup_py, [str('--version')])
+ eggs = list(map(str, pkg_resources.find_distributions(
+ os.path.join(test_pkg, '.eggs'))))
+ assert eggs == ['dep 1.0']
+
+ @pytest.mark.parametrize(
+ 'use_legacy_installer,with_dependency_links_in_setup_py',
+ itertools.product((False, True), (False, True)))
+ def test_setup_requires_with_find_links_in_setup_cfg(
+ self, monkeypatch, use_legacy_installer,
+ with_dependency_links_in_setup_py):
+ monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
+ monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
+ with contexts.save_pkg_resources_state():
+ with contexts.tempdir() as temp_dir:
+ make_trivial_sdist(
+ os.path.join(temp_dir, 'python-xlib-42.tar.gz'),
+ 'python-xlib',
+ '42')
+ test_pkg = os.path.join(temp_dir, 'test_pkg')
+ test_setup_py = os.path.join(test_pkg, 'setup.py')
+ test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
+ os.mkdir(test_pkg)
+ with open(test_setup_py, 'w') as fp:
+ if with_dependency_links_in_setup_py:
+ dependency_links = [os.path.join(temp_dir, 'links')]
+ else:
+ dependency_links = []
+ fp.write(DALS(
+ '''
+ from setuptools import installer, setup
+ if {use_legacy_installer}:
+ installer.fetch_build_egg = installer._legacy_fetch_build_egg
+ setup(setup_requires='python-xlib==42',
+ dependency_links={dependency_links!r})
+ ''').format(use_legacy_installer=use_legacy_installer, # noqa
+ dependency_links=dependency_links))
+ with open(test_setup_cfg, 'w') as fp:
+ fp.write(DALS(
+ '''
+ [easy_install]
+ index_url = {index_url}
+ find_links = {find_links}
+ ''').format(index_url=os.path.join(temp_dir, 'index'),
+ find_links=temp_dir))
+ run_setup(test_setup_py, [str('--version')])
+
+ def test_setup_requires_with_transitive_extra_dependency(
+ self, monkeypatch):
+ # Use case: installing a package with a build dependency on
+ # an already installed `dep[extra]`, which in turn depends
+ # on `extra_dep` (whose is not already installed).
+ with contexts.save_pkg_resources_state():
+ with contexts.tempdir() as temp_dir:
+ # Create source distribution for `extra_dep`.
+ make_trivial_sdist(
+ os.path.join(temp_dir, 'extra_dep-1.0.tar.gz'),
+ 'extra_dep', '1.0')
+ # Create source tree for `dep`.
+ dep_pkg = os.path.join(temp_dir, 'dep')
+ os.mkdir(dep_pkg)
+ build_files({
+ 'setup.py':
+ DALS("""
+ import setuptools
+ setuptools.setup(
+ name='dep', version='2.0',
+ extras_require={'extra': ['extra_dep']},
+ )
+ """),
+ 'setup.cfg': '',
+ }, prefix=dep_pkg)
+ # "Install" dep.
+ run_setup(
+ os.path.join(dep_pkg, 'setup.py'), [str('dist_info')])
+ working_set.add_entry(dep_pkg)
+ # Create source tree for test package.
+ test_pkg = os.path.join(temp_dir, 'test_pkg')
+ test_setup_py = os.path.join(test_pkg, 'setup.py')
+ os.mkdir(test_pkg)
+ with open(test_setup_py, 'w') as fp:
+ fp.write(DALS(
+ '''
+ from setuptools import installer, setup
+ setup(setup_requires='dep[extra]')
+ '''))
+ # Check...
+ monkeypatch.setenv(str('PIP_FIND_LINKS'), str(temp_dir))
+ monkeypatch.setenv(str('PIP_NO_INDEX'), str('1'))
+ monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
+ monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
+ run_setup(test_setup_py, [str('--version')])
+
def make_trivial_sdist(dist_path, distname, version):
"""
@@ -647,7 +855,9 @@ def make_trivial_sdist(dist_path, distname, version):
name=%r,
version=%r
)
- """ % (distname, version)))])
+ """ % (distname, version))),
+ ('setup.cfg', ''),
+ ])
def make_nspkg_sdist(dist_path, distname, version):
@@ -683,12 +893,32 @@ def make_nspkg_sdist(dist_path, distname, version):
make_sdist(dist_path, files)
+def make_python_requires_sdist(dist_path, distname, version, python_requires):
+ make_sdist(dist_path, [
+ (
+ 'setup.py',
+ DALS("""\
+ import setuptools
+ setuptools.setup(
+ name={name!r},
+ version={version!r},
+ python_requires={python_requires!r},
+ )
+ """).format(
+ name=distname, version=version,
+ python_requires=python_requires)),
+ ('setup.cfg', ''),
+ ])
+
+
def make_sdist(dist_path, files):
"""
Create a simple sdist tarball at dist_path, containing the files
listed in ``files`` as ``(filename, content)`` tuples.
"""
+ # Distributions with only one file don't play well with pip.
+ assert len(files) > 1
with tarfile.open(dist_path, 'w:gz') as dist:
for filename, content in files:
file_bytes = io.BytesIO(content.encode('utf-8'))
@@ -721,8 +951,8 @@ def create_setup_requires_package(path, distname='foobar', version='0.1',
test_pkg = os.path.join(path, 'test_pkg')
os.mkdir(test_pkg)
+ # setup.cfg
if use_setup_cfg:
- test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
options = []
metadata = []
for name in use_setup_cfg:
@@ -734,27 +964,29 @@ def create_setup_requires_package(path, distname='foobar', version='0.1',
if isinstance(value, (tuple, list)):
value = ';'.join(value)
section.append('%s: %s' % (name, value))
- with open(test_setup_cfg, 'w') as f:
- f.write(DALS(
- """
- [metadata]
- {metadata}
- [options]
- {options}
- """
- ).format(
- options='\n'.join(options),
- metadata='\n'.join(metadata),
- ))
-
- test_setup_py = os.path.join(test_pkg, 'setup.py')
+ test_setup_cfg_contents = DALS(
+ """
+ [metadata]
+ {metadata}
+ [options]
+ {options}
+ """
+ ).format(
+ options='\n'.join(options),
+ metadata='\n'.join(metadata),
+ )
+ else:
+ test_setup_cfg_contents = ''
+ with open(os.path.join(test_pkg, 'setup.cfg'), 'w') as f:
+ f.write(test_setup_cfg_contents)
+ # setup.py
if setup_py_template is None:
setup_py_template = DALS("""\
import setuptools
setuptools.setup(**%r)
""")
- with open(test_setup_py, 'w') as f:
+ with open(os.path.join(test_pkg, 'setup.py'), 'w') as f:
f.write(setup_py_template % test_setup_attrs)
foobar_path = os.path.join(path, '%s-%s.tar.gz' % (distname, version))
diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py
index 316eb2ed..109f9135 100644
--- a/setuptools/tests/test_egg_info.py
+++ b/setuptools/tests/test_egg_info.py
@@ -524,28 +524,28 @@ class TestEggInfo:
[metadata]
license_file = LICENSE
"""),
- 'LICENSE': DALS("Test license")
- }, True), # with license
+ 'LICENSE': "Test license"
+ }, True), # with license
({
'setup.cfg': DALS("""
[metadata]
license_file = INVALID_LICENSE
"""),
- 'LICENSE': DALS("Test license")
- }, False), # with an invalid license
+ 'LICENSE': "Test license"
+ }, False), # with an invalid license
({
'setup.cfg': DALS("""
"""),
- 'LICENSE': DALS("Test license")
- }, False), # no license_file attribute
+ 'LICENSE': "Test license"
+ }, False), # no license_file attribute
({
'setup.cfg': DALS("""
[metadata]
license_file = LICENSE
"""),
- 'MANIFEST.in': DALS("exclude LICENSE"),
- 'LICENSE': DALS("Test license")
- }, False) # license file is manually excluded
+ 'MANIFEST.in': "exclude LICENSE",
+ 'LICENSE': "Test license"
+ }, False) # license file is manually excluded
])
def test_setup_cfg_license_file(
self, tmpdir_cwd, env, files, license_in_sources):
@@ -565,7 +565,211 @@ class TestEggInfo:
assert 'LICENSE' in sources_text
else:
assert 'LICENSE' not in sources_text
- assert 'INVALID_LICENSE' not in sources_text # for invalid license test
+ # for invalid license test
+ assert 'INVALID_LICENSE' not in sources_text
+
+ @pytest.mark.parametrize("files, incl_licenses, excl_licenses", [
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_files =
+ LICENSE-ABC
+ LICENSE-XYZ
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-XYZ': "XYZ license"
+ }, ['LICENSE-ABC', 'LICENSE-XYZ'], []), # with licenses
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_files = LICENSE-ABC, LICENSE-XYZ
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-XYZ': "XYZ license"
+ }, ['LICENSE-ABC', 'LICENSE-XYZ'], []), # with commas
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_files =
+ LICENSE-ABC
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-XYZ': "XYZ license"
+ }, ['LICENSE-ABC'], ['LICENSE-XYZ']), # with one license
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_files =
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-XYZ': "XYZ license"
+ }, [], ['LICENSE-ABC', 'LICENSE-XYZ']), # empty
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_files = LICENSE-XYZ
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-XYZ': "XYZ license"
+ }, ['LICENSE-XYZ'], ['LICENSE-ABC']), # on same line
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_files =
+ LICENSE-ABC
+ INVALID_LICENSE
+ """),
+ 'LICENSE-ABC': "Test license"
+ }, ['LICENSE-ABC'], ['INVALID_LICENSE']), # with an invalid license
+ ({
+ 'setup.cfg': DALS("""
+ """),
+ 'LICENSE': "Test license"
+ }, [], ['LICENSE']), # no license_files attribute
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_files = LICENSE
+ """),
+ 'MANIFEST.in': "exclude LICENSE",
+ 'LICENSE': "Test license"
+ }, [], ['LICENSE']), # license file is manually excluded
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_files =
+ LICENSE-ABC
+ LICENSE-XYZ
+ """),
+ 'MANIFEST.in': "exclude LICENSE-XYZ",
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-XYZ': "XYZ license"
+ }, ['LICENSE-ABC'], ['LICENSE-XYZ']) # subset is manually excluded
+ ])
+ def test_setup_cfg_license_files(
+ self, tmpdir_cwd, env, files, incl_licenses, excl_licenses):
+ self._create_project()
+ build_files(files)
+
+ environment.run_setup_py(
+ cmd=['egg_info'],
+ pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)])
+ )
+ egg_info_dir = os.path.join('.', 'foo.egg-info')
+
+ with open(os.path.join(egg_info_dir, 'SOURCES.txt')) as sources_file:
+ sources_lines = list(line.strip() for line in sources_file)
+
+ for lf in incl_licenses:
+ assert sources_lines.count(lf) == 1
+
+ for lf in excl_licenses:
+ assert sources_lines.count(lf) == 0
+
+ @pytest.mark.parametrize("files, incl_licenses, excl_licenses", [
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_file =
+ license_files =
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-XYZ': "XYZ license"
+ }, [], ['LICENSE-ABC', 'LICENSE-XYZ']), # both empty
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_file =
+ LICENSE-ABC
+ LICENSE-XYZ
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-XYZ': "XYZ license"
+ # license_file is still singular
+ }, [], ['LICENSE-ABC', 'LICENSE-XYZ']),
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_file = LICENSE-ABC
+ license_files =
+ LICENSE-XYZ
+ LICENSE-PQR
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-PQR': "PQR license",
+ 'LICENSE-XYZ': "XYZ license"
+ }, ['LICENSE-ABC', 'LICENSE-PQR', 'LICENSE-XYZ'], []), # combined
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_file = LICENSE-ABC
+ license_files =
+ LICENSE-ABC
+ LICENSE-XYZ
+ LICENSE-PQR
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-PQR': "PQR license",
+ 'LICENSE-XYZ': "XYZ license"
+ # duplicate license
+ }, ['LICENSE-ABC', 'LICENSE-PQR', 'LICENSE-XYZ'], []),
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_file = LICENSE-ABC
+ license_files =
+ LICENSE-XYZ
+ """),
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-PQR': "PQR license",
+ 'LICENSE-XYZ': "XYZ license"
+ # combined subset
+ }, ['LICENSE-ABC', 'LICENSE-XYZ'], ['LICENSE-PQR']),
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_file = LICENSE-ABC
+ license_files =
+ LICENSE-XYZ
+ LICENSE-PQR
+ """),
+ 'LICENSE-PQR': "Test license"
+ # with invalid licenses
+ }, ['LICENSE-PQR'], ['LICENSE-ABC', 'LICENSE-XYZ']),
+ ({
+ 'setup.cfg': DALS("""
+ [metadata]
+ license_file = LICENSE-ABC
+ license_files =
+ LICENSE-PQR
+ LICENSE-XYZ
+ """),
+ 'MANIFEST.in': "exclude LICENSE-ABC\nexclude LICENSE-PQR",
+ 'LICENSE-ABC': "ABC license",
+ 'LICENSE-PQR': "PQR license",
+ 'LICENSE-XYZ': "XYZ license"
+ # manually excluded
+ }, ['LICENSE-XYZ'], ['LICENSE-ABC', 'LICENSE-PQR'])
+ ])
+ def test_setup_cfg_license_file_license_files(
+ self, tmpdir_cwd, env, files, incl_licenses, excl_licenses):
+ self._create_project()
+ build_files(files)
+
+ environment.run_setup_py(
+ cmd=['egg_info'],
+ pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)])
+ )
+ egg_info_dir = os.path.join('.', 'foo.egg-info')
+
+ with open(os.path.join(egg_info_dir, 'SOURCES.txt')) as sources_file:
+ sources_lines = list(line.strip() for line in sources_file)
+
+ for lf in incl_licenses:
+ assert sources_lines.count(lf) == 1
+
+ for lf in excl_licenses:
+ assert sources_lines.count(lf) == 0
def test_long_description_content_type(self, tmpdir_cwd, env):
# Test that specifying a `long_description_content_type` keyword arg to
diff --git a/setuptools/tests/test_glibc.py b/setuptools/tests/test_glibc.py
deleted file mode 100644
index 795fdc56..00000000
--- a/setuptools/tests/test_glibc.py
+++ /dev/null
@@ -1,52 +0,0 @@
-import warnings
-
-import pytest
-
-from setuptools.glibc import check_glibc_version
-
-__metaclass__ = type
-
-
-@pytest.fixture(params=[
- "2.20",
- # used by "linaro glibc", see gh-3588
- "2.20-2014.11",
- # weird possibilities that I just made up
- "2.20+dev",
- "2.20-custom",
- "2.20.1",
- ])
-def two_twenty(request):
- return request.param
-
-
-@pytest.fixture(params=["asdf", "", "foo.bar"])
-def bad_string(request):
- return request.param
-
-
-class TestGlibc:
- def test_manylinux1_check_glibc_version(self, two_twenty):
- """
- Test that the check_glibc_version function is robust against weird
- glibc version strings.
- """
- assert check_glibc_version(two_twenty, 2, 15)
- assert check_glibc_version(two_twenty, 2, 20)
- assert not check_glibc_version(two_twenty, 2, 21)
- assert not check_glibc_version(two_twenty, 3, 15)
- assert not check_glibc_version(two_twenty, 1, 15)
-
- def test_bad_versions(self, bad_string):
- """
- For unparseable strings, warn and return False
- """
- with warnings.catch_warnings(record=True) as ws:
- warnings.filterwarnings("always")
- assert not check_glibc_version(bad_string, 2, 5)
- for w in ws:
- if "Expected glibc version with" in str(w.message):
- break
- else:
- # Didn't find the warning we were expecting
- assert False
diff --git a/setuptools/tests/test_integration.py b/setuptools/tests/test_integration.py
index 1c0b2b18..f1a27f8b 100644
--- a/setuptools/tests/test_integration.py
+++ b/setuptools/tests/test_integration.py
@@ -64,7 +64,7 @@ def install_context(request, tmpdir, monkeypatch):
monkeypatch.setattr('site.USER_BASE', user_base.strpath)
monkeypatch.setattr('site.USER_SITE', user_site.strpath)
monkeypatch.setattr('sys.path', sys.path + [install_dir.strpath])
- monkeypatch.setenv('PYTHONPATH', os.path.pathsep.join(sys.path))
+ monkeypatch.setenv(str('PYTHONPATH'), str(os.path.pathsep.join(sys.path)))
# Set up the command for performing the installation.
dist = Distribution()
diff --git a/setuptools/tests/test_msvc14.py b/setuptools/tests/test_msvc14.py
new file mode 100644
index 00000000..7833aab4
--- /dev/null
+++ b/setuptools/tests/test_msvc14.py
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+"""
+Tests for msvc support module (msvc14 unit tests).
+"""
+
+import os
+from distutils.errors import DistutilsPlatformError
+import pytest
+import sys
+
+
+@pytest.mark.skipif(sys.platform != "win32",
+ reason="These tests are only for win32")
+class TestMSVC14:
+ """Python 3.8 "distutils/tests/test_msvccompiler.py" backport"""
+ def test_no_compiler(self):
+ import setuptools.msvc as _msvccompiler
+ # makes sure query_vcvarsall raises
+ # a DistutilsPlatformError if the compiler
+ # is not found
+
+ def _find_vcvarsall(plat_spec):
+ return None, None
+
+ old_find_vcvarsall = _msvccompiler._msvc14_find_vcvarsall
+ _msvccompiler._msvc14_find_vcvarsall = _find_vcvarsall
+ try:
+ pytest.raises(DistutilsPlatformError,
+ _msvccompiler._msvc14_get_vc_env,
+ 'wont find this version')
+ finally:
+ _msvccompiler._msvc14_find_vcvarsall = old_find_vcvarsall
+
+ @pytest.mark.skipif(sys.version_info[0] < 3,
+ reason="Unicode requires encode/decode on Python 2")
+ def test_get_vc_env_unicode(self):
+ import setuptools.msvc as _msvccompiler
+
+ test_var = 'ṰḖṤṪ┅ṼẨṜ'
+ test_value = '₃⁴₅'
+
+ # Ensure we don't early exit from _get_vc_env
+ old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None)
+ os.environ[test_var] = test_value
+ try:
+ env = _msvccompiler._msvc14_get_vc_env('x86')
+ assert test_var.lower() in env
+ assert test_value == env[test_var.lower()]
+ finally:
+ os.environ.pop(test_var)
+ if old_distutils_use_sdk:
+ os.environ['DISTUTILS_USE_SDK'] = old_distutils_use_sdk
+
+ def test_get_vc2017(self):
+ import setuptools.msvc as _msvccompiler
+
+ # This function cannot be mocked, so pass it if we find VS 2017
+ # and mark it skipped if we do not.
+ version, path = _msvccompiler._msvc14_find_vc2017()
+ if os.environ.get('APPVEYOR_BUILD_WORKER_IMAGE', '') in [
+ 'Visual Studio 2017'
+ ]:
+ assert version
+ if version:
+ assert version >= 15
+ assert os.path.isdir(path)
+ else:
+ pytest.skip("VS 2017 is not installed")
+
+ def test_get_vc2015(self):
+ import setuptools.msvc as _msvccompiler
+
+ # This function cannot be mocked, so pass it if we find VS 2015
+ # and mark it skipped if we do not.
+ version, path = _msvccompiler._msvc14_find_vc2015()
+ if os.environ.get('APPVEYOR_BUILD_WORKER_IMAGE', '') in [
+ 'Visual Studio 2015', 'Visual Studio 2017'
+ ]:
+ assert version
+ if version:
+ assert version >= 14
+ assert os.path.isdir(path)
+ else:
+ pytest.skip("VS 2015 is not installed")
diff --git a/setuptools/tests/test_pep425tags.py b/setuptools/tests/test_pep425tags.py
deleted file mode 100644
index 30afdec7..00000000
--- a/setuptools/tests/test_pep425tags.py
+++ /dev/null
@@ -1,170 +0,0 @@
-import sys
-
-import pytest
-from mock import patch
-
-from setuptools import pep425tags
-
-__metaclass__ = type
-
-
-class TestPEP425Tags:
-
- def mock_get_config_var(self, **kwd):
- """
- Patch sysconfig.get_config_var for arbitrary keys.
- """
- get_config_var = pep425tags.sysconfig.get_config_var
-
- def _mock_get_config_var(var):
- if var in kwd:
- return kwd[var]
- return get_config_var(var)
- return _mock_get_config_var
-
- def abi_tag_unicode(self, flags, config_vars):
- """
- Used to test ABI tags, verify correct use of the `u` flag
- """
- config_vars.update({'SOABI': None})
- base = pep425tags.get_abbr_impl() + pep425tags.get_impl_ver()
-
- if sys.version_info < (3, 3):
- config_vars.update({'Py_UNICODE_SIZE': 2})
- mock_gcf = self.mock_get_config_var(**config_vars)
- with patch(
- 'setuptools.pep425tags.sysconfig.get_config_var',
- mock_gcf):
- abi_tag = pep425tags.get_abi_tag()
- assert abi_tag == base + flags
-
- config_vars.update({'Py_UNICODE_SIZE': 4})
- mock_gcf = self.mock_get_config_var(**config_vars)
- with patch('setuptools.pep425tags.sysconfig.get_config_var',
- mock_gcf):
- abi_tag = pep425tags.get_abi_tag()
- assert abi_tag == base + flags + 'u'
-
- else:
- # On Python >= 3.3, UCS-4 is essentially permanently enabled, and
- # Py_UNICODE_SIZE is None. SOABI on these builds does not include
- # the 'u' so manual SOABI detection should not do so either.
- config_vars.update({'Py_UNICODE_SIZE': None})
- mock_gcf = self.mock_get_config_var(**config_vars)
- with patch('setuptools.pep425tags.sysconfig.get_config_var',
- mock_gcf):
- abi_tag = pep425tags.get_abi_tag()
- assert abi_tag == base + flags
-
- def test_broken_sysconfig(self):
- """
- Test that pep425tags still works when sysconfig is broken.
- Can be a problem on Python 2.7
- Issue #1074.
- """
- def raises_ioerror(var):
- raise IOError("I have the wrong path!")
-
- with patch('setuptools.pep425tags.sysconfig.get_config_var',
- raises_ioerror):
- with pytest.warns(RuntimeWarning):
- assert len(pep425tags.get_supported())
-
- def test_no_hyphen_tag(self):
- """
- Test that no tag contains a hyphen.
- """
- mock_gcf = self.mock_get_config_var(SOABI='cpython-35m-darwin')
-
- with patch('setuptools.pep425tags.sysconfig.get_config_var',
- mock_gcf):
- supported = pep425tags.get_supported()
-
- for (py, abi, plat) in supported:
- assert '-' not in py
- assert '-' not in abi
- assert '-' not in plat
-
- def test_manual_abi_noflags(self):
- """
- Test that no flags are set on a non-PyDebug, non-Pymalloc ABI tag.
- """
- self.abi_tag_unicode('', {'Py_DEBUG': False, 'WITH_PYMALLOC': False})
-
- def test_manual_abi_d_flag(self):
- """
- Test that the `d` flag is set on a PyDebug, non-Pymalloc ABI tag.
- """
- self.abi_tag_unicode('d', {'Py_DEBUG': True, 'WITH_PYMALLOC': False})
-
- def test_manual_abi_m_flag(self):
- """
- Test that the `m` flag is set on a non-PyDebug, Pymalloc ABI tag.
- """
- self.abi_tag_unicode('m', {'Py_DEBUG': False, 'WITH_PYMALLOC': True})
-
- def test_manual_abi_dm_flags(self):
- """
- Test that the `dm` flags are set on a PyDebug, Pymalloc ABI tag.
- """
- self.abi_tag_unicode('dm', {'Py_DEBUG': True, 'WITH_PYMALLOC': True})
-
-
-class TestManylinux1Tags:
-
- @patch('setuptools.pep425tags.get_platform', lambda: 'linux_x86_64')
- @patch('setuptools.glibc.have_compatible_glibc',
- lambda major, minor: True)
- def test_manylinux1_compatible_on_linux_x86_64(self):
- """
- Test that manylinux1 is enabled on linux_x86_64
- """
- assert pep425tags.is_manylinux1_compatible()
-
- @patch('setuptools.pep425tags.get_platform', lambda: 'linux_i686')
- @patch('setuptools.glibc.have_compatible_glibc',
- lambda major, minor: True)
- def test_manylinux1_compatible_on_linux_i686(self):
- """
- Test that manylinux1 is enabled on linux_i686
- """
- assert pep425tags.is_manylinux1_compatible()
-
- @patch('setuptools.pep425tags.get_platform', lambda: 'linux_x86_64')
- @patch('setuptools.glibc.have_compatible_glibc',
- lambda major, minor: False)
- def test_manylinux1_2(self):
- """
- Test that manylinux1 is disabled with incompatible glibc
- """
- assert not pep425tags.is_manylinux1_compatible()
-
- @patch('setuptools.pep425tags.get_platform', lambda: 'arm6vl')
- @patch('setuptools.glibc.have_compatible_glibc',
- lambda major, minor: True)
- def test_manylinux1_3(self):
- """
- Test that manylinux1 is disabled on arm6vl
- """
- assert not pep425tags.is_manylinux1_compatible()
-
- @patch('setuptools.pep425tags.get_platform', lambda: 'linux_x86_64')
- @patch('setuptools.glibc.have_compatible_glibc',
- lambda major, minor: True)
- @patch('sys.platform', 'linux2')
- def test_manylinux1_tag_is_first(self):
- """
- Test that the more specific tag manylinux1 comes first.
- """
- groups = {}
- for pyimpl, abi, arch in pep425tags.get_supported():
- groups.setdefault((pyimpl, abi), []).append(arch)
-
- for arches in groups.values():
- if arches == ['any']:
- continue
- # Expect the most specific arch first:
- if len(arches) == 3:
- assert arches == ['manylinux1_x86_64', 'linux_x86_64', 'any']
- else:
- assert arches == ['manylinux1_x86_64', 'linux_x86_64']
diff --git a/setuptools/tests/test_register.py b/setuptools/tests/test_register.py
index 96114595..98605806 100644
--- a/setuptools/tests/test_register.py
+++ b/setuptools/tests/test_register.py
@@ -1,43 +1,22 @@
-import mock
-from distutils import log
-
-import pytest
-
from setuptools.command.register import register
from setuptools.dist import Distribution
+from setuptools.errors import RemovedCommandError
+try:
+ from unittest import mock
+except ImportError:
+ import mock
-class TestRegisterTest:
- def test_warns_deprecation(self):
- dist = Distribution()
-
- cmd = register(dist)
- cmd.run_command = mock.Mock()
- cmd.send_metadata = mock.Mock()
- cmd.announce = mock.Mock()
-
- cmd.run()
+import pytest
- cmd.announce.assert_called_with(
- "WARNING: Registering is deprecated, use twine to upload instead "
- "(https://pypi.org/p/twine/)",
- log.WARN
- )
- def test_warns_deprecation_when_raising(self):
+class TestRegister:
+ def test_register_exception(self):
+ """Ensure that the register command has been properly removed."""
dist = Distribution()
+ dist.dist_files = [(mock.Mock(), mock.Mock(), mock.Mock())]
cmd = register(dist)
- cmd.run_command = mock.Mock()
- cmd.send_metadata = mock.Mock()
- cmd.send_metadata.side_effect = Exception
- cmd.announce = mock.Mock()
- with pytest.raises(Exception):
+ with pytest.raises(RemovedCommandError):
cmd.run()
-
- cmd.announce.assert_called_with(
- "WARNING: Registering is deprecated, use twine to upload instead "
- "(https://pypi.org/p/twine/)",
- log.WARN
- )
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index d2c4e0cf..0bea53df 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
"""sdist tests"""
+from __future__ import print_function, unicode_literals
+
import os
-import shutil
import sys
import tempfile
import unicodedata
@@ -50,7 +51,7 @@ def quiet():
# Convert to POSIX path
def posix(path):
- if six.PY3 and not isinstance(path, str):
+ if not six.PY2 and not isinstance(path, str):
return path.replace(os.sep.encode('ascii'), b'/')
else:
return path.replace(os.sep, '/')
@@ -89,30 +90,28 @@ fail_on_latin1_encoded_filenames = pytest.mark.xfail(
)
+def touch(path):
+ path.write_text('', encoding='utf-8')
+
+
class TestSdistTest:
- def setup_method(self, method):
- self.temp_dir = tempfile.mkdtemp()
- with open(os.path.join(self.temp_dir, 'setup.py'), 'w') as f:
- f.write(SETUP_PY)
+ @pytest.fixture(autouse=True)
+ def source_dir(self, tmpdir):
+ (tmpdir / 'setup.py').write_text(SETUP_PY, encoding='utf-8')
# Set up the rest of the test package
- test_pkg = os.path.join(self.temp_dir, 'sdist_test')
- os.mkdir(test_pkg)
- data_folder = os.path.join(self.temp_dir, "d")
- os.mkdir(data_folder)
+ test_pkg = tmpdir / 'sdist_test'
+ test_pkg.mkdir()
+ data_folder = tmpdir / 'd'
+ data_folder.mkdir()
# *.rst was not included in package_data, so c.rst should not be
# automatically added to the manifest when not under version control
- for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst',
- os.path.join(data_folder, "e.dat")]:
- # Just touch the files; their contents are irrelevant
- open(os.path.join(test_pkg, fname), 'w').close()
-
- self.old_cwd = os.getcwd()
- os.chdir(self.temp_dir)
+ for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']:
+ touch(test_pkg / fname)
+ touch(data_folder / 'e.dat')
- def teardown_method(self, method):
- os.chdir(self.old_cwd)
- shutil.rmtree(self.temp_dir)
+ with tmpdir.as_cwd():
+ yield
def test_package_data_in_sdist(self):
"""Regression test for pull request #4: ensures that files listed in
@@ -175,14 +174,14 @@ class TestSdistTest:
manifest = cmd.filelist.files
assert 'setup.py' not in manifest
- def test_defaults_case_sensitivity(self):
+ def test_defaults_case_sensitivity(self, tmpdir):
"""
Make sure default files (README.*, etc.) are added in a case-sensitive
way to avoid problems with packages built on Windows.
"""
- open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close()
- open(os.path.join(self.temp_dir, 'SETUP.cfg'), 'w').close()
+ touch(tmpdir / 'readme.rst')
+ touch(tmpdir / 'SETUP.cfg')
dist = Distribution(SETUP_ATTRS)
# the extension deliberately capitalized for this test
@@ -230,10 +229,6 @@ class TestSdistTest:
u_contents = contents.decode('UTF-8')
# The manifest should contain the UTF-8 filename
- if six.PY2:
- fs_enc = sys.getfilesystemencoding()
- filename = filename.decode(fs_enc)
-
assert posix(filename) in u_contents
@py3_only
@@ -334,7 +329,7 @@ class TestSdistTest:
cmd.read_manifest()
# The filelist should contain the UTF-8 filename
- if six.PY3:
+ if not six.PY2:
filename = filename.decode('utf-8')
assert filename in cmd.filelist.files
@@ -374,7 +369,7 @@ class TestSdistTest:
@fail_on_latin1_encoded_filenames
def test_sdist_with_utf8_encoded_filename(self):
# Test for #303.
- dist = Distribution(SETUP_ATTRS)
+ dist = Distribution(self.make_strings(SETUP_ATTRS))
dist.script_name = 'setup.py'
cmd = sdist(dist)
cmd.ensure_finalized()
@@ -388,7 +383,7 @@ class TestSdistTest:
if sys.platform == 'darwin':
filename = decompose(filename)
- if six.PY3:
+ if not six.PY2:
fs_enc = sys.getfilesystemencoding()
if sys.platform == 'win32':
@@ -405,10 +400,19 @@ class TestSdistTest:
else:
assert filename in cmd.filelist.files
+ @classmethod
+ def make_strings(cls, item):
+ if isinstance(item, dict):
+ return {
+ key: cls.make_strings(value) for key, value in item.items()}
+ if isinstance(item, list):
+ return list(map(cls.make_strings, item))
+ return str(item)
+
@fail_on_latin1_encoded_filenames
def test_sdist_with_latin1_encoded_filename(self):
# Test for #303.
- dist = Distribution(SETUP_ATTRS)
+ dist = Distribution(self.make_strings(SETUP_ATTRS))
dist.script_name = 'setup.py'
cmd = sdist(dist)
cmd.ensure_finalized()
@@ -421,7 +425,19 @@ class TestSdistTest:
with quiet():
cmd.run()
- if six.PY3:
+ if six.PY2:
+ # Under Python 2 there seems to be no decoded string in the
+ # filelist. However, due to decode and encoding of the
+ # file name to get utf-8 Manifest the latin1 maybe excluded
+ try:
+ # fs_enc should match how one is expect the decoding to
+ # be proformed for the manifest output.
+ fs_enc = sys.getfilesystemencoding()
+ filename.decode(fs_enc)
+ assert filename in cmd.filelist.files
+ except UnicodeDecodeError:
+ filename not in cmd.filelist.files
+ else:
# not all windows systems have a default FS encoding of cp1252
if sys.platform == 'win32':
# Latin-1 is similar to Windows-1252 however
@@ -436,18 +452,36 @@ class TestSdistTest:
# The Latin-1 filename should have been skipped
filename = filename.decode('latin-1')
filename not in cmd.filelist.files
- else:
- # Under Python 2 there seems to be no decoded string in the
- # filelist. However, due to decode and encoding of the
- # file name to get utf-8 Manifest the latin1 maybe excluded
- try:
- # fs_enc should match how one is expect the decoding to
- # be proformed for the manifest output.
- fs_enc = sys.getfilesystemencoding()
- filename.decode(fs_enc)
- assert filename in cmd.filelist.files
- except UnicodeDecodeError:
- filename not in cmd.filelist.files
+
+ def test_pyproject_toml_in_sdist(self, tmpdir):
+ """
+ Check if pyproject.toml is included in source distribution if present
+ """
+ touch(tmpdir / 'pyproject.toml')
+ dist = Distribution(SETUP_ATTRS)
+ dist.script_name = 'setup.py'
+ cmd = sdist(dist)
+ cmd.ensure_finalized()
+ with quiet():
+ cmd.run()
+ manifest = cmd.filelist.files
+ assert 'pyproject.toml' in manifest
+
+ def test_pyproject_toml_excluded(self, tmpdir):
+ """
+ Check that pyproject.toml can excluded even if present
+ """
+ touch(tmpdir / 'pyproject.toml')
+ with open('MANIFEST.in', 'w') as mts:
+ print('exclude pyproject.toml', file=mts)
+ dist = Distribution(SETUP_ATTRS)
+ dist.script_name = 'setup.py'
+ cmd = sdist(dist)
+ cmd.ensure_finalized()
+ with quiet():
+ cmd.run()
+ manifest = cmd.filelist.files
+ assert 'pyproject.toml' not in manifest
def test_default_revctrl():
diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py
index 3fb04fb4..1b038954 100644
--- a/setuptools/tests/test_setopt.py
+++ b/setuptools/tests/test_setopt.py
@@ -15,7 +15,7 @@ class TestEdit:
def parse_config(filename):
parser = configparser.ConfigParser()
with io.open(filename, encoding='utf-8') as reader:
- (parser.read_file if six.PY3 else parser.readfp)(reader)
+ (parser.readfp if six.PY2 else parser.read_file)(reader)
return parser
@staticmethod
diff --git a/setuptools/tests/test_setuptools.py b/setuptools/tests/test_setuptools.py
index 5896a69a..bca69c30 100644
--- a/setuptools/tests/test_setuptools.py
+++ b/setuptools/tests/test_setuptools.py
@@ -108,6 +108,11 @@ class TestDepends:
assert not req.is_present()
assert not req.is_current()
+ @needs_bytecode
+ def test_require_present(self):
+ # In #1896, this test was failing for months with the only
+ # complaint coming from test runners (not end users).
+ # TODO: Evaluate if this code is needed at all.
req = Require('Tests', None, 'tests', homepage="http://example.com")
assert req.format is None
assert req.attribute is None
@@ -223,10 +228,10 @@ class TestFeatures:
py_modules=['bar_et'], remove=['bar.ext'],
),
'baz': Feature(
- "baz", optional=False, packages=['pkg.baz'],
- scripts=['scripts/baz_it'],
- libraries=[('libfoo', 'foo/foofoo.c')]
- ),
+ "baz", optional=False, packages=['pkg.baz'],
+ scripts=['scripts/baz_it'],
+ libraries=[('libfoo', 'foo/foofoo.c')]
+ ),
'dwim': Feature("DWIM", available=False, remove='bazish'),
},
script_args=['--without-bar', 'install'],
diff --git a/setuptools/tests/test_test.py b/setuptools/tests/test_test.py
index 6242a018..8ee70a7e 100644
--- a/setuptools/tests/test_test.py
+++ b/setuptools/tests/test_test.py
@@ -12,7 +12,7 @@ from setuptools.command.test import test
from setuptools.dist import Distribution
from .textwrap import DALS
-from . import contexts
+
SETUP_PY = DALS("""
from setuptools import setup
diff --git a/setuptools/tests/test_upload.py b/setuptools/tests/test_upload.py
index 320c6959..7586cb26 100644
--- a/setuptools/tests/test_upload.py
+++ b/setuptools/tests/test_upload.py
@@ -1,213 +1,22 @@
-import mock
-import os
-import re
-
-from distutils import log
-from distutils.errors import DistutilsError
-
-import pytest
-
from setuptools.command.upload import upload
from setuptools.dist import Distribution
-from setuptools.extern import six
-
-
-def _parse_upload_body(body):
- boundary = u'\r\n----------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
- entries = []
- name_re = re.compile(u'^Content-Disposition: form-data; name="([^\"]+)"')
-
- for entry in body.split(boundary):
- pair = entry.split(u'\r\n\r\n')
- if not len(pair) == 2:
- continue
-
- key, value = map(six.text_type.strip, pair)
- m = name_re.match(key)
- if m is not None:
- key = m.group(1)
-
- entries.append((key, value))
-
- return entries
-
-
-@pytest.fixture
-def patched_upload(tmpdir):
- class Fix:
- def __init__(self, cmd, urlopen):
- self.cmd = cmd
- self.urlopen = urlopen
-
- def __iter__(self):
- return iter((self.cmd, self.urlopen))
-
- def get_uploaded_metadata(self):
- request = self.urlopen.call_args_list[0][0][0]
- body = request.data.decode('utf-8')
- entries = dict(_parse_upload_body(body))
-
- return entries
+from setuptools.errors import RemovedCommandError
- class ResponseMock(mock.Mock):
- def getheader(self, name, default=None):
- """Mocked getheader method for response object"""
- return {
- 'content-type': 'text/plain; charset=utf-8',
- }.get(name.lower(), default)
+try:
+ from unittest import mock
+except ImportError:
+ import mock
- with mock.patch('setuptools.command.upload.urlopen') as urlopen:
- urlopen.return_value = ResponseMock()
- urlopen.return_value.getcode.return_value = 200
- urlopen.return_value.read.return_value = b''
-
- content = os.path.join(str(tmpdir), "content_data")
-
- with open(content, 'w') as f:
- f.write("Some content")
-
- dist = Distribution()
- dist.dist_files = [('sdist', '3.7.0', content)]
-
- cmd = upload(dist)
- cmd.announce = mock.Mock()
- cmd.username = 'user'
- cmd.password = 'hunter2'
-
- yield Fix(cmd, urlopen)
-
-
-class TestUploadTest:
- def test_upload_metadata(self, patched_upload):
- cmd, patch = patched_upload
-
- # Set the metadata version to 2.1
- cmd.distribution.metadata.metadata_version = '2.1'
-
- # Run the command
- cmd.ensure_finalized()
- cmd.run()
-
- # Make sure we did the upload
- patch.assert_called_once()
-
- # Make sure the metadata version is correct in the headers
- entries = patched_upload.get_uploaded_metadata()
- assert entries['metadata_version'] == '2.1'
-
- def test_warns_deprecation(self):
- dist = Distribution()
- dist.dist_files = [(mock.Mock(), mock.Mock(), mock.Mock())]
-
- cmd = upload(dist)
- cmd.upload_file = mock.Mock()
- cmd.announce = mock.Mock()
-
- cmd.run()
+import pytest
- cmd.announce.assert_called_once_with(
- "WARNING: Uploading via this command is deprecated, use twine to "
- "upload instead (https://pypi.org/p/twine/)",
- log.WARN
- )
- def test_warns_deprecation_when_raising(self):
+class TestUpload:
+ def test_upload_exception(self):
+ """Ensure that the register command has been properly removed."""
dist = Distribution()
dist.dist_files = [(mock.Mock(), mock.Mock(), mock.Mock())]
cmd = upload(dist)
- cmd.upload_file = mock.Mock()
- cmd.upload_file.side_effect = Exception
- cmd.announce = mock.Mock()
-
- with pytest.raises(Exception):
- cmd.run()
-
- cmd.announce.assert_called_once_with(
- "WARNING: Uploading via this command is deprecated, use twine to "
- "upload instead (https://pypi.org/p/twine/)",
- log.WARN
- )
-
- @pytest.mark.parametrize('url', [
- 'https://example.com/a;parameter', # Has parameters
- 'https://example.com/a?query', # Has query
- 'https://example.com/a#fragment', # Has fragment
- 'ftp://example.com', # Invalid scheme
-
- ])
- def test_upload_file_invalid_url(self, url, patched_upload):
- patched_upload.urlopen.side_effect = Exception("Should not be reached")
-
- cmd = patched_upload.cmd
- cmd.repository = url
-
- cmd.ensure_finalized()
- with pytest.raises(AssertionError):
- cmd.run()
-
- def test_upload_file_http_error(self, patched_upload):
- patched_upload.urlopen.side_effect = six.moves.urllib.error.HTTPError(
- 'https://example.com',
- 404,
- 'File not found',
- None,
- None
- )
-
- cmd = patched_upload.cmd
- cmd.ensure_finalized()
- with pytest.raises(DistutilsError):
+ with pytest.raises(RemovedCommandError):
cmd.run()
-
- cmd.announce.assert_any_call(
- 'Upload failed (404): File not found',
- log.ERROR)
-
- def test_upload_file_os_error(self, patched_upload):
- patched_upload.urlopen.side_effect = OSError("Invalid")
-
- cmd = patched_upload.cmd
- cmd.ensure_finalized()
-
- with pytest.raises(OSError):
- cmd.run()
-
- cmd.announce.assert_any_call('Invalid', log.ERROR)
-
- @mock.patch('setuptools.command.upload.spawn')
- def test_upload_file_gpg(self, spawn, patched_upload):
- cmd, urlopen = patched_upload
-
- cmd.sign = True
- cmd.identity = "Alice"
- cmd.dry_run = True
- content_fname = cmd.distribution.dist_files[0][2]
- signed_file = content_fname + '.asc'
-
- with open(signed_file, 'wb') as f:
- f.write("signed-data".encode('utf-8'))
-
- cmd.ensure_finalized()
- cmd.run()
-
- # Make sure that GPG was called
- spawn.assert_called_once_with([
- "gpg", "--detach-sign", "--local-user", "Alice", "-a",
- content_fname
- ], dry_run=True)
-
- # Read the 'signed' data that was transmitted
- entries = patched_upload.get_uploaded_metadata()
- assert entries['gpg_signature'] == 'signed-data'
-
- def test_show_response_no_error(self, patched_upload):
- # This test is just that show_response doesn't throw an error
- # It is not really important what the printed response looks like
- # in a deprecated command, but we don't want to introduce new
- # errors when importing this function from distutils
-
- patched_upload.cmd.show_response = True
- patched_upload.cmd.ensure_finalized()
- patched_upload.cmd.run()
diff --git a/setuptools/tests/test_virtualenv.py b/setuptools/tests/test_virtualenv.py
index 74a1284c..6549a6c0 100644
--- a/setuptools/tests/test_virtualenv.py
+++ b/setuptools/tests/test_virtualenv.py
@@ -8,13 +8,22 @@ from pytest_fixture_config import yield_requires_config
import pytest_virtualenv
-from setuptools.extern import six
-
from .textwrap import DALS
from .test_easy_install import make_nspkg_sdist
@pytest.fixture(autouse=True)
+def disable_requires_python(monkeypatch):
+ """
+ Disable Requires-Python on Python 2.7
+ """
+ if sys.version_info > (3,):
+ return
+
+ monkeypatch.setenv('PIP_IGNORE_REQUIRES_PYTHON', 'true')
+
+
+@pytest.fixture(autouse=True)
def pytest_virtualenv_works(virtualenv):
"""
pytest_virtualenv may not work. if it doesn't, skip these
@@ -64,7 +73,7 @@ def _get_pip_versions():
from urllib.request import urlopen
from urllib.error import URLError
except ImportError:
- from urllib2 import urlopen, URLError # Python 2.7 compat
+ from urllib2 import urlopen, URLError # Python 2.7 compat
try:
urlopen('https://pypi.org', timeout=1)
@@ -77,12 +86,9 @@ def _get_pip_versions():
'pip==10.0.1',
'pip==18.1',
'pip==19.0.1',
+ 'https://github.com/pypa/pip/archive/master.zip',
]
- # Pip's master dropped support for 3.4.
- if not six.PY34:
- network_versions.append('https://github.com/pypa/pip/archive/master.zip')
-
versions = [None] + [
pytest.param(v, **({} if network else {'marks': pytest.mark.skip}))
for v in network_versions
@@ -121,14 +127,12 @@ def test_pip_upgrade_from_source(pip_version, virtualenv):
virtualenv.run('pip install --no-cache-dir --upgrade ' + sdist)
-def test_test_command_install_requirements(bare_virtualenv, tmpdir):
+def _check_test_command_install_requirements(virtualenv, tmpdir):
"""
Check the test command will install all required dependencies.
"""
- bare_virtualenv.run(' && '.join((
- 'cd {source}',
- 'python setup.py develop',
- )).format(source=SOURCE_DIR))
+ # Install setuptools.
+ virtualenv.run('python setup.py develop', cd=SOURCE_DIR)
def sdist(distname, version):
dist_path = tmpdir.join('%s-%s.tar.gz' % (distname, version))
@@ -179,13 +183,25 @@ def test_test_command_install_requirements(bare_virtualenv, tmpdir):
open('success', 'w').close()
'''))
# Run test command for test package.
- bare_virtualenv.run(' && '.join((
+ virtualenv.run(' && '.join((
'cd {tmpdir}',
'python setup.py test -s test',
)).format(tmpdir=tmpdir))
assert tmpdir.join('success').check()
+def test_test_command_install_requirements(virtualenv, tmpdir):
+ # Ensure pip/wheel packages are installed.
+ virtualenv.run(
+ "python -c \"__import__('pkg_resources').require(['pip', 'wheel'])\"")
+ _check_test_command_install_requirements(virtualenv, tmpdir)
+
+
+def test_test_command_install_requirements_when_using_easy_install(
+ bare_virtualenv, tmpdir):
+ _check_test_command_install_requirements(bare_virtualenv, tmpdir)
+
+
def test_no_missing_dependencies(bare_virtualenv):
"""
Quick and dirty test to ensure all external dependencies are vendored.
diff --git a/setuptools/tests/test_wheel.py b/setuptools/tests/test_wheel.py
index e85a4a7e..f72ccbbf 100644
--- a/setuptools/tests/test_wheel.py
+++ b/setuptools/tests/test_wheel.py
@@ -18,6 +18,7 @@ import pytest
from pkg_resources import Distribution, PathMetadata, PY_MAJOR
from setuptools.extern.packaging.utils import canonicalize_name
+from setuptools.extern.packaging.tags import parse_tag
from setuptools.wheel import Wheel
from .contexts import tempdir
@@ -124,11 +125,12 @@ def flatten_tree(tree):
def format_install_tree(tree):
- return {x.format(
- py_version=PY_MAJOR,
- platform=get_platform(),
- shlib_ext=get_config_var('EXT_SUFFIX') or get_config_var('SO'))
- for x in tree}
+ return {
+ x.format(
+ py_version=PY_MAJOR,
+ platform=get_platform(),
+ shlib_ext=get_config_var('EXT_SUFFIX') or get_config_var('SO'))
+ for x in tree}
def _check_wheel_install(filename, install_dir, install_tree_includes,
@@ -451,6 +453,35 @@ WHEEL_INSTALL_TESTS = (
),
dict(
+ id='empty_namespace_package',
+ file_defs={
+ 'foobar': {
+ '__init__.py':
+ "__import__('pkg_resources').declare_namespace(__name__)",
+ },
+ },
+ setup_kwargs=dict(
+ namespace_packages=['foobar'],
+ packages=['foobar'],
+ ),
+ install_tree=flatten_tree({
+ 'foo-1.0-py{py_version}.egg': [
+ 'foo-1.0-py{py_version}-nspkg.pth',
+ {'EGG-INFO': [
+ 'PKG-INFO',
+ 'RECORD',
+ 'WHEEL',
+ 'namespace_packages.txt',
+ 'top_level.txt',
+ ]},
+ {'foobar': [
+ '__init__.py',
+ ]},
+ ]
+ }),
+ ),
+
+ dict(
id='data_in_package',
file_defs={
'foo': {
@@ -543,3 +574,12 @@ def test_wheel_no_dist_dir():
_check_wheel_install(wheel_path, install_dir, None,
project_name,
version, None)
+
+
+def test_wheel_is_compatible(monkeypatch):
+ def sys_tags():
+ for t in parse_tag('cp36-cp36m-manylinux1_x86_64'):
+ yield t
+ monkeypatch.setattr('setuptools.wheel.sys_tags', sys_tags)
+ assert Wheel(
+ 'onnxruntime-0.1.2-cp36-cp36m-manylinux1_x86_64.whl').is_compatible()