test_local_wheels.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import unittest
  2. import os
  3. import platform
  4. import subprocess
  5. import glob
  6. from testpath.tempdir import TemporaryDirectory
  7. from testpath import assert_isfile, assert_isdir
  8. from nsist.pypi import fetch_pypi_wheels
  9. class TestLocalWheels(unittest.TestCase):
  10. def test_matching_one_pattern(self):
  11. with TemporaryDirectory() as td1:
  12. subprocess.call(['pip', 'wheel', 'requests==2.19.1', '-w', td1])
  13. with TemporaryDirectory() as td2:
  14. fetch_pypi_wheels([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  15. assert_isdir(os.path.join(td2, 'requests'))
  16. assert_isfile(os.path.join(td2, 'requests-2.19.1.dist-info', 'METADATA'))
  17. assert_isdir(os.path.join(td2, 'urllib3'))
  18. self.assertTrue(glob.glob(os.path.join(td2, 'urllib3*.dist-info')))
  19. def test_duplicate_wheel_files_raise(self):
  20. with TemporaryDirectory() as td1:
  21. subprocess.call(['pip', 'wheel', 'requests==2.19.1', '-w', td1])
  22. with TemporaryDirectory() as td2:
  23. with self.assertRaisesRegex(ValueError, 'wheel distribution requests already included'):
  24. fetch_pypi_wheels(['requests==2.19.1'], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  25. def test_invalid_wheel_file_raise(self):
  26. with TemporaryDirectory() as td1:
  27. open(os.path.join(td1, 'notawheel.txt'), 'w+')
  28. with TemporaryDirectory() as td2:
  29. with self.assertRaisesRegex(ValueError, 'Invalid wheel file name: notawheel.txt'):
  30. fetch_pypi_wheels([], [os.path.join(td1, '*')], td2, platform.python_version(), 64)
  31. def test_incompatible_plateform_wheel_file_raise(self):
  32. with TemporaryDirectory() as td1:
  33. open(os.path.join(td1, 'incompatiblewheel-1.0.0-py2.py3-none-linux_x86_64.whl'), 'w+')
  34. with TemporaryDirectory() as td2:
  35. with self.assertRaisesRegex(ValueError, '{0} is not compatible with Python {1} for Windows'
  36. .format('incompatiblewheel-1.0.0-py2.py3-none-linux_x86_64.whl', platform.python_version())):
  37. fetch_pypi_wheels([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  38. def test_incompatible_python_wheel_file_raise(self):
  39. with TemporaryDirectory() as td1:
  40. open(os.path.join(td1, 'incompatiblewheel-1.0.0-py26-none-any.whl'), 'w+')
  41. with TemporaryDirectory() as td2:
  42. with self.assertRaisesRegex(ValueError, '{0} is not compatible with Python {1} for Windows'
  43. .format('incompatiblewheel-1.0.0-py26-none-any.whl', platform.python_version())):
  44. fetch_pypi_wheels([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  45. def test_useless_wheel_glob_path_raise(self):
  46. with TemporaryDirectory() as td1:
  47. with TemporaryDirectory() as td2:
  48. with self.assertRaisesRegex(ValueError, 'does not match any wheel file'):
  49. fetch_pypi_wheels([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
  50. # To exclude these, run: nosetests -a '!network'
  51. TestLocalWheels.test_matching_one_pattern.network = 1
  52. TestLocalWheels.test_duplicate_wheel_files_raise.network = 1