test_pypi.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 WheelLocator, extract_wheel, CachedRelease, merge_dir_to
  7. def test_download():
  8. wd = WheelLocator("astsearch==0.1.2", "3.5.1", 64)
  9. wheel = wd.fetch()
  10. assert_isfile(str(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_extra_sources():
  17. with TemporaryDirectory() as td:
  18. src1 = Path(td, 'src1')
  19. src1.mkdir()
  20. src2 = Path(td, 'src2')
  21. src2.mkdir()
  22. # First one found wins, even if a later one is more specific.
  23. expected = (src1 / 'astsearch-0.1.2-py3-none-any.whl')
  24. expected.touch()
  25. (src2 / 'astsearch-0.1.2-py3-none-win_amd64.whl').touch()
  26. wl = WheelLocator("astsearch==0.1.2", "3.5.1", 64,
  27. extra_sources=[src1, src2])
  28. assert_equal(wl.check_extra_sources(), expected)
  29. wl = WheelLocator("astsearch==0.2.0", "3.5.1", 64,
  30. extra_sources=[src1, src2])
  31. assert_is(wl.check_extra_sources(), None)
  32. def test_pick_best_wheel():
  33. wd = WheelLocator("astsearch==0.1.2", "3.5.1", 64)
  34. # Some of the wheel filenames below are impossible combinations - they are
  35. # there to test the scoring and ranking machinery.
  36. # Prefer Windows-specific wheel
  37. releases = [
  38. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  39. CachedRelease('astsearch-0.1.2-py3-none-win_amd64.whl'),
  40. ]
  41. assert_equal(wd.pick_best_wheel(releases), releases[1])
  42. # Wrong Windows bitness
  43. releases = [
  44. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  45. CachedRelease('astsearch-0.1.2-py3-none-win_32.whl'),
  46. ]
  47. assert_equal(wd.pick_best_wheel(releases), releases[0])
  48. # Prefer more specific Python version
  49. releases = [
  50. CachedRelease('astsearch-0.1.2-cp35-none-any.whl'),
  51. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  52. ]
  53. assert_equal(wd.pick_best_wheel(releases), releases[0])
  54. # Prefer more specific Python version
  55. releases = [
  56. CachedRelease('astsearch-0.1.2-py34.py35-none-any.whl'),
  57. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  58. ]
  59. assert_equal(wd.pick_best_wheel(releases), releases[0])
  60. # Incompatible Python version
  61. releases = [
  62. CachedRelease('astsearch-0.1.2-cp33-none-any.whl'),
  63. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  64. ]
  65. assert_equal(wd.pick_best_wheel(releases), releases[1])
  66. # Prefer more specific ABI version
  67. releases = [
  68. CachedRelease('astsearch-0.1.2-py3-abi3-any.whl'),
  69. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  70. ]
  71. assert_equal(wd.pick_best_wheel(releases), releases[0])
  72. # Incompatible ABI version
  73. releases = [
  74. CachedRelease('astsearch-0.1.2-cp35-abi4-win_amd64.whl'),
  75. CachedRelease('astsearch-0.1.2-py3-none-any.whl'),
  76. ]
  77. assert_equal(wd.pick_best_wheel(releases), releases[1])
  78. # Platform has priority over other attributes
  79. releases = [
  80. CachedRelease('astsearch-0.1.2-cp35-abi3-any.whl'),
  81. CachedRelease('astsearch-0.1.2-py2.py3-none-win_amd64.whl'),
  82. ]
  83. assert_equal(wd.pick_best_wheel(releases), releases[1])
  84. def test_merge_dir_to():
  85. with TemporaryDirectory() as td1, TemporaryDirectory() as td2:
  86. td1 = Path(td1)
  87. td2 = Path(td2)
  88. with (td1 / 'ab').open('w') as f:
  89. f.write(u"original")
  90. with (td2 / 'ab').open('w') as f:
  91. f.write(u"alternate")
  92. (td1 / 'subdir').mkdir()
  93. with (td1 / 'subdir' / 'foo').open('w'): pass
  94. (td2 / 'subdir').mkdir()
  95. with (td2 / 'subdir' / 'bar').open('w'): pass
  96. merge_dir_to(td2, td1)
  97. assert_isfile(str(td1 / 'subdir' / 'foo'))
  98. assert_isfile(str(td1 / 'subdir' / 'bar'))
  99. with (td1 / 'ab').open() as f:
  100. assert_equal(f.read(), u"alternate")
  101. # Test with conflicts
  102. (td1 / 'conflict').mkdir()
  103. with (td2 / 'conflict').open('w'): pass
  104. with assert_raises(RuntimeError):
  105. merge_dir_to(td2, td1)
  106. with assert_raises(RuntimeError):
  107. merge_dir_to(td1, td2)