test_copymodules.py 2.0 KB

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