Ejemplo n.º 1
0
def test_install_dependencies_with_preinstall_with_requirements(callmock):
    d = Deployment("test", preinstall=["foobar"])
    d.pip_prefix = ["pip", "install"]
    d.install_dependencies()
    callmock.assert_has_calls(
        [call(["pip", "install", "foobar"]), call(["pip", "install", "-r", "./requirements.txt"])]
    )
Ejemplo n.º 2
0
def test_upgrade_pip_with_preinstall(callmock):
    d = Deployment('test', upgrade_pip=True, preinstall=['foobar'])
    d.pip_prefix = ['pip', 'install']
    d.install_dependencies()
    callmock.assert_has_calls([
        call(['pip', 'install', '-U', 'pip']),
        call(['pip', 'install', 'foobar'])])
Ejemplo n.º 3
0
def test_create_venv_with_setuptools(callmock):
    d = Deployment('test', setuptools=True)
    d.create_virtualenv()
    eq_(TEST_VENV_PATH, d.package_dir)
    callmock.assert_called_with(['virtualenv', '--setuptools', TEST_VENV_PATH])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', LOG_ARG], d.pip_args)
Ejemplo n.º 4
0
def test_upgrade_pip(callmock):
    d = Deployment('test', upgrade_pip=True)
    d.pip_prefix = d.pip_preinstall_prefix = ['pip']
    d.pip_args = ['install']
    d.install_dependencies()
    callmock.assert_called_with(
        ['pip', 'install', ANY, '-U', 'pip'])
Ejemplo n.º 5
0
def test_install_dependencies_with_preinstall(callmock):
    d = Deployment('test', preinstall=['foobar'])
    d.pip_prefix = d.pip_preinstall_prefix = ['pip']
    d.pip_args = ['install']
    d.install_dependencies()
    callmock.assert_called_with(
        ['pip', 'install', 'foobar'])
Ejemplo n.º 6
0
def test_create_venv_with_verbose(callmock):
    d = Deployment('test', verbose=True)
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 '--verbose',
                                 'debian/test/opt/venvs/test'])
Ejemplo n.º 7
0
def test_create_venv_with_verbose(callmock):
    d = Deployment('test', verbose=True)
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 '--verbose',
                                 'debian/test/opt/venvs/test'])
Ejemplo n.º 8
0
def test_create_venv_with_extra_virtualenv(callmock):
    d = Deployment('test', extra_virtualenv_arg=["--never-download"])
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 '--never-download',
                                 'debian/test/opt/venvs/test'])
Ejemplo n.º 9
0
def test_upgrade_pip(callmock):
    d = Deployment('test', upgrade_pip=True)
    d.pip_prefix = d.pip_preinstall_prefix = ['pip']
    d.pip_args = ['install']
    d.install_dependencies()
    callmock.assert_called_with(
        ['pip', 'install', ANY, '-U', 'pip'])
Ejemplo n.º 10
0
def test_install_dependencies_with_requirements(callmock):
    d = Deployment('test')
    d.pip_prefix = ['pip']
    d.pip_args = ['install']
    d.install_dependencies()
    callmock.assert_called_with(
        ['pip', 'install', '-r', './requirements.txt'])
Ejemplo n.º 11
0
def test_install_dependencies_with_preinstall(callmock):
    d = Deployment('test', preinstall=['foobar'])
    d.pip_prefix = d.pip_preinstall_prefix = ['pip']
    d.pip_args = ['install']
    d.install_dependencies()
    callmock.assert_called_with(
        ['pip', 'install', 'foobar'])
Ejemplo n.º 12
0
def test_fix_activate_path():
    deployment = Deployment('test')
    temp = tempfile.NamedTemporaryFile()

    with open(temp.name, 'w') as fh:
        fh.write(textwrap.dedent("""
            other things

            VIRTUAL_ENV="/this/path/is/wrong/and/longer/than/new/path"

            more other things
        """))

    expected = textwrap.dedent("""
        other things

        VIRTUAL_ENV="/usr/share/python/test"

        more other things
    """)

    with patch('dh_virtualenv.deployment.os.path.join',
               return_value=temp.name):
        deployment.fix_activate_path()

    with open(temp.name) as fh:
        eq_(expected, temp.read())
