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