diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2017-10-12 10:14:43 +0200 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2017-10-12 10:14:43 +0200 |
commit | 5a0f4b9784a35e514f53ea08adb29d999f511cac (patch) | |
tree | c532933d1aa5c538efa7f71bd3771586856ecafe /setuptools/tests/test_build_meta.py | |
parent | 3e8bb3bcc17f349a20bf70c2678a154d8ff693b6 (diff) | |
download | external_python_setuptools-5a0f4b9784a35e514f53ea08adb29d999f511cac.tar.gz external_python_setuptools-5a0f4b9784a35e514f53ea08adb29d999f511cac.tar.bz2 external_python_setuptools-5a0f4b9784a35e514f53ea08adb29d999f511cac.zip |
Renamed 'pep517' to 'build_meta'
Diffstat (limited to 'setuptools/tests/test_build_meta.py')
-rw-r--r-- | setuptools/tests/test_build_meta.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py new file mode 100644 index 00000000..69a700c2 --- /dev/null +++ b/setuptools/tests/test_build_meta.py @@ -0,0 +1,93 @@ +import os + +import pytest + +from .files import build_files +from .textwrap import DALS + + +futures = pytest.importorskip('concurrent.futures') +importlib = pytest.importorskip('importlib') + + +class BuildBackendBase(object): + def __init__(self, cwd=None, env={}, backend_name='setuptools.build_meta'): + self.cwd = cwd + self.env = env + self.backend_name = backend_name + + +class BuildBackend(BuildBackendBase): + """PEP 517 Build Backend""" + def __init__(self, *args, **kwargs): + super(BuildBackend, self).__init__(*args, **kwargs) + self.pool = futures.ProcessPoolExecutor() + + def __getattr__(self, name): + """Handles aribrary function invocations on the build backend.""" + def method(*args, **kw): + root = os.path.abspath(self.cwd) + caller = BuildBackendCaller(root, self.env, self.backend_name) + return self.pool.submit(caller, name, *args, **kw).result() + + return method + + +class BuildBackendCaller(BuildBackendBase): + def __call__(self, name, *args, **kw): + """Handles aribrary function invocations on the build backend.""" + os.chdir(self.cwd) + os.environ.update(self.env) + mod = importlib.import_module(self.backend_name) + return getattr(mod, name)(*args, **kw) + + +@pytest.fixture +def build_backend(tmpdir): + defn = { + 'setup.py': DALS(""" + __import__('setuptools').setup( + name='foo', + py_modules=['hello'], + setup_requires=['six'], + ) + """), + 'hello.py': DALS(""" + def run(): + print('hello') + """), + } + build_files(defn, prefix=str(tmpdir)) + with tmpdir.as_cwd(): + yield BuildBackend(cwd='.') + + +def test_get_requires_for_build_wheel(build_backend): + actual = build_backend.get_requires_for_build_wheel() + expected = ['six', 'setuptools', 'wheel'] + assert sorted(actual) == sorted(expected) + + +def test_build_wheel(build_backend): + dist_dir = os.path.abspath('pip-wheel') + os.makedirs(dist_dir) + wheel_name = build_backend.build_wheel(dist_dir) + + assert os.path.isfile(os.path.join(dist_dir, wheel_name)) + + +def test_build_sdist(build_backend): + dist_dir = os.path.abspath('pip-sdist') + os.makedirs(dist_dir) + sdist_name = build_backend.build_sdist(dist_dir) + + assert os.path.isfile(os.path.join(dist_dir, sdist_name)) + + +def test_prepare_metadata_for_build_wheel(build_backend): + dist_dir = os.path.abspath('pip-dist-info') + os.makedirs(dist_dir) + + dist_info = build_backend.prepare_metadata_for_build_wheel(dist_dir) + + assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA')) |