test_bdist_dumb.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """Tests for distutils.command.bdist_dumb."""
  2. import os
  3. import sys
  4. import zipfile
  5. from distutils.command.bdist_dumb import bdist_dumb
  6. from distutils.core import Distribution
  7. from distutils.tests import support
  8. import pytest
  9. SETUP_PY = """\
  10. from distutils.core import setup
  11. import foo
  12. setup(name='foo', version='0.1', py_modules=['foo'],
  13. url='xxx', author='xxx', author_email='xxx')
  14. """
  15. @support.combine_markers
  16. @pytest.mark.usefixtures('save_env')
  17. @pytest.mark.usefixtures('save_argv')
  18. @pytest.mark.usefixtures('save_cwd')
  19. class TestBuildDumb(
  20. support.TempdirManager,
  21. ):
  22. @pytest.mark.usefixtures('needs_zlib')
  23. def test_simple_built(self):
  24. # let's create a simple package
  25. tmp_dir = self.mkdtemp()
  26. pkg_dir = os.path.join(tmp_dir, 'foo')
  27. os.mkdir(pkg_dir)
  28. self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
  29. self.write_file((pkg_dir, 'foo.py'), '#')
  30. self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
  31. self.write_file((pkg_dir, 'README'), '')
  32. dist = Distribution({
  33. 'name': 'foo',
  34. 'version': '0.1',
  35. 'py_modules': ['foo'],
  36. 'url': 'xxx',
  37. 'author': 'xxx',
  38. 'author_email': 'xxx',
  39. })
  40. dist.script_name = 'setup.py'
  41. os.chdir(pkg_dir)
  42. sys.argv = ['setup.py']
  43. cmd = bdist_dumb(dist)
  44. # so the output is the same no matter
  45. # what is the platform
  46. cmd.format = 'zip'
  47. cmd.ensure_finalized()
  48. cmd.run()
  49. # see what we have
  50. dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
  51. base = f"{dist.get_fullname()}.{cmd.plat_name}.zip"
  52. assert dist_created == [base]
  53. # now let's check what we have in the zip file
  54. fp = zipfile.ZipFile(os.path.join('dist', base))
  55. try:
  56. contents = fp.namelist()
  57. finally:
  58. fp.close()
  59. contents = sorted(filter(None, map(os.path.basename, contents)))
  60. wanted = ['foo-0.1-py{}.{}.egg-info'.format(*sys.version_info[:2]), 'foo.py']
  61. if not sys.dont_write_bytecode:
  62. wanted.append(f'foo.{sys.implementation.cache_tag}.pyc')
  63. assert contents == sorted(wanted)