test_commands.py 1019 B

1234567891011121314151617181920212223242526272829
  1. import io
  2. from testpath import assert_isfile, assert_not_path_exists
  3. from zipfile import ZipFile
  4. from nsist import commands, _assemble_launchers
  5. cmds = {'acommand': {'entry_point': 'somemod:somefunc',
  6. 'extra_preamble': io.StringIO(u'import extra')}}
  7. def test_prepare_bin_dir(tmpdir):
  8. commands.prepare_bin_directory(tmpdir, cmds)
  9. zip_file = str(tmpdir / 'acommand-append.zip')
  10. exe_file = str(tmpdir / 'acommand.exe')
  11. assert_isfile(zip_file)
  12. assert_not_path_exists(exe_file) # Created by _assemble_launchers
  13. with ZipFile(zip_file) as zf:
  14. assert zf.testzip() is None
  15. script_contents = zf.read('__main__.py').decode('utf-8')
  16. assert 'import extra' in script_contents
  17. assert 'somefunc()' in script_contents
  18. _assemble_launchers.main(['_assemble_launchers.py', str(tmpdir)])
  19. assert_isfile(exe_file)
  20. with ZipFile(exe_file) as zf:
  21. assert zf.testzip() is None
  22. assert zf.read('__main__.py').decode('utf-8') == script_contents