Ejemplo n.º 13
0
def test_venv_with_custom_python(callmock):
    d = Deployment('test', python='/tmp/python')
    d.create_virtualenv()
    eq_(TEST_VENV_PATH, d.package_dir)
    callmock.assert_called_with(['virtualenv', '--python', '/tmp/python', TEST_VENV_PATH])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', LOG_ARG], d.pip_args)
Ejemplo n.º 14
0
def test_fix_activate_path():
    deployment = Deployment('test')
    temp = tempfile.NamedTemporaryFile()

    with open(temp.name, 'w') as fh:
        fh.write(
            textwrap.dedent("""
            other things

            VIRTUAL_ENV="/this/path/is/wrong/and/longer/than/new/path"

            more other things
        """))

    expected = textwrap.dedent("""
        other things

        VIRTUAL_ENV="/usr/share/python/test"

        more other things
    """)

    with patch('dh_virtualenv.deployment.os.path.join',
               return_value=temp.name):
        deployment.fix_activate_path()

    with open(temp.name) as fh:
        eq_(expected, temp.read())
Ejemplo n.º 15
0
def test_create_venv_with_extra_virtualenv(callmock):
    d = Deployment('test', extra_virtualenv_arg=["--never-download"])
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 '--never-download',
                                 'debian/test/usr/share/python/test'])
Ejemplo n.º 16
0
def test_create_venv_with_system_packages(callmock):
    d = Deployment('test', use_system_packages=True)
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--system-site-packages',
                                 'debian/test/opt/venvs/test'])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', LOG_ARG], d.pip_args)
Ejemplo n.º 17
0
def test_install_dependencies_with_preinstall_with_requirements(callmock):
    d = Deployment('test', preinstall=['foobar'])
    d.pip_prefix = ['pip', 'install']
    d.install_dependencies()
    callmock.assert_has_calls([
        call(['pip', 'install', 'foobar']),
        call(['pip', 'install', '-r', './requirements.txt'])
    ])
Ejemplo n.º 18
0
def test_testrunner(callmock):
    d = Deployment('test')
    d.run_tests()
    callmock.assert_called_once_with([
        PY_CMD,
        'setup.py',
        'test',
    ], cwd='.')
Ejemplo n.º 19
0
def test_testrunner(callmock):
    d = Deployment('test')
    d.run_tests()
    callmock.assert_called_once_with([
        'debian/test/usr/share/python/test/bin/python',
        'setup.py',
        'test',
    ])
Ejemplo n.º 20
0
def test_create_venv_with_extra_urls(callmock):
    d = Deployment('test', extra_urls=['foo', 'bar'])
    d.create_virtualenv()
    eq_(TEST_VENV_PATH, d.package_dir)
    callmock.assert_called_with(['virtualenv', TEST_VENV_PATH])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', '--extra-index-url=foo', '--extra-index-url=bar', LOG_ARG],
        d.pip_args)
Ejemplo n.º 21
0
def test_install_dependencies_with_preinstall_with_requirements(callmock):
    d = Deployment('test', preinstall=['foobar'])
    d.pip_prefix = ['pip', 'install']
    d.install_dependencies()
    callmock.assert_has_calls([
        call(['pip', 'install', 'foobar']),
        call(['pip', 'install', '-r', 'requirements.txt'])
    ])
Ejemplo n.º 22
0
def test_create_venv_with_system_packages(callmock):
    d = Deployment('test', use_system_packages=True)
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(
        ['virtualenv', '--system-site-packages', 'debian/test/opt/venvs/test'])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', LOG_ARG], d.pip_args)
Ejemplo n.º 23
0
def test_testrunner(callmock):
    d = Deployment('test')
    d.run_tests()
    callmock.assert_called_once_with([
        'debian/test/usr/share/python/test/bin/python',
        'setup.py',
        'test',
    ])
Ejemplo n.º 24
0
def test_install_package(callmock):
    d = Deployment('test')
    d.bin_dir = 'derp'
    d.pip_prefix = ['derp/python', 'derp/pip']
    d.install_package()
    callmock.assert_called_with([
        'derp/python', 'derp/pip', '.',
    ], cwd=os.getcwd())
Ejemplo n.º 25
0
def test_testrunner(callmock):
    d = Deployment('test')
    d.run_tests()
    callmock.assert_called_once_with([
        PY_CMD,
        'setup.py',
        'test',
    ], cwd='.')
