test_commands.py 987 B

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