Beispiel #1
0
def test_prepare_bin_dir(tmp_path):
    cmds = {
        'acommand': {
            'entry_point': 'somemod:somefunc',
            'extra_preamble': io.StringIO(u'import extra')
        }
    }
    commands.prepare_bin_directory(tmp_path, cmds)

    exe_file = str(tmp_path / 'acommand.exe')

    assert_isfile(exe_file)

    with open(commands.find_exe(console=True), 'rb') as lf:
        b_launcher = lf.read()
        assert b_launcher[:2] == b'MZ'  # Sanity check

    with open(exe_file, 'rb') as ef:
        b_exe = ef.read()
        assert b_exe[:len(b_launcher)] == b_launcher
        assert b_exe[len(b_launcher):].startswith(
            b"#!<launcher_dir>\\..\\Python\\python.exe\r\n")

    with ZipFile(exe_file) as zf:
        assert zf.testzip() is None
        script_contents = zf.read('__main__.py').decode('utf-8')
    assert 'import extra' in script_contents
    assert 'somefunc()' in script_contents
Beispiel #2
0
def test_prepare_bin_dir(tmpdir):
    commands.prepare_bin_directory(tmpdir, cmds)
    assert_isfile(str(tmpdir / 'acommand.exe'))
    script_file = tmpdir / 'acommand-script.py'
    assert_isfile(str(script_file))

    with script_file.open() as f:
        script_contents = f.read()
    assert script_contents.startswith("#!python")
    assert 'import extra' in script_contents
    assert 'somefunc()' in script_contents

    _rewrite_shebangs.main(['_rewrite_shebangs.py', str(tmpdir)])
    with script_file.open() as f:
        assert f.read().startswith('#!"')
Beispiel #3
0
def test_prepare_bin_dir(tmpdir):
    cmds = {
        'acommand': {
            'entry_point': 'somemod:somefunc',
            'extra_preamble': io.StringIO(u'import extra')
        }
    }
    commands.prepare_bin_directory(tmpdir, cmds)

    launcher_file = str(tmpdir / 'launcher_exe.dat')
    launcher_noconsole_file = str(tmpdir / 'launcher_noconsole_exe.dat')
    zip_file = str(tmpdir / 'acommand-append.zip')
    zip_file_invalid = str(tmpdir / 'acommand-append-noconsole.zip')
    exe_file = str(tmpdir / 'acommand.exe')

    assert_isfile(launcher_file)
    assert_isfile(launcher_noconsole_file)
    assert_isfile(zip_file)
    assert_not_path_exists(zip_file_invalid)
    assert_not_path_exists(exe_file)

    with open(launcher_file, 'rb') as lf:
        b_launcher = lf.read()
        assert b_launcher[:2] == b'MZ'
    with open(launcher_noconsole_file, 'rb') as lf:
        assert lf.read(2) == b'MZ'

    with ZipFile(zip_file) as zf:
        assert zf.testzip() is None
        script_contents = zf.read('__main__.py').decode('utf-8')
    assert 'import extra' in script_contents
    assert 'somefunc()' in script_contents

    _assemble_launchers.main(['_assemble_launchers.py', 'C:\\path\\to\\python', str(tmpdir)])

    assert_isfile(exe_file)

    with open(exe_file, 'rb') as ef, open(zip_file, 'rb') as zf:
        b_exe = ef.read()
        b_zip = zf.read()
        assert b_exe[:len(b_launcher)] == b_launcher
        assert b_exe[len(b_launcher):-len(b_zip)].decode('utf-8') == '#!"C:\\path\\to\\python.exe"\r\n'
        assert b_exe[-len(b_zip):] == b_zip

    with ZipFile(exe_file) as zf:
        assert zf.testzip() is None
        assert zf.read('__main__.py').decode('utf-8') == script_contents
Beispiel #4
0
def test_prepare_bin_dir():
    with TemporaryDirectory() as td:
        td = Path(td)
        commands.prepare_bin_directory(td, cmds)
        assert_isfile(td / 'acommand.exe')
        script_file = td / 'acommand-script.py'
        assert_isfile(script_file)

        with script_file.open() as f:
            script_contents = f.read()
        assert script_contents.startswith("#!python")
        assert_in('import extra', script_contents)
        assert_in('somefunc()', script_contents)

        _rewrite_shebangs.main(['_rewrite_shebangs.py', str(td)])
        with script_file.open() as f:
            assert f.read().startswith('#!"')
Beispiel #5
0
def test_prepare_bin_dir():
    with TemporaryDirectory() as td:
        td = Path(td)
        commands.prepare_bin_directory(td, cmds)
        assert_isfile(td / 'acommand.exe')
        script_file = td / 'acommand-script.py'
        assert_isfile(script_file)

        with script_file.open() as f:
            script_contents = f.read()
        assert script_contents.startswith("#!python")
        assert_in('import extra', script_contents)
        assert_in('somefunc()', script_contents)

        _rewrite_shebangs.main(['_rewrite_shebangs.py', str(td)])
        with script_file.open() as f:
            assert f.read().startswith('#!"')
Beispiel #6
0
def test_prepare_bin_dir(tmpdir):
    commands.prepare_bin_directory(tmpdir, cmds)

    zip_file = str(tmpdir / 'acommand-append.zip')
    exe_file = str(tmpdir / 'acommand.exe')
    assert_isfile(zip_file)
    assert_not_path_exists(exe_file)  # Created by _assemble_launchers

    with ZipFile(zip_file) as zf:
        assert zf.testzip() is None
        script_contents = zf.read('__main__.py').decode('utf-8')
    assert 'import extra' in script_contents
    assert 'somefunc()' in script_contents

    _assemble_launchers.main(['_assemble_launchers.py', str(tmpdir)])

    assert_isfile(exe_file)
    with ZipFile(exe_file) as zf:
        assert zf.testzip() is None
        assert zf.read('__main__.py').decode('utf-8') == script_contents