test_commands.py 910 B

1234567891011121314151617181920212223242526272829
  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. tmpdir = Path(tmpdir)
  12. commands.prepare_bin_directory(tmpdir, cmds)
  13. assert_is_file(str(tmpdir / 'acommand.exe'))
  14. script_file = tmpdir / 'acommand-script.py'
  15. assert_is_file(str(script_file))
  16. with script_file.open() as f:
  17. script_contents = f.read()
  18. assert script_contents.startswith("#!python")
  19. assert 'import extra' in script_contents
  20. assert 'somefunc()' in script_contents
  21. _rewrite_shebangs.main(['_rewrite_shebangs.py', str(tmpdir)])
  22. with script_file.open() as f:
  23. assert f.read().startswith('#!"')