test_commands.py 884 B

12345678910111213141516171819202122232425262728
  1. import io
  2. try:
  3. from pathlib import Path
  4. except ImportError:
  5. from pathlib2 import Path # Backport
  6. from nsist import commands, _rewrite_shebangs
  7. from .utils import assert_is_file
  8. cmds = {'acommand': {'entry_point': 'somemod:somefunc',
  9. 'extra_preamble': io.StringIO(u'import extra')}}
  10. def test_prepare_bin_dir(tmpdir):
  11. commands.prepare_bin_directory(tmpdir, cmds)
  12. assert_is_file(str(tmpdir / 'acommand.exe'))
  13. script_file = tmpdir / 'acommand-script.py'
  14. assert_is_file(str(script_file))
  15. with script_file.open() as f:
  16. script_contents = f.read()
  17. assert script_contents.startswith("#!python")
  18. assert 'import extra' in script_contents
  19. assert 'somefunc()' in script_contents
  20. _rewrite_shebangs.main(['_rewrite_shebangs.py', str(tmpdir)])
  21. with script_file.open() as f:
  22. assert f.read().startswith('#!"')