aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests
diff options
context:
space:
mode:
authorCarsten Klein <trancesilken@gmail.com>2018-08-17 14:58:35 +0200
committerPaul Ganssle <pganssle@users.noreply.github.com>2018-08-17 08:58:35 -0400
commit0254a2fda8e8bd4f289d01e2179191e936517f04 (patch)
tree6007c5bc0b659c4d69ffbcc8df917f7a0c747cdf /setuptools/tests
parentbbf99b7e599766e15dc56f58f68fe6c32c972faf (diff)
downloadexternal_python_setuptools-0254a2fda8e8bd4f289d01e2179191e936517f04.tar.gz
external_python_setuptools-0254a2fda8e8bd4f289d01e2179191e936517f04.tar.bz2
external_python_setuptools-0254a2fda8e8bd4f289d01e2179191e936517f04.zip
Rename find_namepaces_ns to find_namespace_packages (#1423)
* fix #1419 PEP420: add find_namespace: directive * fix #1419 PEP420: add find_namespace: directive to documentation * fix #1419 PEP420: add tests * fix #1419 PEP420: clean up code * fix #1419 PEP420: fix typo in documentation * fix #1419 PEP420: fix typo in documentation * fix #1419 PEP420: clean up code * fix #1419 PEP420: add changelog entry * fixup! fix #1419 PEP420: add tests * fix #1419 PEP420: cleanup code refactor markers * #1420: Rename find_namespace_ns to find_namespace_packages * #1420: update changelog entry
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/__init__.py12
-rw-r--r--setuptools/tests/test_config.py64
-rw-r--r--setuptools/tests/test_find_packages.py16
3 files changed, 80 insertions, 12 deletions
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index 54dd7d2b..5f4a1c29 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -2,5 +2,17 @@ import locale
import pytest
+from setuptools.extern.six import PY2, PY3
+
+
+__all__ = [
+ 'fail_on_ascii', 'py2_only', 'py3_only'
+]
+
+
is_ascii = locale.getpreferredencoding() == 'ANSI_X3.4-1968'
fail_on_ascii = pytest.mark.xfail(is_ascii, reason="Test fails in this locale")
+
+
+py2_only = pytest.mark.skipif(not PY2, reason="Test runs on Python 2 only")
+py3_only = pytest.mark.skipif(not PY3, reason="Test runs on Python 3 only")
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py
index 19b37633..acf22154 100644
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -4,18 +4,20 @@ from distutils.errors import DistutilsOptionError, DistutilsFileError
from mock import patch
from setuptools.dist import Distribution, _Distribution
from setuptools.config import ConfigHandler, read_configuration
-
+from . import py2_only, py3_only
class ErrConfigHandler(ConfigHandler):
"""Erroneous handler. Fails to implement required methods."""
-def make_package_dir(name, base_dir):
+def make_package_dir(name, base_dir, ns=False):
dir_package = base_dir
for dir_name in name.split('/'):
dir_package = dir_package.mkdir(dir_name)
- init_file = dir_package.join('__init__.py')
- init_file.write('')
+ init_file = None
+ if not ns:
+ init_file = dir_package.join('__init__.py')
+ init_file.write('')
return dir_package, init_file
@@ -596,6 +598,60 @@ class TestOptions:
assert set(dist.packages) == set(
['fake_package', 'fake_package.sub_two'])
+ @py2_only
+ def test_find_namespace_directive_fails_on_py2(self, tmpdir):
+ dir_package, config = fake_env(
+ tmpdir,
+ '[options]\n'
+ 'packages = find_namespace:\n'
+ )
+
+ with pytest.raises(DistutilsOptionError):
+ with get_dist(tmpdir) as dist:
+ dist.parse_config_files()
+
+ @py3_only
+ def test_find_namespace_directive(self, tmpdir):
+ dir_package, config = fake_env(
+ tmpdir,
+ '[options]\n'
+ 'packages = find_namespace:\n'
+ )
+
+ dir_sub_one, _ = make_package_dir('sub_one', dir_package)
+ dir_sub_two, _ = make_package_dir('sub_two', dir_package, ns=True)
+
+ with get_dist(tmpdir) as dist:
+ assert set(dist.packages) == {
+ 'fake_package', 'fake_package.sub_two', 'fake_package.sub_one'
+ }
+
+ config.write(
+ '[options]\n'
+ 'packages = find_namespace:\n'
+ '\n'
+ '[options.packages.find]\n'
+ 'where = .\n'
+ 'include =\n'
+ ' fake_package.sub_one\n'
+ ' two\n'
+ )
+ with get_dist(tmpdir) as dist:
+ assert dist.packages == ['fake_package.sub_one']
+
+ config.write(
+ '[options]\n'
+ 'packages = find_namespace:\n'
+ '\n'
+ '[options.packages.find]\n'
+ 'exclude =\n'
+ ' fake_package.sub_one\n'
+ )
+ with get_dist(tmpdir) as dist:
+ assert set(dist.packages) == {
+ 'fake_package', 'fake_package.sub_two'
+ }
+
def test_extras_require(self, tmpdir):
fake_env(
tmpdir,
diff --git a/setuptools/tests/test_find_packages.py b/setuptools/tests/test_find_packages.py
index 02ae5a94..b08f91c7 100644
--- a/setuptools/tests/test_find_packages.py
+++ b/setuptools/tests/test_find_packages.py
@@ -7,12 +7,12 @@ import platform
import pytest
+from . import py3_only
+
from setuptools.extern.six import PY3
from setuptools import find_packages
-
-py3_only = pytest.mark.xfail(not PY3, reason="Test runs on Python 3 only")
if PY3:
- from setuptools import find_packages_ns
+ from setuptools import find_namespace_packages
# modeled after CPython's test.support.can_symlink
@@ -156,26 +156,26 @@ class TestFindPackages:
@py3_only
def test_pep420_ns_package(self):
- packages = find_packages_ns(
+ packages = find_namespace_packages(
self.dist_dir, include=['pkg*'], exclude=['pkg.subpkg.assets'])
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
@py3_only
def test_pep420_ns_package_no_includes(self):
- packages = find_packages_ns(
+ packages = find_namespace_packages(
self.dist_dir, exclude=['pkg.subpkg.assets'])
self._assert_packages(packages, ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg'])
@py3_only
def test_pep420_ns_package_no_includes_or_excludes(self):
- packages = find_packages_ns(self.dist_dir)
+ packages = find_namespace_packages(self.dist_dir)
expected = ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg', 'pkg.subpkg.assets']
self._assert_packages(packages, expected)
@py3_only
def test_regular_package_with_nested_pep420_ns_packages(self):
self._touch('__init__.py', self.pkg_dir)
- packages = find_packages_ns(
+ packages = find_namespace_packages(
self.dist_dir, exclude=['docs', 'pkg.subpkg.assets'])
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
@@ -183,6 +183,6 @@ class TestFindPackages:
def test_pep420_ns_package_no_non_package_dirs(self):
shutil.rmtree(self.docs_dir)
shutil.rmtree(os.path.join(self.dist_dir, 'pkg/subpkg/assets'))
- packages = find_packages_ns(self.dist_dir)
+ packages = find_namespace_packages(self.dist_dir)
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])