test_egg_info.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import os
  2. import stat
  3. import pytest
  4. from . import environment
  5. from .textwrap import DALS
  6. from . import contexts
  7. class TestEggInfo:
  8. setup_script = DALS("""
  9. from setuptools import setup
  10. setup(
  11. name='foo',
  12. py_modules=['hello'],
  13. entry_points={'console_scripts': ['hi = hello.run']},
  14. zip_safe=False,
  15. )
  16. """)
  17. def _create_project(self):
  18. with open('setup.py', 'w') as f:
  19. f.write(self.setup_script)
  20. with open('hello.py', 'w') as f:
  21. f.write(DALS("""
  22. def run():
  23. print('hello')
  24. """))
  25. @pytest.yield_fixture
  26. def env(self):
  27. class Environment(str): pass
  28. with contexts.tempdir(prefix='setuptools-test.') as env_dir:
  29. env = Environment(env_dir)
  30. os.chmod(env_dir, stat.S_IRWXU)
  31. subs = 'home', 'lib', 'scripts', 'data', 'egg-base'
  32. env.paths = dict(
  33. (dirname, os.path.join(env_dir, dirname))
  34. for dirname in subs
  35. )
  36. list(map(os.mkdir, env.paths.values()))
  37. config = os.path.join(env.paths['home'], '.pydistutils.cfg')
  38. with open(config, 'w') as f:
  39. f.write(DALS("""
  40. [egg_info]
  41. egg-base = %(egg-base)s
  42. """ % env.paths
  43. ))
  44. yield env
  45. def test_egg_base_installed_egg_info(self, tmpdir_cwd, env):
  46. self._create_project()
  47. environ = os.environ.copy().update(
  48. HOME=env.paths['home'],
  49. )
  50. cmd = [
  51. 'install',
  52. '--home', env.paths['home'],
  53. '--install-lib', env.paths['lib'],
  54. '--install-scripts', env.paths['scripts'],
  55. '--install-data', env.paths['data'],
  56. ]
  57. code, data = environment.run_setup_py(
  58. cmd=cmd,
  59. pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
  60. data_stream=1,
  61. env=environ,
  62. )
  63. if code:
  64. raise AssertionError(data)
  65. actual = self._find_egg_info_files(env.paths['lib'])
  66. expected = [
  67. 'PKG-INFO',
  68. 'SOURCES.txt',
  69. 'dependency_links.txt',
  70. 'entry_points.txt',
  71. 'not-zip-safe',
  72. 'top_level.txt',
  73. ]
  74. assert sorted(actual) == expected
  75. def _find_egg_info_files(self, root):
  76. results = (
  77. filenames
  78. for dirpath, dirnames, filenames in os.walk(root)
  79. if os.path.basename(dirpath) == 'EGG-INFO'
  80. )
  81. # expect exactly one result
  82. result, = results
  83. return result