示例#1
0
def test_non_package_with_pip(tmp_directory):
    _write_sample_pip_req()

    Path('setup.py').write_text(setup_py)
    name = f'venv-{Path(tmp_directory).name}'

    runner = CliRunner()
    result = runner.invoke(install, catch_exceptions=False)

    assert Path('.gitignore').read_text() == f'\n{name}\n'
    assert Path('requirements.lock.txt').exists()
    assert result.exit_code == 0
示例#2
0
def test_install_pip_does_not_duplicate_gitignore_entry(tmp_directory):
    _write_sample_pip_req()

    Path('setup.py').write_text(setup_py)
    name = f'venv-{Path(tmp_directory).name}'

    Path('.gitignore').write_text(f'{name}\n')

    runner = CliRunner()
    result = runner.invoke(install, catch_exceptions=False)

    # the entry was already there, should not duplicate
    assert Path('.gitignore').read_text() == f'{name}\n'
    assert result.exit_code == 0
示例#3
0
def test_install_lock_pip(tmp_directory, mock_cmdr_wrapped, create_setup_py,
                          create_dev_lock):
    _write_sample_pip_req('requirements.lock.txt')

    if create_dev_lock:
        _write_sample_pip_req('requirements.dev.lock.txt')

    if create_setup_py:
        Path('setup.py').write_text(setup_py)

    runner = CliRunner()
    result = runner.invoke(install, args='--use-lock', catch_exceptions=False)

    venv, pip = _get_venv_and_pip()

    expected = [
        call('python', '-m', 'venv', venv, description='Creating venv'),
        call(pip,
             'install',
             '--editable',
             '.',
             description='Installing project'),
        call(pip,
             'install',
             '--requirement',
             'requirements.lock.txt',
             description='Installing dependencies'),
        call(pip,
             'install',
             '--requirement',
             'requirements.dev.lock.txt',
             description='Installing dependencies')
    ]

    if not create_setup_py:
        expected.pop(1)

    if not create_dev_lock:
        expected.pop(-1)

    assert mock_cmdr_wrapped.call_args_list == expected
    assert Path('.gitignore').read_text() == f'\n{venv}\n'
    assert result.exit_code == 0
示例#4
0
def test_install_pip(tmp_directory):
    _write_sample_pip_req()

    Path('setup.py').write_text(setup_py)
    name = f'venv-{Path(tmp_directory).name}'

    runner = CliRunner()
    result = runner.invoke(install, catch_exceptions=False)

    if os.name == 'nt':
        expected_command = (
            f'\nIf using cmd.exe: {name}\\Scripts\\activate.bat'
            f'\nIf using PowerShell: {name}\\Scripts\\Activate.ps1')
    else:
        expected_command = f'source {name}/bin/activate'

    assert Path('.gitignore').read_text() == f'\n{name}\n'
    assert expected_command in result.stdout
    assert Path('requirements.lock.txt').exists()
    assert result.exit_code == 0