test_develop.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. """develop tests
  2. """
  3. import os
  4. import site
  5. import sys
  6. import io
  7. from setuptools.extern import six
  8. import pytest
  9. from setuptools.command.develop import develop
  10. from setuptools.dist import Distribution
  11. from . import contexts
  12. SETUP_PY = """\
  13. from setuptools import setup
  14. setup(name='foo',
  15. packages=['foo'],
  16. use_2to3=True,
  17. )
  18. """
  19. INIT_PY = """print "foo"
  20. """
  21. @pytest.yield_fixture
  22. def temp_user(monkeypatch):
  23. with contexts.tempdir() as user_base:
  24. with contexts.tempdir() as user_site:
  25. monkeypatch.setattr('site.USER_BASE', user_base)
  26. monkeypatch.setattr('site.USER_SITE', user_site)
  27. yield
  28. @pytest.yield_fixture
  29. def test_env(tmpdir, temp_user):
  30. target = tmpdir
  31. foo = target.mkdir('foo')
  32. setup = target / 'setup.py'
  33. if setup.isfile():
  34. raise ValueError(dir(target))
  35. with setup.open('w') as f:
  36. f.write(SETUP_PY)
  37. init = foo / '__init__.py'
  38. with init.open('w') as f:
  39. f.write(INIT_PY)
  40. with target.as_cwd():
  41. yield target
  42. class TestDevelop:
  43. in_virtualenv = hasattr(sys, 'real_prefix')
  44. in_venv = hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix
  45. @pytest.mark.skipif(in_virtualenv or in_venv,
  46. reason="Cannot run when invoked in a virtualenv or venv")
  47. def test_2to3_user_mode(self, test_env):
  48. settings = dict(
  49. name='foo',
  50. packages=['foo'],
  51. use_2to3=True,
  52. version='0.0',
  53. )
  54. dist = Distribution(settings)
  55. dist.script_name = 'setup.py'
  56. cmd = develop(dist)
  57. cmd.user = 1
  58. cmd.ensure_finalized()
  59. cmd.install_dir = site.USER_SITE
  60. cmd.user = 1
  61. with contexts.quiet():
  62. cmd.run()
  63. # let's see if we got our egg link at the right place
  64. content = os.listdir(site.USER_SITE)
  65. content.sort()
  66. assert content == ['easy-install.pth', 'foo.egg-link']
  67. # Check that we are using the right code.
  68. fn = os.path.join(site.USER_SITE, 'foo.egg-link')
  69. with io.open(fn) as egg_link_file:
  70. path = egg_link_file.read().split()[0].strip()
  71. fn = os.path.join(path, 'foo', '__init__.py')
  72. with io.open(fn) as init_file:
  73. init = init_file.read().strip()
  74. expected = 'print("foo")' if six.PY3 else 'print "foo"'
  75. assert init == expected
  76. def test_console_scripts(self, tmpdir):
  77. """
  78. Test that console scripts are installed and that they reference
  79. only the project by name and not the current version.
  80. """
  81. pytest.skip("TODO: needs a fixture to cause 'develop' "
  82. "to be invoked without mutating environment.")
  83. settings = dict(
  84. name='foo',
  85. packages=['foo'],
  86. version='0.0',
  87. entry_points={
  88. 'console_scripts': [
  89. 'foocmd = foo:foo',
  90. ],
  91. },
  92. )
  93. dist = Distribution(settings)
  94. dist.script_name = 'setup.py'
  95. cmd = develop(dist)
  96. cmd.ensure_finalized()
  97. cmd.install_dir = tmpdir
  98. cmd.run()
  99. #assert '0.0' not in foocmd_text