test_pypi.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. from nose.tools import *
  2. from os.path import join as pjoin
  3. from pathlib import Path
  4. from testpath import assert_isfile, assert_isdir
  5. from testpath.tempdir import TemporaryDirectory
  6. from nsist.pypi import WheelDownloader, extract_wheel, CachedRelease, merge_dir_to
  7. def test_download():
  8. wd = WheelDownloader("astsearch==0.1.2", "3.5.1", 64)
  9. wheel = wd.fetch()
  10. assert_isfile(wheel)
  11. with TemporaryDirectory() as td:
  12. extract_wheel(wheel, target_dir=td)
  13. assert_isfile(pjoin(td, 'astsearch.py'))
  14. # To exclude this, run: nosetests -a '!network'
  15. test_download.network = 1
  16. def test_pick_best_wheel():
  17. wd = WheelDownloader("astsearch==0.1.2", "3.5.1", 64)
  18. # Some of the wheel filenames below are impossible combinations - they are
  19. # there to test the scoring and ranking machinery.
  20. # Prefer Windows-specific wheel
  21. releases = [
  22. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  23. CachedRelease('astsearch-0.1.2-py3-none-win_amd64.whl'),
  24. ]
  25. assert_equal(wd.pick_best_wheel(releases), releases[1])
  26. # Wrong Windows bitness
  27. releases = [
  28. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  29. CachedRelease('astsearch-0.1.2-py3-none-win_32.whl'),
  30. ]
  31. assert_equal(wd.pick_best_wheel(releases), releases[0])
  32. # Prefer more specific Python version
  33. releases = [
  34. CachedRelease('astsearch-0.1.2-cp35-none-any.whl'),
  35. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  36. ]
  37. assert_equal(wd.pick_best_wheel(releases), releases[0])
  38. # Prefer more specific Python version
  39. releases = [
  40. CachedRelease('astsearch-0.1.2-py34.py35-none-any.whl'),
  41. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  42. ]
  43. assert_equal(wd.pick_best_wheel(releases), releases[0])
  44. # Incompatible Python version
  45. releases = [
  46. CachedRelease('astsearch-0.1.2-cp33-none-any.whl'),
  47. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  48. ]
  49. assert_equal(wd.pick_best_wheel(releases), releases[1])
  50. # Prefer more specific ABI version
  51. releases = [
  52. CachedRelease('astsearch-0.1.2-py3-abi3-any.whl'),
  53. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  54. ]
  55. assert_equal(wd.pick_best_wheel(releases), releases[0])
  56. # Incompatible ABI version
  57. releases = [
  58. CachedRelease('astsearch-0.1.2-cp35-abi4-win_amd64.whl'),
  59. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  60. ]
  61. assert_equal(wd.pick_best_wheel(releases), releases[1])
  62. # Platform has priority over other attributes
  63. releases = [
  64. CachedRelease('astsearch-0.1.2-cp35-abi3-any.whl'),
  65. CachedRelease('astsearch-0.1.2-py2.py3-none-win_amd64.whl'),
  66. ]
  67. assert_equal(wd.pick_best_wheel(releases), releases[1])
  68. def test_merge_dir_to():
  69. with TemporaryDirectory() as td1, TemporaryDirectory() as td2:
  70. td1 = Path(td1)
  71. td2 = Path(td2)
  72. with (td1 / 'ab').open('w') as f:
  73. f.write(u"original")
  74. with (td2 / 'ab').open('w') as f:
  75. f.write(u"alternate")
  76. (td1 / 'subdir').mkdir()
  77. with (td1 / 'subdir' / 'foo').open('w'): pass
  78. (td2 / 'subdir').mkdir()
  79. with (td2 / 'subdir' / 'bar').open('w'): pass
  80. merge_dir_to(td2, td1)
  81. assert_isfile(td1 / 'subdir' / 'foo')
  82. assert_isfile(td1 / 'subdir' / 'bar')
  83. with (td1 / 'ab').open() as f:
  84. assert_equal(f.read(), u"alternate")
  85. # Test with conflicts
  86. (td1 / 'conflict').mkdir()
  87. with (td2 / 'conflict').open('w'): pass
  88. with assert_raises(RuntimeError):
  89. merge_dir_to(td2, td1)
  90. with assert_raises(RuntimeError):
  91. merge_dir_to(td1, td2)