Ejemplo n.º 26
0
def test_upgrade_pip_with_preinstall(callmock):
    d = Deployment('test', upgrade_pip=True, preinstall=['foobar'])
    d.pip_prefix = d.pip_preinstall_prefix = ['pip']
    d.pip_args = ['install']
    d.install_dependencies()
    callmock.assert_has_calls([
        call(['pip', 'install', ANY, '-U', 'pip']),
        call(['pip', 'install', 'foobar'])])
Ejemplo n.º 27
0
def test_create_venv(callmock):
    d = Deployment('test')
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with([
        'virtualenv', '--no-site-packages', 'debian/test/usr/share/python/test'
    ])
    eq_([PY_CMD, PIP_CMD, 'install', '--log=' + os.path.abspath('foo')],
        d.pip_prefix)
Ejemplo n.º 28
0
def test_install_package(callmock):
    d = Deployment('test')
    d.bin_dir = 'derp'
    d.install_package()
    callmock.assert_called_with([
        'derp/python', 'setup.py', 'install', '--record', 'foo',
        '--install-headers',
        'debian/test/usr/share/python/test/include/site/python2.6'
    ])
Ejemplo n.º 29
0
def test_create_venv_with_extra_urls(callmock):
    d = Deployment('test', extra_urls=['foo', 'bar'])
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(
        ['virtualenv', '--no-site-packages', 'debian/test/opt/venvs/test'])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', '--extra-index-url=foo', '--extra-index-url=bar', LOG_ARG],
        d.pip_args)
Ejemplo n.º 30
0
def test_venv_with_custom_python(callmock):
    d = Deployment('test', python='/tmp/python')
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 '--python', '/tmp/python',
                                 'debian/test/opt/venvs/test'])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', LOG_ARG], d.pip_args)
Ejemplo n.º 31
0
def test_create_venv_with_extra_pip_arg(callmock):
    d = Deployment('test', extra_pip_arg=['--no-compile'])
    d.create_virtualenv()
    d.install_dependencies()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 'debian/test/opt/venvs/test'])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', LOG_ARG, '--no-compile'], d.pip_args)
Ejemplo n.º 32
0
def test_venv_with_custom_python(callmock):
    d = Deployment('test', python='/tmp/python')
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 '--python', '/tmp/python',
                                 'debian/test/opt/venvs/test'])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', LOG_ARG], d.pip_args)
Ejemplo n.º 33
0
def test_create_venv_with_extra_urls(callmock):
    d = Deployment('test', extra_urls=['foo', 'bar'])
    d.create_virtualenv()
    eq_('debian/test/opt/venvs/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 'debian/test/opt/venvs/test'])
    eq_([PY_CMD, PIP_CMD], d.pip_prefix)
    eq_(['install', '--extra-index-url=foo',
         '--extra-index-url=bar',
         LOG_ARG], d.pip_args)
Ejemplo n.º 34
0
def test_create_builtin_venv_with_unsupported_options(callmock):
    d = Deployment('test',
                   python='python_interpreter',
                   builtin_venv=True,
                   setuptools=True,
                   verbose=True)
    d.create_virtualenv()
    eq_(TEST_VENV_PATH, d.package_dir)
    callmock.assert_called_with(
        ['python_interpreter', '-m', 'venv', TEST_VENV_PATH])
Ejemplo n.º 35
0
def test_install_package(callmock):
    d = Deployment('test')
    d.bin_dir = 'derp'
    d.install_package()
    callmock.assert_called_with([
        'derp/python', 'setup.py', 'install',
        '--record', 'foo',
        '--install-headers',
        'debian/test/usr/share/python/test/include/site/python2.6'
    ])
Ejemplo n.º 36
0
def test_create_venv_with_system_packages(callmock):
    d = Deployment('test', use_system_packages=True)
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--system-site-packages',
                                 'debian/test/usr/share/python/test'])
    eq_([PY_CMD,
         PIP_CMD,
         'install',
         '--log=' + os.path.abspath('foo')], d.pip_prefix)
Ejemplo n.º 37
0
def test_create_venv(callmock):
    d = Deployment('test')
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 'debian/test/usr/share/python/test'])
    eq_(['debian/test/usr/share/python/test/bin/python',
         'debian/test/usr/share/python/test/bin/pip',
         'install',
         '--log=foo'], d.pip_prefix)
