test_local_wheels.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import glob
  2. import os
  3. import platform
  4. import subprocess
  5. import pytest
  6. from testpath import assert_isfile, assert_isdir
  7. from nsist.pypi import fetch_pypi_wheels
  8. # To exclude tests requiring network on an unplugged machine, use: pytest -m "not network"
  9. @pytest.mark.network
  10. def test_matching_one_pattern(tmpdir):
  11. td1 = str(tmpdir.mkdir('wheels'))
  12. td2 = str(tmpdir.mkdir('pkgs'))
  13. subprocess.call(['pip', 'wheel', 'requests==2.19.1', '-w', str(td1)])
  14. fetch_pypi_wheels([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  15. assert_isdir(os.path.join(td2, 'requests'))
  16. assert_isfile(os.path.join(td2, 'requests-2.19.1.dist-info', 'METADATA'))
  17. assert_isdir(os.path.join(td2, 'urllib3'))
  18. assert glob.glob(os.path.join(td2, 'urllib3*.dist-info'))
  19. @pytest.mark.network
  20. def test_duplicate_wheel_files_raise(tmpdir):
  21. td1 = str(tmpdir.mkdir('wheels'))
  22. td2 = str(tmpdir.mkdir('pkgs'))
  23. subprocess.call(['pip', 'wheel', 'requests==2.19.1', '-w', str(td1)])
  24. with pytest.raises(ValueError, match='wheel distribution requests already included'):
  25. fetch_pypi_wheels(['requests==2.19.1'],
  26. [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  27. def test_invalid_wheel_file_raise(tmpdir):
  28. td1 = str(tmpdir.mkdir('wheels'))
  29. td2 = str(tmpdir.mkdir('pkgs'))
  30. open(os.path.join(td1, 'notawheel.txt'), 'w+')
  31. with pytest.raises(ValueError, match='Invalid wheel file name: notawheel.txt'):
  32. fetch_pypi_wheels([], [os.path.join(td1, '*')], td2, platform.python_version(), 64)
  33. def test_incompatible_plateform_wheel_file_raise(tmpdir):
  34. td1 = str(tmpdir.mkdir('wheels'))
  35. td2 = str(tmpdir.mkdir('pkgs'))
  36. open(os.path.join(td1, 'incompatiblewheel-1.0.0-py2.py3-none-linux_x86_64.whl'), 'w+')
  37. with pytest.raises(ValueError, match='{0} is not compatible with Python {1} for Windows'
  38. .format('incompatiblewheel-1.0.0-py2.py3-none-linux_x86_64.whl',
  39. platform.python_version())):
  40. fetch_pypi_wheels([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  41. def test_incompatible_python_wheel_file_raise(tmpdir):
  42. td1 = str(tmpdir.mkdir('wheels'))
  43. td2 = str(tmpdir.mkdir('pkgs'))
  44. open(os.path.join(td1, 'incompatiblewheel-1.0.0-py26-none-any.whl'), 'w+')
  45. with pytest.raises(ValueError, match='{0} is not compatible with Python {1} for Windows'
  46. .format('incompatiblewheel-1.0.0-py26-none-any.whl',
  47. platform.python_version())):
  48. fetch_pypi_wheels([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  49. def test_useless_wheel_glob_path_raise(tmpdir):
  50. td1 = str(tmpdir.mkdir('wheels'))
  51. td2 = str(tmpdir.mkdir('pkgs'))
  52. with pytest.raises(ValueError, match='does not match any wheel file'):
  53. fetch_pypi_wheels([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)