test_local_wheels.py 2.8 KB

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