Ejemplo n.º 38
0
def test_custom_src_dir(callmock):
    d = Deployment("test")
    d.pip_prefix = ["pip", "install"]
    d.sourcedirectory = "root/srv/application"
    d.create_virtualenv()
    d.install_dependencies()
    callmock.assert_called_with(
        [
            "debian/test/usr/share/python/test/bin/python",
            "debian/test/usr/share/python/test/bin/pip",
            "install",
            "--log=foo",
            "-r",
            "root/srv/application/requirements.txt",
        ]
    )
    d.install_package()
    callmock.assert_called_with(
        [
            "debian/test/usr/share/python/test/bin/python",
            "debian/test/usr/share/python/test/bin/pip",
            "install",
            "--log=foo",
            "root/srv/application",
        ]
    )
Ejemplo n.º 39
0
def test_create_venv(callmock):
    d = Deployment('test')
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with([
        'virtualenv', '--no-site-packages', 'debian/test/usr/share/python/test'
    ])
    eq_([
        'debian/test/usr/share/python/test/bin/python',
        'debian/test/usr/share/python/test/bin/pip', 'install', '--log=foo'
    ], d.pip_prefix)
Ejemplo n.º 40
0
def test_create_venv_with_extra_urls(callmock):
    d = Deployment('test', extra_urls=['foo', 'bar'])
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 'debian/test/usr/share/python/test'])
    eq_(['debian/test/usr/share/python/test/bin/python',
         'debian/test/usr/share/python/test/bin/pip',
         'install', '--extra-index-url=foo',
         '--extra-index-url=bar',
         '--log=foo'], d.pip_prefix)
Ejemplo n.º 41
0
def test_venv_with_custom_python(callmock):
    d = Deployment('test', python='/tmp/python')
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 '--python', '/tmp/python',
                                 'debian/test/usr/share/python/test'])
    eq_([PY_CMD,
         PIP_CMD,
         'install',
         '--log=' + os.path.abspath('foo')], d.pip_prefix)
Ejemplo n.º 42
0
def test_fix_local_symlinks(deployment_dir):
    d = Deployment('testing')
    d.package_dir = deployment_dir

    local = os.path.join(deployment_dir, 'local')
    os.makedirs(local)
    target = os.path.join(deployment_dir, 'sometarget')
    symlink = os.path.join(local, 'symlink')
    os.symlink(target, symlink)

    d.fix_local_symlinks()
    eq_(os.readlink(symlink), '../sometarget')
Ejemplo n.º 43
0
def test_fix_local_symlinks(deployment_dir):
    d = Deployment("testing")
    d.package_dir = deployment_dir

    local = os.path.join(deployment_dir, "local")
    os.makedirs(local)
    target = os.path.join(deployment_dir, "sometarget")
    symlink = os.path.join(local, "symlink")
    os.symlink(target, symlink)

    d.fix_local_symlinks()
    eq_(os.readlink(symlink), "../sometarget")
Ejemplo n.º 44
0
def test_fix_local_symlinks_with_relative_links(deployment_dir):
    # Runs shouldn't ruin the already relative symlinks.
    d = Deployment('testing')
    d.package_dir = deployment_dir

    local = os.path.join(deployment_dir, 'local')
    os.makedirs(local)
    symlink = os.path.join(local, 'symlink')
    os.symlink('../target', symlink)

    d.fix_local_symlinks()
    eq_(os.readlink(symlink), '../target')
Ejemplo n.º 45
0
def test_custom_pip_tool_used_for_installation(callmock, _):
    d = Deployment(
        'test', preinstall=['pip-custom-platform'],
        pip_tool='pip-custom-platform',
    )
    d.install_dependencies()
    d.install_package()
    callmock.assert_has_calls([
        call([PY_CMD, PIP_CMD, 'install', LOG_ARG, 'pip-custom-platform']),
        call([PY_CMD, CUSTOM_PIP_CMD, 'install', LOG_ARG, '-r', './requirements.txt']),
        call([PY_CMD, CUSTOM_PIP_CMD, 'install', LOG_ARG, '.'], cwd=os.path.abspath('.')),
    ])
