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'}): runner.invoke(hatch, ['install', package_dir]) wait_for_os() with venv(venv_dir): assert 'ko' in get_installed_packages(editable=False) with env_vars({'_IGNORE_VENV_': '1'}): result = runner.invoke(hatch, ['uninstall', 'ko', '-y']) wait_for_os() with venv(venv_dir): assert 'ko' not in get_installed_packages(editable=False) assert result.exit_code == 0 assert 'A project has been detected!' not in result.output assert 'Uninstalling for this project...' in result.output
def test_project_existing_venv_all_packages(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok']) venv_dir = os.path.join(d, 'venv') wait_until(is_venv, venv_dir) assert os.path.exists(venv_dir) with env_vars({'_IGNORE_VENV_': '1'}): runner.invoke(hatch, ['install', 'six==1.9.0']) wait_for_os() assert os.path.exists(venv_dir) with venv(venv_dir): assert 'ok' in get_installed_packages() initial_version = get_version_as_bytes('six') with env_vars({'_IGNORE_VENV_': '1'}): result = runner.invoke(hatch, ['update', '--all']) wait_for_os() with venv(venv_dir): final_version = get_version_as_bytes('six') assert result.exit_code == 0 assert initial_version < final_version assert 'A project has been detected!' not in result.output assert 'Updating for this project...' in result.output
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 test_cwd_dist_exists(): with temp_chdir(): runner = CliRunner() runner.invoke(hatch, ['init', PACKAGE_NAME, '--basic', '-ne']) runner.invoke(hatch, ['build']) with env_vars(ENV_VARS): result = runner.invoke(hatch, ['release', '-u', USERNAME, '-t']) assert result.exit_code == 0
def test_path_relative(): with temp_chdir(): runner = CliRunner() runner.invoke(hatch, ['init', PACKAGE_NAME, '--basic', '-ne']) runner.invoke(hatch, ['build']) with env_vars(ENV_VARS): result = runner.invoke(hatch, ['release', '-p', 'dist', '-u', USERNAME, '-t']) print(result.output) assert result.exit_code == 0
def venv(d, evars=None): venv_exe_dir = locate_exe_dir(d) evars = evars or {} evars['_HATCHING_'] = '1' evars['VIRTUAL_ENV'] = d evars['PATH'] = '{}{}{}'.format(venv_exe_dir, os.pathsep, os.environ.get('PATH', '')) with env_vars(evars, ignore={'__PYVENV_LAUNCHER__'}): yield venv_exe_dir
def test_cwd(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', PACKAGE_NAME, '--basic']) runner.invoke(hatch, ['build']) os.chdir(os.path.join(d, 'dist')) with env_vars(ENV_VARS): result = runner.invoke(hatch, ['release', '-u', USERNAME, '-t']) assert result.exit_code == 0
def test_config_not_exist(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', PACKAGE_NAME, '--basic', '-ne']) runner.invoke(hatch, ['build']) with temp_move_path(SETTINGS_FILE, d): with env_vars(ENV_VARS): result = runner.invoke(hatch, ['release', '-p', 'dist', '-t']) assert result.exit_code == 1 assert 'Unable to locate config file. Try `hatch config --restore`.' in result.output
def test_project_no_venv_coverage(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic', '-ne']) create_test_complete_coverage(d, 'ok') with env_vars({'_IGNORE_VENV_': '1'}): result = runner.invoke(hatch, ['test', '-c']) assert result.exit_code == 0 assert '1 passed' in result.output assert result.output.strip().endswith(' 100%')
def test_path_full(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['new', PACKAGE_NAME, '--basic', '-ne']) runner.invoke(hatch, ['new', 'ko', '--basic', '-ne']) runner.invoke(hatch, ['build', '-p', PACKAGE_NAME]) build_dir = os.path.join(d, PACKAGE_NAME, 'dist') os.chdir(os.path.join(d, 'ko')) with env_vars(ENV_VARS): result = runner.invoke(hatch, ['release', '-p', build_dir, '-u', USERNAME, '-t']) assert result.exit_code == 0
def venv(d, evars=None): venv_exe_dir = locate_exe_dir(d) evars = evars or {} evars['VIRTUAL_ENV'] = d evars['PATH'] = '{}{}{}'.format(venv_exe_dir, os.pathsep, os.environ.get('PATH', '')) hatch_level = int(os.environ.get('_HATCH_LEVEL_', 0)) evars['_HATCH_LEVEL_'] = str(hatch_level + 1) with env_vars(evars): yield
def test_config_username(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', PACKAGE_NAME, '--basic', '-ne']) runner.invoke(hatch, ['build']) with temp_move_path(SETTINGS_FILE, d): settings = copy_default_settings() settings['pypi_username'] = USERNAME save_settings(settings) with env_vars(ENV_VARS): result = runner.invoke(hatch, ['release', '-p', 'dist', '-t']) assert result.exit_code == 0
def cmd_shell(env_name, nest, shell_path): old_prompt = os.environ.get('PROMPT', '$P$G') new_prompt = '({}) {}'.format(env_name, old_prompt) if nest: if VENV_TEXT.match(old_prompt): new_prompt = VENV_TEXT.sub('({}) '.format(env_name), old_prompt) hatch_level = int(os.environ.get('_HATCH_LEVEL_', 1)) if hatch_level > 1: new_prompt = '{} {}'.format(hatch_level, new_prompt) with env_vars({'PROMPT': new_prompt}): yield [shell_path or 'cmd', '/k']
def test_username_env(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', PACKAGE_NAME, '--basic', '-ne']) runner.invoke(hatch, ['build']) os.chdir(os.path.join(d, 'dist')) with temp_move_path(SETTINGS_FILE, d): settings = copy_default_settings() settings['pypi_username'] = '' save_settings(settings) extra_env_vars = {'TWINE_USERNAME': USERNAME, **ENV_VARS} with env_vars(extra_env_vars): result = runner.invoke(hatch, ['release', '-t']) assert result.exit_code == 0
def test_config_username_empty(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', PACKAGE_NAME, '--basic']) runner.invoke(hatch, ['build']) with temp_move_path(SETTINGS_FILE, d): settings = copy_default_settings() settings['pypi_username'] = '' save_settings(settings) with env_vars(ENV_VARS): result = runner.invoke(hatch, ['release', '-p', 'dist', '-t']) assert result.exit_code == 1 assert ( 'A username must be supplied via -u/--username or ' 'in {} as pypi_username.'.format(SETTINGS_FILE)) in result.output
def zsh_shell(env_name, nest, shell_path): old_prompt = os.environ.get( 'PROMPT', get_prompt([shell_path or 'zsh', '-i', '-c', 'echo $PROMPT'], default='%m%# ')) new_prompt = '({}) {}'.format(env_name, old_prompt) if nest: if VENV_TEXT.match(old_prompt): new_prompt = VENV_TEXT.sub('({}) '.format(env_name), old_prompt) hatch_level = int(os.environ.get('_HATCH_LEVEL_', 1)) if hatch_level > 1: new_prompt = '{} {}'.format(hatch_level, new_prompt) with env_vars({'PROMPT': new_prompt}): yield [shell_path or 'zsh']
def test_project_existing_venv(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic']) venv_dir = os.path.join(d, 'venv') wait_until(is_venv, venv_dir) with venv(venv_dir): install_packages(['pytest', 'coverage']) installed_packages = get_installed_packages(editable=False) assert 'pytest' in installed_packages assert 'coverage' in installed_packages create_test_passing(d) with env_vars({'_IGNORE_VENV_': '1'}): result = runner.invoke(hatch, ['test']) assert result.exit_code == 0 assert '1 passed' in result.output
def test_project_no_venv(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '-ne']) venv_dir = os.path.join(d, 'venv') assert not os.path.exists(venv_dir) with env_vars({'_IGNORE_VENV_': '1'}): result = runner.invoke(hatch, ['uninstall', 'ko', '-y']) wait_until(is_venv, venv_dir) assert os.path.exists(venv_dir) assert result.exit_code == 2 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... complete!' in result.output assert 'New virtual envs have nothing to uninstall, exiting...' in result.output assert 'Uninstalling for this project...' not in result.output
def test_project_no_venv(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '-ne']) venv_dir = os.path.join(d, 'venv') assert not os.path.exists(venv_dir) with env_vars({'_IGNORE_VENV_': '1'}): result = runner.invoke(hatch, ['update', 'six']) wait_until(is_venv, venv_dir) assert os.path.exists(venv_dir) with venv(venv_dir): assert 'ok' in get_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... complete!' in result.output assert 'Updating for this project...' in result.output