Commit 6d0daf14 authored by Paul Ganssle's avatar Paul Ganssle

Wrap build_meta tests in a reusable test class

parent f40a47a7
...@@ -6,7 +6,6 @@ import tarfile ...@@ -6,7 +6,6 @@ import tarfile
import pytest import pytest
from setuptools.build_meta import build_sdist
from .files import build_files from .files import build_files
from .textwrap import DALS from .textwrap import DALS
from . import py2_only from . import py2_only
...@@ -103,136 +102,137 @@ defns = [ ...@@ -103,136 +102,137 @@ defns = [
] ]
@pytest.fixture(params=defns) class TestBuildMetaBackend:
def build_backend(tmpdir, request): backend_name = 'setuptools.build_meta'
build_files(request.param, prefix=str(tmpdir))
with tmpdir.as_cwd(): def get_build_backend(self):
yield BuildBackend(cwd='.') return BuildBackend(cwd='.', backend_name=self.backend_name)
@pytest.fixture(params=defns)
def test_get_requires_for_build_wheel(build_backend): def build_backend(self, tmpdir, request):
actual = build_backend.get_requires_for_build_wheel() build_files(request.param, prefix=str(tmpdir))
expected = ['six', 'wheel'] with tmpdir.as_cwd():
assert sorted(actual) == sorted(expected) yield self.get_build_backend()
def test_get_requires_for_build_wheel(self, build_backend):
def test_get_requires_for_build_sdist(build_backend): actual = build_backend.get_requires_for_build_wheel()
actual = build_backend.get_requires_for_build_sdist() expected = ['six', 'wheel']
expected = ['six'] assert sorted(actual) == sorted(expected)
assert sorted(actual) == sorted(expected)
def test_get_requires_for_build_sdist(self, build_backend):
actual = build_backend.get_requires_for_build_sdist()
def test_build_wheel(build_backend): expected = ['six']
dist_dir = os.path.abspath('pip-wheel') assert sorted(actual) == sorted(expected)
os.makedirs(dist_dir)
wheel_name = build_backend.build_wheel(dist_dir) def test_build_wheel(self, build_backend):
dist_dir = os.path.abspath('pip-wheel')
assert os.path.isfile(os.path.join(dist_dir, wheel_name)) os.makedirs(dist_dir)
wheel_name = build_backend.build_wheel(dist_dir)
def test_build_sdist(build_backend): assert os.path.isfile(os.path.join(dist_dir, wheel_name))
dist_dir = os.path.abspath('pip-sdist')
os.makedirs(dist_dir) def test_build_sdist(self, build_backend):
sdist_name = build_backend.build_sdist(dist_dir) dist_dir = os.path.abspath('pip-sdist')
os.makedirs(dist_dir)
assert os.path.isfile(os.path.join(dist_dir, sdist_name)) 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') def test_prepare_metadata_for_build_wheel(self, build_backend):
os.makedirs(dist_dir) dist_dir = os.path.abspath('pip-dist-info')
os.makedirs(dist_dir)
dist_info = build_backend.prepare_metadata_for_build_wheel(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'))
assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))
@py2_only @py2_only
def test_prepare_metadata_for_build_wheel_with_str(build_backend): def test_prepare_metadata_for_build_wheel_with_str(self, build_backend):
dist_dir = os.path.abspath(str('pip-dist-info')) dist_dir = os.path.abspath(str('pip-dist-info'))
os.makedirs(dist_dir) os.makedirs(dist_dir)
dist_info = build_backend.prepare_metadata_for_build_wheel(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')) assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))
def test_build_sdist_explicit_dist(self, build_backend):
def test_build_sdist_explicit_dist(build_backend): # explicitly specifying the dist folder should work
# explicitly specifying the dist folder should work # the folder sdist_directory and the ``--dist-dir`` can be the same
# the folder sdist_directory and the ``--dist-dir`` can be the same dist_dir = os.path.abspath('dist')
dist_dir = os.path.abspath('dist') sdist_name = build_backend.build_sdist(dist_dir)
sdist_name = build_backend.build_sdist(dist_dir) assert os.path.isfile(os.path.join(dist_dir, sdist_name))
assert os.path.isfile(os.path.join(dist_dir, sdist_name))
def test_build_sdist_version_change(self, build_backend):
sdist_into_directory = os.path.abspath("out_sdist")
def test_build_sdist_version_change(build_backend): os.makedirs(sdist_into_directory)
sdist_into_directory = os.path.abspath("out_sdist")
os.makedirs(sdist_into_directory) sdist_name = build_backend.build_sdist(sdist_into_directory)
assert os.path.isfile(os.path.join(sdist_into_directory, sdist_name))
sdist_name = build_backend.build_sdist(sdist_into_directory)
assert os.path.isfile(os.path.join(sdist_into_directory, sdist_name)) # if the setup.py changes subsequent call of the build meta
# should still succeed, given the
# if the setup.py changes subsequent call of the build meta # sdist_directory the frontend specifies is empty
# should still succeed, given the with open(os.path.abspath("setup.py"), 'rt') as file_handler:
# sdist_directory the frontend specifies is empty content = file_handler.read()
with open(os.path.abspath("setup.py"), 'rt') as file_handler: with open(os.path.abspath("setup.py"), 'wt') as file_handler:
content = file_handler.read() file_handler.write(
with open(os.path.abspath("setup.py"), 'wt') as file_handler: content.replace("version='0.0.0'", "version='0.0.1'"))
file_handler.write(
content.replace("version='0.0.0'", "version='0.0.1'")) shutil.rmtree(sdist_into_directory)
os.makedirs(sdist_into_directory)
shutil.rmtree(sdist_into_directory)
os.makedirs(sdist_into_directory) sdist_name = build_backend.build_sdist("out_sdist")
assert os.path.isfile(
sdist_name = build_backend.build_sdist("out_sdist") os.path.join(os.path.abspath("out_sdist"), sdist_name))
assert os.path.isfile(
os.path.join(os.path.abspath("out_sdist"), sdist_name)) 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
def test_build_sdist_setup_py_exists(tmpdir_cwd): build_files(defns[0])
# If build_sdist is called from a script other than setup.py,
# ensure setup.py is include build_backend = self.get_build_backend()
build_files(defns[0]) targz_path = build_backend.build_sdist("temp")
targz_path = build_sdist("temp") with tarfile.open(os.path.join("temp", targz_path)) as tar:
with tarfile.open(os.path.join("temp", targz_path)) as tar: assert any('setup.py' in name for name in tar.getnames())
assert any('setup.py' in name for name in tar.getnames())
def test_build_sdist_setup_py_manifest_excluded(self, tmpdir_cwd):
# Ensure that MANIFEST.in can exclude setup.py
def test_build_sdist_setup_py_manifest_excluded(tmpdir_cwd): files = {
# Ensure that MANIFEST.in can exclude setup.py 'setup.py': DALS("""
files = { __import__('setuptools').setup(
'setup.py': DALS(""" name='foo',
__import__('setuptools').setup( version='0.0.0',
name='foo', py_modules=['hello']
version='0.0.0', )"""),
py_modules=['hello'] 'hello.py': '',
)"""), 'MANIFEST.in': DALS("""
'hello.py': '', exclude setup.py
'MANIFEST.in': DALS(""" """)
exclude setup.py }
""")
} build_files(files)
build_files(files) build_backend = self.get_build_backend()
targz_path = build_sdist("temp") targz_path = build_backend.build_sdist("temp")
with tarfile.open(os.path.join("temp", targz_path)) as tar: with tarfile.open(os.path.join("temp", targz_path)) as tar:
assert not any('setup.py' in name for name in tar.getnames()) assert not any('setup.py' in name for name in tar.getnames())
def test_build_sdist_builds_targz_even_if_zip_indicated(self, tmpdir_cwd):
def test_build_sdist_builds_targz_even_if_zip_indicated(tmpdir_cwd): files = {
files = { 'setup.py': DALS("""
'setup.py': DALS(""" __import__('setuptools').setup(
__import__('setuptools').setup( name='foo',
name='foo', version='0.0.0',
version='0.0.0', py_modules=['hello']
py_modules=['hello'] )"""),
)"""), 'hello.py': '',
'hello.py': '', 'setup.cfg': DALS("""
'setup.cfg': DALS(""" [sdist]
[sdist] formats=zip
formats=zip """)
""") }
}
build_files(files)
build_files(files)
build_sdist("temp") build_backend = self.get_build_backend()
build_backend.build_sdist("temp")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment