test_commands.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import io
  2. from nose.tools import *
  3. try:
  4. from pathlib import Path
  5. except ImportError:
  6. from pathlib2 import Path # Backport
  7. from testpath.tempdir import TemporaryDirectory
  8. from testpath import assert_isfile
  9. from nsist import commands, _rewrite_shebangs
  10. cmds = {'acommand': {
  11. 'entry_point': 'somemod:somefunc',
  12. 'extra_preamble': io.StringIO(u'import extra')
  13. }}
  14. def test_prepare_bin_dir():
  15. with TemporaryDirectory() as td:
  16. td = Path(td)
  17. commands.prepare_bin_directory(td, cmds)
  18. assert_isfile(str(td / 'acommand.exe'))
  19. script_file = td / 'acommand-script.py'
  20. assert_isfile(str(script_file))
  21. with script_file.open() as f:
  22. script_contents = f.read()
  23. assert script_contents.startswith("#!python")
  24. assert_in('import extra', script_contents)
  25. assert_in('somefunc()', script_contents)
  26. _rewrite_shebangs.main(['_rewrite_shebangs.py', str(td)])
  27. with script_file.open() as f:
  28. assert f.read().startswith('#!"')