PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/functional/test_install_cleanup.py

http://github.com/pypa/pip
Python | 156 lines | 130 code | 12 blank | 14 comment | 1 complexity | fc84efd2116504331565e08900eded58 MD5 | raw file
Possible License(s): 0BSD, MIT, BSD-3-Clause, MPL-2.0, LGPL-2.1, Apache-2.0
  1. import os
  2. from os.path import exists
  3. import pytest
  4. from pip._internal.cli.status_codes import PREVIOUS_BUILD_DIR_ERROR
  5. from tests.lib import need_mercurial, windows_workaround_7667
  6. from tests.lib.local_repos import local_checkout
  7. def test_cleanup_after_install(script, data):
  8. """
  9. Test clean up after installing a package.
  10. """
  11. script.pip(
  12. 'install', '--no-index',
  13. '--find-links={}'.format(data.find_links),
  14. 'simple'
  15. )
  16. build = script.venv_path / "build"
  17. src = script.venv_path / "src"
  18. assert not exists(build), "build/ dir still exists: {}".format(build)
  19. assert not exists(src), "unexpected src/ dir exists: {}" .format(src)
  20. script.assert_no_temp()
  21. @pytest.mark.network
  22. def test_no_clean_option_blocks_cleaning_after_install(script, data):
  23. """
  24. Test --no-clean option blocks cleaning after install
  25. """
  26. build = script.base_path / 'pip-build'
  27. script.pip(
  28. 'install', '--no-clean', '--no-index', '--build', build,
  29. '--find-links={}'.format(data.find_links), 'simple', expect_temp=True,
  30. )
  31. assert exists(build)
  32. @pytest.mark.network
  33. @need_mercurial
  34. @windows_workaround_7667
  35. def test_cleanup_after_install_editable_from_hg(script, tmpdir):
  36. """
  37. Test clean up after cloning from Mercurial.
  38. """
  39. requirement = '{}#egg=ScriptTest'.format(
  40. local_checkout('hg+https://bitbucket.org/ianb/scripttest', tmpdir)
  41. )
  42. script.pip('install', '-e', requirement)
  43. build = script.venv_path / 'build'
  44. src = script.venv_path / 'src'
  45. assert not exists(build), "build/ dir still exists: {}".format(build)
  46. assert exists(src), "expected src/ dir doesn't exist: {}".format(src)
  47. script.assert_no_temp()
  48. def test_cleanup_after_install_from_local_directory(script, data):
  49. """
  50. Test clean up after installing from a local directory.
  51. """
  52. to_install = data.packages.joinpath("FSPkg")
  53. script.pip('install', to_install)
  54. build = script.venv_path / 'build'
  55. src = script.venv_path / 'src'
  56. assert not exists(build), "unexpected build/ dir exists: {}".format(build)
  57. assert not exists(src), "unexpected src/ dir exist: {}".format(src)
  58. script.assert_no_temp()
  59. def test_cleanup_req_satisfied_no_name(script, data):
  60. """
  61. Test cleanup when req is already satisfied, and req has no 'name'
  62. """
  63. # this test confirms Issue #420 is fixed
  64. # reqs with no 'name' that were already satisfied were leaving behind tmp
  65. # build dirs
  66. # 2 examples of reqs that would do this
  67. # 1) https://bitbucket.org/ianb/initools/get/tip.zip
  68. # 2) parent-0.1.tar.gz
  69. dist = data.packages.joinpath("parent-0.1.tar.gz")
  70. script.pip('install', dist)
  71. script.pip('install', dist)
  72. build = script.venv_path / 'build'
  73. assert not exists(build), \
  74. "unexpected build/ dir exists: {build}".format(**locals())
  75. script.assert_no_temp()
  76. def test_cleanup_after_install_exception(script, data):
  77. """
  78. Test clean up after a 'setup.py install' exception.
  79. """
  80. # broken==0.2broken fails during install; see packages readme file
  81. result = script.pip(
  82. 'install', '-f', data.find_links, '--no-index', 'broken==0.2broken',
  83. expect_error=True,
  84. )
  85. build = script.venv_path / 'build'
  86. assert not exists(build), \
  87. "build/ dir still exists: {result.stdout}".format(**locals())
  88. script.assert_no_temp()
  89. def test_cleanup_after_egg_info_exception(script, data):
  90. """
  91. Test clean up after a 'setup.py egg_info' exception.
  92. """
  93. # brokenegginfo fails during egg_info; see packages readme file
  94. result = script.pip(
  95. 'install', '-f', data.find_links, '--no-index', 'brokenegginfo==0.1',
  96. expect_error=True,
  97. )
  98. build = script.venv_path / 'build'
  99. assert not exists(build), \
  100. "build/ dir still exists: {result.stdout}".format(**locals())
  101. script.assert_no_temp()
  102. @pytest.mark.network
  103. def test_cleanup_prevented_upon_build_dir_exception(script, data):
  104. """
  105. Test no cleanup occurs after a PreviousBuildDirError
  106. """
  107. build = script.venv_path / 'build'
  108. build_simple = build / 'simple'
  109. os.makedirs(build_simple)
  110. build_simple.joinpath("setup.py").write_text("#")
  111. result = script.pip(
  112. 'install', '-f', data.find_links, '--no-index', 'simple',
  113. '--build', build,
  114. expect_error=True, expect_temp=True,
  115. )
  116. assert result.returncode == PREVIOUS_BUILD_DIR_ERROR, str(result)
  117. assert "pip can't proceed" in result.stderr, str(result)
  118. assert exists(build_simple), str(result)
  119. @pytest.mark.network
  120. def test_pep517_no_legacy_cleanup(script, data, with_wheel):
  121. """Test a PEP 517 failed build does not attempt a legacy cleanup"""
  122. to_install = data.packages.joinpath('pep517_wrapper_buildsys')
  123. script.environ["PIP_TEST_FAIL_BUILD_WHEEL"] = "1"
  124. res = script.pip(
  125. 'install', '-f', data.find_links, to_install,
  126. expect_error=True
  127. )
  128. # Must not have built the package
  129. expected = "Failed building wheel for pep517-wrapper-buildsys"
  130. assert expected in str(res)
  131. # Must not have attempted legacy cleanup
  132. assert "setup.py clean" not in str(res)