Ejemplo n.º 46
0
def test_fix_local_symlinks_with_relative_links(deployment_dir):
        # Runs shouldn't ruin the already relative symlinks.
        d = Deployment('testing')
        d.package_dir = deployment_dir

        local = os.path.join(deployment_dir, 'local')
        os.makedirs(local)
        symlink = os.path.join(local, 'symlink')
        os.symlink('../target', symlink)

        d.fix_local_symlinks()
        eq_(os.readlink(symlink), '../target')
Ejemplo n.º 47
0
def test_fix_local_symlinks(deployment_dir):
        d = Deployment('testing')
        d.package_dir = deployment_dir

        local = os.path.join(deployment_dir, 'local')
        os.makedirs(local)
        target = os.path.join(deployment_dir, 'sometarget')
        symlink = os.path.join(local, 'symlink')
        os.symlink(target, symlink)

        d.fix_local_symlinks()
        eq_(os.readlink(symlink), '../sometarget')
Ejemplo n.º 48
0
def test_create_venv_with_extra_urls(callmock):
    d = Deployment('test', extra_urls=['foo', 'bar'])
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with([
        'virtualenv', '--no-site-packages', 'debian/test/usr/share/python/test'
    ])
    eq_([
        'debian/test/usr/share/python/test/bin/python',
        'debian/test/usr/share/python/test/bin/pip', 'install',
        '--extra-index-url=foo', '--extra-index-url=bar', '--log=foo'
    ], d.pip_prefix)
Ejemplo n.º 49
0
def test_create_venv_with_extra_pip_arg(callmock):
    d = Deployment('test', extra_pip_arg=['--no-compile'])
    d.create_virtualenv()
    d.install_dependencies()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 'debian/test/usr/share/python/test'])
    eq_([PY_CMD,
         PIP_CMD,
         'install',
         '--log=' + os.path.abspath('foo'),
         '--no-compile'], d.pip_prefix)
Ejemplo n.º 50
0
def test_fix_local_symlinks_with_relative_links(deployment_dir):
    # Runs shouldn't ruin the already relative symlinks.
    d = Deployment("testing")
    d.package_dir = deployment_dir

    local = os.path.join(deployment_dir, "local")
    os.makedirs(local)
    symlink = os.path.join(local, "symlink")
    os.symlink("../target", symlink)

    d.fix_local_symlinks()
    eq_(os.readlink(symlink), "../target")
Ejemplo n.º 51
0
def test_create_venv_with_custom_index_url(callmock):
    d = Deployment('test',
                   extra_urls=['foo', 'bar'],
                   pypi_url='http://example.com/simple')
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with([
        'virtualenv', '--no-site-packages', 'debian/test/usr/share/python/test'
    ])
    eq_([
        PY_CMD, PIP_CMD, 'install', '--pypi-url=http://example.com/simple',
        '--extra-index-url=foo', '--extra-index-url=bar',
        '--log=' + os.path.abspath('foo')
    ], d.pip_prefix)
Ejemplo n.º 52
0
def test_find_script_files_normal_shebang(bin_dir):
    d = Deployment('testing')
    d.bin_dir = bin_dir

    script_files = [os.path.join(bin_dir, s) for s in ('s1', 's2', 's3')]
    for script in script_files:
        with open(os.path.join(bin_dir, script), 'w') as f:
            f.write('#!/usr/bin/python\n')

    with open(os.path.join(bin_dir, 'n1'), 'w') as f:
        f.write('#!/bin/bash')

    found_files = sorted(d.find_script_files())
    eq_(found_files, script_files)
Ejemplo n.º 53
0
def test_create_venv(callmock):
    d = Deployment("test")
    d.create_virtualenv()
    eq_("debian/test/usr/share/python/test", d.package_dir)
    callmock.assert_called_with(["virtualenv", "--no-site-packages", "debian/test/usr/share/python/test"])
    eq_(
        [
            "debian/test/usr/share/python/test/bin/python",
            "debian/test/usr/share/python/test/bin/pip",
            "install",
            "--log=foo",
        ],
        d.pip_prefix,
    )
