Skip to content

Commit

Permalink
Add regression test for #2849
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Nov 4, 2021
1 parent 41b6e76 commit a571672
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions setuptools/tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import unicodedata
import contextlib
import io
from unittest import mock

import pytest

Expand Down Expand Up @@ -106,6 +107,13 @@ def source_dir(self, tmpdir):
with tmpdir.as_cwd():
yield

def assert_package_data_in_manifest(self, cmd):
manifest = cmd.filelist.files
assert os.path.join('sdist_test', 'a.txt') in manifest
assert os.path.join('sdist_test', 'b.txt') in manifest
assert os.path.join('sdist_test', 'c.rst') not in manifest
assert os.path.join('d', 'e.dat') in manifest

def test_package_data_in_sdist(self):
"""Regression test for pull request #4: ensures that files listed in
package_data are included in the manifest even if they're not added to
Expand All @@ -120,11 +128,7 @@ def test_package_data_in_sdist(self):
with quiet():
cmd.run()

manifest = cmd.filelist.files
assert os.path.join('sdist_test', 'a.txt') in manifest
assert os.path.join('sdist_test', 'b.txt') in manifest
assert os.path.join('sdist_test', 'c.rst') not in manifest
assert os.path.join('d', 'e.dat') in manifest
self.assert_package_data_in_manifest(cmd)

def test_package_data_and_include_package_data_in_sdist(self):
"""
Expand All @@ -142,11 +146,44 @@ def test_package_data_and_include_package_data_in_sdist(self):
with quiet():
cmd.run()

manifest = cmd.filelist.files
assert os.path.join('sdist_test', 'a.txt') in manifest
assert os.path.join('sdist_test', 'b.txt') in manifest
assert os.path.join('sdist_test', 'c.rst') not in manifest
assert os.path.join('d', 'e.dat') in manifest
self.assert_package_data_in_manifest(cmd)

def test_custom_build_py(self):
"""
Ensure projects defining custom build_py don't break
when creating sdists (issue #2849)
"""
from distutils.command.build_py import build_py as OrigBuildPy

using_custom_command_guard = mock.Mock()

class CustomBuildPy(OrigBuildPy):
"""
Some projects have custom commands inheriting from `distutils`
"""

def get_data_files(self):
using_custom_command_guard()
return super().get_data_files()

setup_attrs = {**SETUP_ATTRS, 'include_package_data': True}
assert setup_attrs['package_data']

dist = Distribution(setup_attrs)
dist.script_name = 'setup.py'
cmd = sdist(dist)
cmd.ensure_finalized()

# Make sure we use the custom command
cmd.cmdclass = {'build_py': CustomBuildPy}
cmd.distribution.cmdclass = {'build_py': CustomBuildPy}
assert cmd.distribution.get_command_class('build_py') == CustomBuildPy

with quiet():
cmd.run()

using_custom_command_guard.assert_called()
self.assert_package_data_in_manifest(cmd)

def test_setup_py_exists(self):
dist = Distribution(SETUP_ATTRS)
Expand Down

0 comments on commit a571672

Please sign in to comment.