test_copymodules.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. tmpdir = str(tmpdir)
  14. copy_modules(['plainmod', 'plainpkg'], tmpdir, '3.3.5', sample_path)
  15. assert_is_file(pjoin(tmpdir, 'plainmod.py'))
  16. assert_is_dir(pjoin(tmpdir, 'plainpkg'))
  17. @skip_on_windows
  18. def test_copy_wrong_platform(tmpdir):
  19. tmpdir = str(tmpdir)
  20. with pytest.raises(ExtensionModuleMismatch, match="will not be usable on Windows"):
  21. copy_modules(['unix_extmod'], tmpdir, '3.3.5', sample_path)
  22. with pytest.raises(ExtensionModuleMismatch, match="will not be usable on Windows"):
  23. copy_modules(['unix_extpkg'], tmpdir, '3.3.5', sample_path)
  24. @only_on_windows
  25. def test_copy_windows(tmpdir):
  26. tmpdir = str(tmpdir)
  27. copy_modules(['win_extmod', 'win_extpkg'], tmpdir, running_python, sample_path)
  28. assert_is_file(pjoin(tmpdir, 'win_extmod.pyd'))
  29. assert_is_dir(pjoin(tmpdir, 'win_extpkg'))
  30. @only_on_windows
  31. def test_copy_wrong_pyversion(tmpdir):
  32. tmpdir = str(tmpdir)
  33. with pytest.raises(ExtensionModuleMismatch, match="on Python 4"):
  34. copy_modules(['win_extpkg'], tmpdir, '4.0.0', sample_path)
  35. with pytest.raises(ExtensionModuleMismatch, match="on Python 4"):
  36. copy_modules(['win_extmod'], tmpdir, '4.0.0', sample_path)
  37. def test_copy_from_zipfile(tmpdir):
  38. tmpdir = str(tmpdir)
  39. copy_modules(['zippedmod2', 'zippedpkg2'],
  40. tmpdir, running_python, sample_path)
  41. # assert_is_file(pjoin(tmpdir, 'zippedmod.py'))
  42. # assert_is_dir(pjoin(tmpdir, 'zippedpkg'))
  43. assert_is_file(pjoin(tmpdir, 'zippedmod2.py'))
  44. assert_is_dir(pjoin(tmpdir, 'zippedpkg2'))
  45. def test_module_not_found(tmpdir):
  46. tmpdir = str(tmpdir)
  47. with pytest.raises(ImportError):
  48. copy_modules(['nonexistant'], tmpdir, '3.3.5', sample_path)