Ejemplo n.º 54
0
def test_create_venv_with_custom_index_url(callmock):
    d = Deployment('test', extra_urls=['foo', 'bar'],
                   pypi_url='http://example.com/simple')
    d.create_virtualenv()
    eq_('debian/test/usr/share/python/test', d.package_dir)
    callmock.assert_called_with(['virtualenv', '--no-site-packages',
                                 'debian/test/usr/share/python/test'])
    eq_(['debian/test/usr/share/python/test/bin/python',
         'debian/test/usr/share/python/test/bin/pip',
         'install',
         '--pypi-url=http://example.com/simple',
         '--extra-index-url=foo',
         '--extra-index-url=bar',
         '--log=foo'], d.pip_prefix)
Ejemplo n.º 55
0
def test_deployment_from_options_with_verbose():
        options, _ = get_default_parser().parse_args([
            '--verbose'
        ])
        d = Deployment.from_options('foo', options)
        eq_(d.package, 'foo')
        eq_(d.verbose, True)
Ejemplo n.º 56
0
def test_find_script_files_long_shebang(bin_dir):
    d = Deployment('testing')
    d.bin_dir = bin_dir

    script_files = [os.path.join(bin_dir, s) for s in ('s1', 's2', 's3')]
    for script in script_files:
        with open(os.path.join(bin_dir, script), 'w') as f:
            # It does not really matter what we write into the
            # exec statement as executable here
            f.write(create_new_style_shebang('/usr/bin/python'))

    with open(os.path.join(bin_dir, 'n1'), 'w') as f:
        f.write('#!/bin/bash')

    found_files = sorted(d.find_script_files())
    eq_(found_files, script_files)
Ejemplo n.º 57
0
def check_shebangs_fix(interpreter, path):
    """Checks shebang substitution for the given interpreter"""
    deployment = Deployment('test')
    temp = tempfile.NamedTemporaryFile()
    # We cheat here a little. The fix_shebangs walks through the
    # project directory, however we can just point to a single
    # file, as the underlying mechanism is just grep -r.
    deployment.bin_dir = temp.name
    expected_shebang = '#!' + os.path.join(path, 'bin/python') + '\n'

    with open(temp.name, 'w') as f:
        f.write('#!/usr/bin/{0}\n'.format(interpreter))

    deployment.fix_shebangs()

    with open(temp.name) as f:
        eq_(f.read(), expected_shebang)

    with open(temp.name, 'w') as f:
        f.write('#!/usr/bin/env {0}\n'.format(interpreter))

    deployment.fix_shebangs()

    with open(temp.name) as f:
        eq_(f.readline(), expected_shebang)
Ejemplo n.º 58
0
def test_deployment_from_options():
    options, _ = get_default_parser().parse_args([
        '--extra-index-url', 'http://example.com', '-O--pypi-url',
        'http://example.org'
    ])
    d = Deployment.from_options('foo', options)
    eq_(d.package, 'foo')
    eq_(d.pypi_url, 'http://example.org')
    eq_(d.extra_urls, ['http://example.com'])
Ejemplo n.º 59
0
def test_custom_src_dir(callmock):
    d = Deployment('test')
    d.pip_prefix = ['pip', 'install']
    d.sourcedirectory = 'root/srv/application'
    d.create_virtualenv()
    d.install_dependencies()
    callmock.assert_called_with([
        'debian/test/usr/share/python/test/bin/python',
        'debian/test/usr/share/python/test/bin/pip', 'install', '--log=foo',
        '-r', 'root/srv/application/requirements.txt'
    ], )
    d.install_package()
    callmock.assert_called_with([
        'debian/test/usr/share/python/test/bin/python',
        'debian/test/usr/share/python/test/bin/pip',
        'install',
        '--log=foo',
        'root/srv/application',
    ])
Ejemplo n.º 60
0
def test_custom_src_dir(callmock):
    d = Deployment('test')
    d.pip_prefix = ['pip', 'install']
    d.sourcedirectory = 'root/srv/application'
    d.create_virtualenv()
    d.install_dependencies()
    callmock.assert_called_with([
        PY_CMD, PIP_CMD, 'install', '--log=' + os.path.abspath('foo'), '-r',
        'root/srv/application/requirements.txt'
    ], )
    d.install_package()
    callmock.assert_called_with([
        PY_CMD,
        PIP_CMD,
        'install',
        '--log=' + os.path.abspath('foo'),
        '.',
    ],
                                cwd=os.path.abspath('root/srv/application'))