test_lib.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """Test the test support."""
  2. from __future__ import absolute_import
  3. import filecmp
  4. import re
  5. from os.path import isdir, join
  6. from tests.lib import SRC_DIR
  7. def test_tmp_dir_exists_in_env(script):
  8. """
  9. Test that $TMPDIR == env.temp_path and path exists and env.assert_no_temp()
  10. passes (in fast env)
  11. """
  12. # need these tests to ensure the assert_no_temp feature of scripttest is
  13. # working
  14. script.assert_no_temp() # this fails if env.tmp_path doesn't exist
  15. assert script.environ['TMPDIR'] == script.temp_path
  16. assert isdir(script.temp_path)
  17. def test_correct_pip_version(script):
  18. """
  19. Check we are running proper version of pip in run_pip.
  20. """
  21. # output is like:
  22. # pip PIPVERSION from PIPDIRECTORY (python PYVERSION)
  23. result = script.pip('--version')
  24. # compare the directory tree of the invoked pip with that of this source
  25. # distribution
  26. pip_folder_outputed = re.match(
  27. r'pip \d+(\.[\d]+)+(\.?(b|rc|dev|pre|post)\d+)? from (.*) '
  28. r'\(python \d(.[\d])+\)$',
  29. result.stdout
  30. ).group(4)
  31. pip_folder = join(SRC_DIR, 'src', 'pip')
  32. diffs = filecmp.dircmp(pip_folder, pip_folder_outputed)
  33. # If any non-matching .py files exist, we have a problem: run_pip
  34. # is picking up some other version! N.B. if this project acquires
  35. # primary resources other than .py files, this code will need
  36. # maintenance
  37. mismatch_py = [
  38. x for x in diffs.left_only + diffs.right_only + diffs.diff_files
  39. if x.endswith('.py')
  40. ]
  41. assert not mismatch_py, (
  42. 'mismatched source files in %r and %r: %r' %
  43. (pip_folder, pip_folder_outputed, mismatch_py)
  44. )
  45. def test_as_import(script):
  46. """ test that pip.__init__.py does not shadow
  47. the command submodule with a dictionary
  48. """
  49. import pip._internal.commands.install as inst
  50. assert inst is not None