test_develop.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. """develop tests"""
  2. import os
  3. import platform
  4. import subprocess
  5. import sys
  6. import pytest
  7. from setuptools._path import paths_on_pythonpath
  8. from . import contexts, namespaces
  9. SETUP_PY = """\
  10. from setuptools import setup
  11. setup(name='foo',
  12. packages=['foo'],
  13. )
  14. """
  15. INIT_PY = """print "foo"
  16. """
  17. @pytest.fixture
  18. def temp_user(monkeypatch):
  19. with contexts.tempdir() as user_base:
  20. with contexts.tempdir() as user_site:
  21. monkeypatch.setattr('site.USER_BASE', user_base)
  22. monkeypatch.setattr('site.USER_SITE', user_site)
  23. yield
  24. @pytest.fixture
  25. def test_env(tmpdir, temp_user):
  26. target = tmpdir
  27. foo = target.mkdir('foo')
  28. setup = target / 'setup.py'
  29. if setup.isfile():
  30. raise ValueError(dir(target))
  31. with setup.open('w') as f:
  32. f.write(SETUP_PY)
  33. init = foo / '__init__.py'
  34. with init.open('w') as f:
  35. f.write(INIT_PY)
  36. with target.as_cwd():
  37. yield target
  38. class TestNamespaces:
  39. @staticmethod
  40. def install_develop(src_dir, target):
  41. develop_cmd = [
  42. sys.executable,
  43. 'setup.py',
  44. 'develop',
  45. '--install-dir',
  46. str(target),
  47. ]
  48. with src_dir.as_cwd():
  49. with paths_on_pythonpath([str(target)]):
  50. subprocess.check_call(develop_cmd)
  51. @pytest.mark.xfail(reason="pkg_resources has been removed")
  52. @pytest.mark.skipif(
  53. bool(os.environ.get("APPVEYOR")),
  54. reason="https://github.com/pypa/setuptools/issues/851",
  55. )
  56. @pytest.mark.skipif(
  57. platform.python_implementation() == 'PyPy',
  58. reason="https://github.com/pypa/setuptools/issues/1202",
  59. )
  60. @pytest.mark.uses_network
  61. def test_namespace_package_importable(self, tmpdir):
  62. """
  63. Installing two packages sharing the same namespace, one installed
  64. naturally using pip or `--single-version-externally-managed`
  65. and the other installed using `develop` should leave the namespace
  66. in tact and both packages reachable by import.
  67. """
  68. pkg_A = namespaces.build_namespace_package(tmpdir, 'myns.pkgA')
  69. pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB')
  70. target = tmpdir / 'packages'
  71. # use pip to install to the target directory
  72. install_cmd = [
  73. sys.executable,
  74. '-m',
  75. 'pip',
  76. 'install',
  77. str(pkg_A),
  78. '-t',
  79. str(target),
  80. ]
  81. subprocess.check_call(install_cmd)
  82. self.install_develop(pkg_B, target)
  83. namespaces.make_site_dir(target)
  84. try_import = [
  85. sys.executable,
  86. '-c',
  87. 'import myns.pkgA; import myns.pkgB',
  88. ]
  89. with paths_on_pythonpath([str(target)]):
  90. subprocess.check_call(try_import)
  91. # additionally ensure that pkg_resources import works
  92. pkg_resources_imp = [
  93. sys.executable,
  94. '-c',
  95. 'import pkg_resources',
  96. ]
  97. with paths_on_pythonpath([str(target)]):
  98. subprocess.check_call(pkg_resources_imp)