def test_clone_venv_not_exist(): with temp_chdir(): runner = CliRunner() env_name = os.urandom(10).hex() while os.path.exists(os.path.join(VENV_DIR, env_name)): # no cov env_name = os.urandom(10).hex() result = runner.invoke(hatch, ['env', env_name, '-c', env_name]) assert result.exit_code == 1 assert 'Virtual env `{name}` does not exist.'.format( name=env_name) in result.output
def test_list_success(): with temp_chdir() as d: runner = CliRunner() with temp_move_path(SETTINGS_FILE, d): settings = copy_default_settings() settings['pypaths']['name1'] = 'path1' settings['pypaths']['name2'] = 'path2' save_settings(settings) result = runner.invoke(hatch, ['pypath', '-l']) assert result.exit_code == 0 assert 'name1 -> path1\nname2 -> path2' in result.output
def test_build_matrix_pypy3(): with temp_chdir() as d: settings = copy_default_settings() settings['basic'] = False settings['ci'] = ['travis'] settings['pyversions'] = ['pypy3'] create_package(d, 'ok', settings) contents = read_file(os.path.join(d, '.travis.yml')) parsed = parse(TEMPLATE, contents) assert parsed['build_matrix'] == ('\n - python: pypy3.5-5.8.0' '\n env: TOXENV=pypy3')
def test_success(): with temp_chdir() as d: runner = CliRunner() with temp_move_path(SETTINGS_FILE, d): restore_settings() result = runner.invoke(hatch, ['pypath', 'name', 'path']) settings = load_settings() assert settings['pypaths']['name'] == 'path' assert result.exit_code == 0 assert 'Successfully saved Python `name` located at `path`.' in result.output
def test_get_editable_package_location(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['new', 'foo', '--basic', '-ne']) runner.invoke(hatch, ['new', 'bar', '--basic', '-ne']) venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir): install_packages(['-e', os.path.join(d, 'foo')]) install_packages(['-e', os.path.join(d, 'bar')]) assert get_editable_package_location('foo') == os.path.join(d, 'foo')
def test_project_no_venv_coverage_merge(): 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'}): runner.invoke(hatch, ['test', '-c']) result = runner.invoke(hatch, ['test', '-c', '-m']) assert result.exit_code == 0 assert '1 passed' in result.output assert result.output.strip().endswith(' 100%')
def test_build_matrix_multiple(): with temp_chdir() as d: settings = copy_default_settings() settings['pyversions'] = ['2.7', '3.6'] create_package(d, 'ok', settings) contents = read_file(os.path.join(d, 'tox.ini')) parsed = parse(TEMPLATE, contents) assert parsed['build_matrix'] == ( '\n py27,' '\n py36,' )
def test_python_invalid(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic', '-ne']) with temp_move_path(SETTINGS_FILE, d): settings = copy_default_settings() settings['pypaths']['python'] = '' save_settings(settings) result = runner.invoke(hatch, ['build', '-py', 'python']) assert result.exit_code == 1 assert 'Python path named `python` does not exist or is invalid.' in result.output
def test_path_relative(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['egg', 'ok', '--basic']) result = runner.invoke(hatch, ['grow', 'major', '-p', 'ok']) init_file = os.path.join(d, 'ok', 'ok', '__init__.py') contents = read_file(init_file) assert result.exit_code == 0 assert contents == "__version__ = '1.0.0'\n" assert 'Updated {}'.format(init_file) in result.output assert '0.0.1 -> 1.0.0' in result.output
def test_pyname(): with temp_chdir() as d: runner = CliRunner() with temp_move_path(SETTINGS_FILE, d): settings = copy_default_settings() settings['pypaths']['pyname'] = 'pypath' save_settings(settings) result = runner.invoke(hatch, ['shed', '-p', 'pyname']) assert load_settings()['pypaths'] == {} assert result.exit_code == 0 assert 'Successfully removed Python path named `pyname`.' in result.output
def test_package_not_exist(): with temp_chdir() as d: runner = CliRunner() venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir, evars=ENV_VARS): result = runner.invoke( hatch, ['release', PACKAGE_NAME, '-u', USERNAME, '-t']) assert result.exit_code == 1 assert '`{}` is not an editable package.'.format( PACKAGE_NAME) in result.output
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_config_not_exist(): with temp_chdir() as d: runner = CliRunner() with temp_move_path(SETTINGS_FILE, d): result = runner.invoke(hatch, ['new', 'ok', '--basic', '-ne']) assert result.exit_code == 0 assert ( 'Unable to locate config file; try `hatch config --restore`. ' 'The default project structure will be used.' ) in result.output assert 'Created project `ok`' in result.output
def test_path_full(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['new', 'ok', '--basic']) runner.invoke(hatch, ['new', 'ko', '--basic']) package_dir = os.path.join(d, 'ok') create_test_passing(package_dir) os.chdir(os.path.join(d, 'ko')) result = runner.invoke(hatch, ['test', '-p', os.path.join(d, 'ok')]) assert result.exit_code == 0 assert '1 passed' in result.output
def test_packages(): with temp_chdir() as d: runner = CliRunner() venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir): runner.invoke(hatch, ['install', 'six']) assert 'six' in get_installed_packages() result = runner.invoke(hatch, ['uninstall', '-y', 'six']) assert 'six' not in get_installed_packages() assert result.exit_code == 0
def test_path_full_not_exist(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['egg', 'ok', '--basic']) full_path = os.path.join(d, 'ko') result = runner.invoke(hatch, ['grow', 'fix', '-p', full_path]) init_file = os.path.join(d, 'ok', 'ok', '__init__.py') contents = read_file(init_file) assert result.exit_code == 1 assert contents == "__version__ = '0.0.1'\n" assert 'Directory `{}` does not exist.'.format(full_path) in result.output
def test_init_cwd(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic']) os.chdir(os.path.join(d, 'ok')) result = runner.invoke(hatch, ['grow', 'patch']) init_file = os.path.join(d, 'ok', '__init__.py') contents = read_file(init_file) assert result.exit_code == 0 assert contents == "__version__ = '0.0.2'\n" assert 'Updated {}'.format(init_file) in result.output assert '0.0.1 -> 0.0.2' in result.output
def test_basic(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic', '-ne']) assert os.path.exists(os.path.join(d, 'ok', '__init__.py')) assert os.path.exists(os.path.join(d, 'tests', '__init__.py')) assert os.path.exists(os.path.join(d, 'setup.py')) assert os.path.exists(os.path.join(d, 'MANIFEST.in')) assert os.path.exists(os.path.join(d, 'requirements.txt')) assert os.path.exists(os.path.join(d, '.coveragerc')) assert os.path.exists(os.path.join(d, 'tox.ini')) assert matching_file(r'^LICENSE.*', os.listdir(d)) assert matching_file(r'^README.*', os.listdir(d))
def test_all_packages_none(): with temp_chdir() as d: venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir): runner = CliRunner() result = runner.invoke(hatch, ['update', '-nd', '--all']) if get_python_implementation() in {'PyPy'}: # no cov assert result.exit_code == 0 else: assert result.exit_code == 1 assert 'No packages installed.' in result.output
def test_licenses_multiple(): with temp_chdir() as d: settings = copy_default_settings() settings['licenses'] = ['mit', 'apache2'] create_package(d, 'ok', settings) contents = read_file(os.path.join(d, 'README.rst')) parsed = parse(TEMPLATE, contents) assert parsed['license_info'] == ( 'both\n\n' '- `MIT License <https://choosealicense.com/licenses/mit>`_\n' '- `Apache License, Version 2.0 <https://choosealicense.com/licenses/apache-2.0>`_' '\n\nat your option')
def test_get_installed_packages_no_editable(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic', '-ne']) venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir): install_packages(['six']) install_packages(['-e', '.']) packages = get_installed_packages(editable=False) assert 'six' in packages assert 'ok' not in packages
def test_env_not_exist(): with temp_chdir(): runner = CliRunner() env_name = os.urandom(10).hex() while os.path.exists(os.path.join(VENV_DIR, env_name)): # no cov env_name = os.urandom(10).hex() result = runner.invoke(hatch, ['uninstall', '-y', '-e', env_name, 'six']) assert result.exit_code == 1 assert 'Virtual env named `{}` does not exist.'.format( env_name) in result.output
def test_path_full(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['new', PACKAGE_NAME, '--basic']) runner.invoke(hatch, ['new', 'ko', '--basic']) 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 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_no_config(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic']) init_file = os.path.join(d, 'ok', '__init__.py') with temp_move_path(SETTINGS_FILE, d): result = runner.invoke(hatch, ['grow', 'pre']) contents = read_file(init_file) assert result.exit_code == 0 assert contents == "__version__ = '0.0.1-rc.1'\n" assert 'Updated {}'.format(init_file) in result.output assert '0.0.1 -> 0.0.1-rc.1' in result.output
def test_infra(): with temp_chdir() as d: runner = CliRunner() venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir): install_packages(['setuptools==36.0.1']) initial_version = get_version_as_bytes('setuptools') result = runner.invoke(hatch, ['update', '-nd', '--infra']) final_version = get_version_as_bytes('setuptools') assert result.exit_code == 0 assert initial_version < final_version
def test_path_full(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['new', 'ok', '--basic']) runner.invoke(hatch, ['new', 'ko', '--basic']) package_dir = os.path.join(d, 'ok') os.chdir(os.path.join(d, 'ko')) result = runner.invoke(hatch, ['build', '-p', package_dir]) files = os.listdir(os.path.join(package_dir, 'dist')) assert result.exit_code == 0 assert matching_file(r'.*\.whl$', files) assert len(files) == 2
def test_build_dir_full(): with temp_chdir() as d: runner = CliRunner() runner.invoke(hatch, ['init', 'ok', '--basic', '-ne']) build_dir = os.path.join(d, '_build_dir') result = runner.invoke(hatch, ['build', '-d', build_dir]) files = os.listdir(build_dir) assert result.exit_code == 0 assert matching_file(r'.*\.whl$', files) assert len(files) == 2 assert ('Files found in `{}`:\n\n'.format(build_dir) + format_files(build_dir)) in result.output
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 test_all_packages(): with temp_chdir() as d: venv_dir = os.path.join(d, 'venv') create_venv(venv_dir) with venv(venv_dir): install_packages(['requests==2.17.3']) initial_version = get_version_as_bytes('requests') runner = CliRunner() result = runner.invoke(hatch, ['update', '-nd', '--all']) final_version = get_version_as_bytes('requests') assert result.exit_code == 0 assert initial_version < final_version