test_copymodules.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import os
  2. import sys
  3. import pytest
  4. from testpath import assert_isfile, assert_isdir
  5. from nsist.copymodules import copy_modules, ExtensionModuleMismatch
  6. from .utils import test_dir, skip_on_windows, only_on_windows
  7. pjoin = os.path.join
  8. running_python = '.'.join(str(x) for x in sys.version_info[:3])
  9. sample_path = [pjoin(test_dir, 'sample_pkgs'),
  10. pjoin(test_dir, 'sample_zip.egg'),
  11. pjoin(test_dir, 'sample_zip.egg/rootdir'),
  12. ]
  13. def test_copy_plain(tmpdir):
  14. tmpdir = str(tmpdir)
  15. copy_modules(['plainmod', 'plainpkg'], tmpdir, '3.3.5', sample_path)
  16. assert_isfile(pjoin(tmpdir, 'plainmod.py'))
  17. assert_isdir(pjoin(tmpdir, 'plainpkg'))
  18. @skip_on_windows
  19. def test_copy_wrong_platform(tmpdir):
  20. tmpdir = str(tmpdir)
  21. with pytest.raises(ExtensionModuleMismatch, match="will not be usable on Windows"):
  22. copy_modules(['unix_extmod'], tmpdir, '3.3.5', sample_path)
  23. with pytest.raises(ExtensionModuleMismatch, match="will not be usable on Windows"):
  24. copy_modules(['unix_extpkg'], tmpdir, '3.3.5', sample_path)
  25. @only_on_windows
  26. def test_copy_windows(tmpdir):
  27. tmpdir = str(tmpdir)
  28. copy_modules(['win_extmod', 'win_extpkg'], tmpdir, running_python, sample_path)
  29. assert_isfile(pjoin(tmpdir, 'win_extmod.pyd'))
  30. assert_isdir(pjoin(tmpdir, 'win_extpkg'))
  31. @only_on_windows
  32. def test_copy_wrong_pyversion(tmpdir):
  33. tmpdir = str(tmpdir)
  34. with pytest.raises(ExtensionModuleMismatch, match="on Python 4"):
  35. copy_modules(['win_extpkg'], tmpdir, '4.0.0', sample_path)
  36. with pytest.raises(ExtensionModuleMismatch, match="on Python 4"):
  37. copy_modules(['win_extmod'], tmpdir, '4.0.0', sample_path)
  38. def test_copy_from_zipfile(tmpdir):
  39. tmpdir = str(tmpdir)
  40. copy_modules(['zippedmod2', 'zippedpkg2'],
  41. tmpdir, running_python, sample_path)
  42. # assert_isfile(pjoin(tmpdir, 'zippedmod.py'))
  43. # assert_isdir(pjoin(tmpdir, 'zippedpkg'))
  44. assert_isfile(pjoin(tmpdir, 'zippedmod2.py'))
  45. assert_isdir(pjoin(tmpdir, 'zippedpkg2'))
  46. def test_module_not_found(tmpdir):
  47. tmpdir = str(tmpdir)
  48. with pytest.raises(ImportError):
  49. copy_modules(['nonexistant'], tmpdir, '3.3.5', sample_path)