test_copymodules.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os
  2. import shutil
  3. import sys
  4. import tempfile
  5. import unittest
  6. pjoin = os.path.join
  7. from .utils import assert_is_file, assert_is_dir, test_dir
  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. from nsist.copymodules import copy_modules, ExtensionModuleMismatch
  14. class TestCopyModules(unittest.TestCase):
  15. def setUp(self):
  16. self.target = tempfile.mkdtemp()
  17. def tearDown(self):
  18. shutil.rmtree(self.target)
  19. def test_copy_plain(self):
  20. copy_modules(['plainmod', 'plainpkg'], self.target, '3.3.5', sample_path)
  21. assert_is_file(pjoin(self.target, 'plainmod.py'))
  22. assert_is_dir(pjoin(self.target, 'plainpkg'))
  23. @unittest.skipIf(sys.platform.startswith("win"), "test for non-Windows platforms")
  24. def test_copy_wrong_platform(self):
  25. with self.assertRaisesRegexp(ExtensionModuleMismatch, "will not be usable on Windows"):
  26. copy_modules(['unix_extmod'], self.target, '3.3.5', sample_path)
  27. with self.assertRaisesRegexp(ExtensionModuleMismatch, "will not be usable on Windows"):
  28. copy_modules(['unix_extpkg'], self.target, '3.3.5', sample_path)
  29. @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
  30. def test_copy_windows(self):
  31. copy_modules(['win_extmod', 'win_extpkg'], self.target, running_python, sample_path)
  32. assert_is_file(pjoin(self.target, 'win_extmod.pyd'))
  33. assert_is_dir(pjoin(self.target, 'win_extpkg'))
  34. @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
  35. def test_copy_wrong_pyversion(self):
  36. with self.assertRaisesRegexp(ExtensionModuleMismatch, "on Python 4"):
  37. copy_modules(['win_extpkg'], self.target, '4.0.0', sample_path)
  38. with self.assertRaisesRegexp(ExtensionModuleMismatch, "on Python 4"):
  39. copy_modules(['win_extmod'], self.target, '4.0.0', sample_path)
  40. def test_copy_from_zipfile(self):
  41. copy_modules(['zippedmod2','zippedpkg2'],
  42. self.target, running_python, sample_path)
  43. # assert_is_file(pjoin(self.target, 'zippedmod.py'))
  44. # assert_is_dir(pjoin(self.target, 'zippedpkg'))
  45. assert_is_file(pjoin(self.target, 'zippedmod2.py'))
  46. assert_is_dir(pjoin(self.target, 'zippedpkg2'))
  47. def test_module_not_found(self):
  48. with self.assertRaises(ImportError):
  49. copy_modules(['nonexistant'], self.target, '3.3.5', sample_path)