def test_envs(): with temp_chdir(): runner = CliRunner() env_name1, env_name2 = get_new_venv_name(count=2) venv_dir1 = os.path.join(VENV_DIR, env_name1) venv_dir2 = os.path.join(VENV_DIR, env_name2) create_venv(venv_dir1) try: result = runner.invoke(hatch, [ 'init', '-ne', '--basic', 'ok', '-e', '{}/{}'.format( env_name1, env_name2) ]) wait_until(is_venv, venv_dir2) with venv(venv_dir1): assert 'ok' in get_editable_packages() with venv(venv_dir2): assert 'ok' in get_editable_packages() finally: remove_path(venv_dir1) remove_path(venv_dir2) assert result.exit_code == 0 assert 'Creating virtual env `{}`... complete!'.format( env_name1) not in result.output assert 'Creating virtual env `{}`... complete!'.format( env_name2) in result.output assert 'Installing locally in virtual env `{}`... complete!'.format( env_name1) in result.output assert 'Installing locally in virtual env `{}`... complete!'.format( env_name2) in result.output
def test_local_editable(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok']) venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir): assert 'ok' not in get_editable_packages() result = runner.invoke(hatch, ['install', '-l']) assert 'ok' in get_editable_packages() assert result.exit_code == 0
def test_project_no_venv_install_dev_requirements(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic', '-ne']) with open(os.path.join(d, 'dev-requirements.txt'), 'w') as f: f.write('six\n') create_test_passing(d) with env_vars({'_IGNORE_VENV_': '1'}): result = runner.invoke(hatch, ['test']) with venv(os.path.join(d, 'venv')): assert 'ok' in get_editable_packages() installed_packages = get_installed_packages(editable=False) assert 'pytest' in installed_packages assert 'coverage' in installed_packages assert 'six' in installed_packages assert result.exit_code == 0 assert 'A project has been detected!' in result.output assert 'Creating a dedicated virtual env... complete!' in result.output assert 'Installing this project in the virtual env...' in result.output assert 'Ensuring pytest and coverage are available...' in result.output assert 'Installing test dependencies in the virtual env...' in result.output assert '1 passed' in result.output
def list_envs(ctx, param, value): if not value or ctx.resilient_parsing: return venvs = get_available_venvs() if venvs: echo_success('Virtual environments found in `{}`:\n'.format( get_venv_dir())) for venv_name, venv_dir in venvs: with venv(venv_dir): echo_success('{} ->'.format(venv_name)) if value == 1: echo_info(' Version: {}'.format(get_python_version())) elif value == 2: echo_info(' Version: {}'.format(get_python_version())) echo_info(' Implementation: {}'.format( get_python_implementation())) else: echo_info(' Version: {}'.format(get_python_version())) echo_info(' Implementation: {}'.format( get_python_implementation())) echo_info(' Local packages: {}'.format(', '.join( sorted(get_editable_packages())))) # I don't want to move users' virtual environments # temporarily for tests as one may be in use. else: # no cov echo_failure('No virtual environments found in `{}`. To create ' 'one do `hatch env NAME`.'.format(get_venv_dir())) ctx.exit()
def test_env(): with temp_chdir() as d: runner = CliRunner() result = runner.invoke(hatch, ['init', 'new-project', '--basic']) venv_dir = os.path.join(d, 'venv') wait_until(is_venv, venv_dir) with venv(venv_dir): assert 'new-project' in get_editable_packages() assert result.exit_code == 0 assert 'Creating its own virtual env... complete!' in result.output assert 'Installing locally in the virtual env... complete!' in result.output
def test_new_env(): with temp_chdir(): runner = CliRunner() env_name = get_new_venv_name() venv_dir = os.path.join(VENV_DIR, env_name) try: result = runner.invoke(hatch, ['init', '--basic', 'ok', env_name]) with venv(venv_dir): assert 'ok' in get_editable_packages() finally: remove_path(venv_dir) assert result.exit_code == 0 assert 'Creating virtual env `{}`...'.format(env_name) in result.output assert 'Installing locally in virtual env `{}`...'.format(env_name) in result.output
def test_project_existing_venv(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok']) runner.invoke(hatch, ['new', 'ko', '-ne']) venv_dir = os.path.join(d, 'venv') package_dir = os.path.join(d, 'ko') wait_until(is_venv, venv_dir) assert os.path.exists(venv_dir) with env_vars({'_IGNORE_VENV_': '1'}): result = runner.invoke(hatch, ['install', package_dir]) wait_for_os() with venv(venv_dir): assert 'ok' in get_editable_packages() assert 'ko' in get_installed_packages(editable=False) assert result.exit_code == 0 assert 'A project has been detected!' not in result.output assert 'Installing for this project...' in result.output