test_pypi.py 3.7 KB

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