test_local_wheels.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import glob
  2. import os
  3. from pathlib import Path
  4. import platform
  5. import subprocess
  6. from zipfile import ZipFile
  7. import pytest
  8. from testpath import assert_isfile, assert_isdir, assert_not_path_exists
  9. from nsist.wheels import WheelGetter, extract_wheel
  10. # To exclude tests requiring network on an unplugged machine, use: pytest -m "not network"
  11. @pytest.mark.network
  12. def test_matching_one_pattern(tmpdir):
  13. td1 = str(tmpdir.mkdir('wheels'))
  14. td2 = str(tmpdir.mkdir('pkgs'))
  15. subprocess.call(['pip', 'wheel', 'requests==2.19.1', '-w', str(td1)])
  16. wg = WheelGetter([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  17. wg.get_globs()
  18. assert_isdir(os.path.join(td2, 'requests'))
  19. assert_isfile(os.path.join(td2, 'requests-2.19.1.dist-info', 'METADATA'))
  20. assert_isdir(os.path.join(td2, 'urllib3'))
  21. assert glob.glob(os.path.join(td2, 'urllib3*.dist-info'))
  22. @pytest.mark.network
  23. def test_duplicate_wheel_files_raise(tmpdir):
  24. td1 = str(tmpdir.mkdir('wheels'))
  25. td2 = str(tmpdir.mkdir('pkgs'))
  26. subprocess.call(['pip', 'wheel', 'requests==2.19.1', '-w', str(td1)])
  27. wg = WheelGetter(['requests==2.19.1'], [os.path.join(td1, '*.whl')], td2,
  28. platform.python_version(), 64)
  29. with pytest.raises(ValueError, match='Multiple wheels specified'):
  30. wg.get_all()
  31. def test_invalid_wheel_file_raise(tmpdir):
  32. td1 = str(tmpdir.mkdir('wheels'))
  33. td2 = str(tmpdir.mkdir('pkgs'))
  34. open(os.path.join(td1, 'notawheel.txt'), 'w+')
  35. wg = WheelGetter([], [os.path.join(td1, '*')], td2,
  36. platform.python_version(), 64)
  37. with pytest.raises(ValueError, match='notawheel.txt'):
  38. wg.get_globs()
  39. def test_incompatible_platform_wheel_file_raise(tmpdir):
  40. td1 = str(tmpdir.mkdir('wheels'))
  41. td2 = str(tmpdir.mkdir('pkgs'))
  42. Path(td1, 'incompatiblewheel-1.0.0-py2.py3-none-linux_x86_64.whl').touch()
  43. wg = WheelGetter([], [os.path.join(td1, '*.whl')], td2,
  44. platform.python_version(), 64)
  45. with pytest.raises(ValueError, match='not compatible with .* win_amd64'):
  46. wg.get_globs()
  47. def test_incompatible_python_wheel_file_raise(tmpdir):
  48. td1 = str(tmpdir.mkdir('wheels'))
  49. td2 = str(tmpdir.mkdir('pkgs'))
  50. Path(td1, 'incompatiblewheel-1.0.0-py26-none-any.whl').touch()
  51. wg = WheelGetter([], [os.path.join(td1, '*.whl')], td2,
  52. platform.python_version(), 64)
  53. with pytest.raises(ValueError, match='not compatible with Python {}'
  54. .format(platform.python_version())):
  55. wg.get_globs()
  56. def test_useless_wheel_glob_path_raise(tmpdir):
  57. td1 = str(tmpdir.mkdir('wheels'))
  58. td2 = str(tmpdir.mkdir('pkgs'))
  59. wg = WheelGetter([], [os.path.join(td1, '*.whl')], td2, '3.6', 64)
  60. with pytest.raises(ValueError, match='does not match any files'):
  61. wg.get_globs()
  62. def test_extract_exclude_folder(tmpdir):
  63. whl_file = str(tmpdir / 'foo.whl')
  64. pkgs = tmpdir.mkdir('pkgs')
  65. with ZipFile(whl_file, 'w') as zf:
  66. zf.writestr('foo/bar.txt', b'blah')
  67. zf.writestr('foo/bar/abc.txt', b'blah')
  68. extract_wheel(whl_file, str(pkgs), exclude=['pkgs/foo/bar'])
  69. assert_isfile(str(pkgs / 'foo' / 'bar.txt'))
  70. assert_not_path_exists(str(pkgs / 'foo' / 'bar'))
  71. def test_extract_data_lib_sitepkg(tmpdir):
  72. whl_file = str(tmpdir / 'foo.whl')
  73. pkgs = tmpdir.mkdir('pkgs')
  74. with ZipFile(whl_file, 'w') as zf:
  75. zf.writestr('osgeo/bar.txt', b'blah')
  76. # The case of 'Lib/site-packages' shouldn't matter
  77. zf.writestr('foo-1.0.data/data/Lib/siTE-packages/osgeo/abc.txt', b'a')
  78. zf.writestr('foo-1.0.data/data/lib/site-packages/osgeo/def.txt', b'd')
  79. extract_wheel(whl_file, str(pkgs), exclude=['pkgs/foo/bar'])
  80. assert_isfile(str(pkgs / 'osgeo' / 'bar.txt'))
  81. assert_isfile(str(pkgs / 'osgeo' / 'abc.txt'))
  82. assert_isfile(str(pkgs / 'osgeo' / 'def.txt'))