Пример #1
0
def test_extras():
    with temp_chdir() as d:
        runner = CliRunner()
        test_dir = os.path.join(d, 'a', 'b')
        test_file1 = os.path.join(test_dir, 'file1.txt')
        test_file2 = os.path.join(d, 'x', 'y', 'file2.txt')
        test_glob = '{}{}*'.format(os.path.join(d, 'x'), os.path.sep)
        fake_file = os.path.join(test_dir, 'file.py')
        create_file(test_file1)
        create_file(test_file2)

        with temp_move_path(SETTINGS_FILE, d):
            new_settings = copy_default_settings()
            new_settings['extras'] = [
                test_dir, test_file1, test_glob, fake_file
            ]
            save_settings(new_settings)

            runner.invoke(hatch, ['egg', 'ok', '--basic'])
            d = os.path.join(d, 'ok')

        assert os.path.exists(os.path.join(d, 'b', 'file1.txt'))
        assert os.path.exists(os.path.join(d, 'file1.txt'))
        assert os.path.exists(os.path.join(d, 'y', 'file2.txt'))
        assert not os.path.exists(os.path.join(d, 'file2.txt'))
        assert not os.path.exists(os.path.join(d, 'file.py'))
Пример #2
0
def test_interactive_mode():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            result = runner.invoke(
                hatch, ['init', '-i', '--basic', '-ne'],
                input=
                'ok\n0.1.0\nTest Description\nPicard\[email protected]\nmpl\n'
            )

        assert result.exit_code == 0
        assert os.path.exists(os.path.join(d, 'ok', '__init__.py'))
        assert "__version__ = '0.1.0'\n" == read_file(
            os.path.join(d, 'ok', '__init__.py'))
        assert os.path.exists(os.path.join(d, 'LICENSE-MPL'))
        assert os.path.exists(os.path.join(d, 'pyproject.toml'))
        pyproject = toml.load('pyproject.toml')
        metadata = pyproject['metadata']
        assert metadata['name'] == 'ok'
        assert metadata['version'] == '0.1.0'
        assert metadata['description'] == 'Test Description'
        assert metadata['author'] == 'Picard'
        assert metadata['author_email'] == '*****@*****.**'
        assert metadata['license'] == 'MPL-2.0'
        assert metadata['url'] == 'https://github.com/_/ok'
Пример #3
0
def test_pyname_and_env():
    with temp_chdir() as d:
        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()

        venv_dir = os.path.join(VENV_DIR, env_name)

        try:
            runner.invoke(hatch, ['env', env_name])
            assert os.path.exists(venv_dir)

            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', '-e', env_name])
                assert load_settings()['pypaths'] == {}
                assert not os.path.exists(venv_dir)
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
        assert 'Successfully removed Python path named `pyname`.' in result.output
        assert 'Successfully removed virtual env named `{}`.'.format(
            env_name) in result.output
Пример #4
0
def test_pyname_config_not_exist():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            result = runner.invoke(hatch, ['shed', '-p', 'python'])

        assert result.exit_code == 1
        assert 'Unable to locate config file. Try `hatch config --restore`.' in result.output
Пример #5
0
def test_python_no_config():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['init', 'ok', '--basic'])

        with temp_move_path(SETTINGS_FILE, d):
            result = runner.invoke(hatch, ['build', '-py', 'python'])

        assert result.exit_code == 1
        assert 'Unable to locate config file. Try `hatch config --restore`.' in result.output
Пример #6
0
def test_update_config_not_exist():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            result = runner.invoke(hatch, ['config', '-u'])

            assert result.exit_code == 0
            assert 'Settings were successfully restored.' in result.output
            assert load_settings() == copy_default_settings()
Пример #7
0
def test_pyname_key_not_exist():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            restore_settings()
            result = runner.invoke(hatch, ['init', 'ok', '-py', 'pyname'])

        assert result.exit_code == 1
        assert 'Unable to find a Python path named `pyname`.' in result.output
Пример #8
0
def test_pyname_not_exist():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            restore_settings()
            result = runner.invoke(hatch, ['shed', '-p', 'pyname'])

        assert result.exit_code == 0
        assert 'Python path named `pyname` already does not exist.' in result.output
Пример #9
0
def test_config_not_exist():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            result = runner.invoke(hatch, ['init', '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
Пример #10
0
def test_list_success_no_pypaths():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            restore_settings()
            result = runner.invoke(hatch, ['pypath', '-l'])

        assert result.exit_code == 0
        assert ('There are no saved Python paths. Add '
                'one via `hatch pypath NAME PATH`.') in result.output
Пример #11
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
Пример #12
0
def test_temp_move_path():
    with temp_chdir() as d1:
        path = os.path.join(d1, 'test')
        create_file(path)
        assert os.path.exists(path)

        with temp_chdir() as d2:
            with temp_move_path(path, d2) as dst:
                assert not os.path.exists(path)
                assert dst == os.path.join(d2, 'test')

        assert os.path.exists(path)
Пример #13
0
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
Пример #14
0
def test_python_invalid():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['init', 'ok', '--basic'])

        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
Пример #15
0
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
Пример #16
0
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
Пример #17
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
Пример #18
0
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
Пример #19
0
def test_python():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['init', 'ok', '--basic'])

        with temp_move_path(SETTINGS_FILE, d):
            settings = copy_default_settings()
            settings['pypaths']['python'] = sys.executable
            save_settings(settings)
            result = runner.invoke(hatch, ['build', '-py', 'python', '-pp', 'Delphi'])
            files = os.listdir(os.path.join(d, 'dist'))

        assert result.exit_code == 0
        assert matching_file(r'.*\.whl$', files)
        assert len(files) == 2
Пример #20
0
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
Пример #21
0
def test_success_missing_key():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            settings = copy_default_settings()
            settings.pop('pypaths')
            save_settings(settings)
            result = runner.invoke(hatch, ['pypath', 'name', 'path'])
            settings = load_settings()

            assert settings['pypaths']['name'] == 'path'
            assert list(settings.keys())[-1] != 'pypaths'

        assert result.exit_code == 0
        assert 'Settings were successfully updated to include `pypaths` entry.' in result.output
        assert 'Successfully saved Python `name` located at `path`.' in result.output
Пример #22
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
Пример #23
0
def test_build_option():
    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):
            settings = copy_default_settings()
            settings['semver']['build'] = 'rc'
            save_settings(settings)
            result = runner.invoke(hatch, ['grow', 'build', '--build', 'nightly'])
            contents = read_file(init_file)

        assert result.exit_code == 0
        assert contents == "__version__ = '0.0.1+nightly.1'\n"
        assert 'Updated {}'.format(init_file) in result.output
        assert '0.0.1 -> 0.0.1+nightly.1' in result.output
Пример #24
0
def test_update():
    with temp_chdir() as d:
        runner = CliRunner()

        with temp_move_path(SETTINGS_FILE, d):
            new_settings = copy_default_settings()
            new_settings.pop('email')
            new_settings['new setting'] = ''
            save_settings(new_settings)
            assert load_settings() == new_settings

            result = runner.invoke(hatch, ['config', '-u'])
            updated_settings = load_settings()

            assert result.exit_code == 0
            assert 'Settings were successfully updated.' in result.output
            assert 'email' in updated_settings
            assert 'new setting' in updated_settings
Пример #25
0
def test_repository_local():
    with temp_chdir() as d:
        runner = CliRunner()
        runner.invoke(hatch, ['new', PACKAGE_NAME, '--basic', '-ne'])
        runner.invoke(hatch, ['build', '-p', PACKAGE_NAME])
        package_dir = os.path.join(d, PACKAGE_NAME)

        venv_dir = os.path.join(d, 'venv')
        create_venv(venv_dir)

        # Make sure there's no configuration
        with temp_move_path(os.path.expanduser("~/.pypirc"), d):
            with venv(venv_dir, evars=ENV_VARS):
                install_packages(['-e', package_dir])
                # Will error, since there's no configuration parameter for
                # this URL
                result = runner.invoke(hatch, ['release', '-l', '-u', USERNAME, '-r', TEST_REPOSITORY])

        assert result.exit_code == 1
Пример #26
0
def test_pyname():
    with temp_chdir() as d:
        runner = CliRunner()

        env_name = get_new_venv_name()
        venv_dir = os.path.join(VENV_DIR, env_name)

        try:
            with temp_move_path(SETTINGS_FILE, d):
                settings = copy_default_settings()
                settings['pypaths']['python'] = sys.executable
                save_settings(settings)
                result = runner.invoke(hatch,
                                       ['env', env_name, '-py', 'python'])
                assert os.path.exists(venv_dir)
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
        assert 'Successfully saved virtual env `{}` to `{}`.'.format(
            env_name, venv_dir) in result.output
Пример #27
0
def test_pyname():
    with temp_chdir() as d:
        runner = CliRunner()

        env_name = get_new_venv_name()
        venv_dir = os.path.join(VENV_DIR, env_name)

        try:
            with temp_move_path(SETTINGS_FILE, d):
                settings = copy_default_settings()
                settings['pypaths']['python'] = sys.executable
                save_settings(settings)
                result = runner.invoke(hatch, ['init', 'ok', '-py', 'python'])
                venv_dir = os.path.join(d, 'venv')
                global_version = get_python_version()
                wait_until(is_venv, venv_dir)
                with venv(venv_dir):
                    assert get_python_version() == global_version
        finally:
            remove_path(venv_dir)

        assert result.exit_code == 0
Пример #28
0
def xonsh_shell(env_name, nest, shell_path):
    with TemporaryDirectory() as d:
        with temp_move_path(os.path.expanduser('~/.xonshrc'), d) as path:
            new_config = ''
            if path:
                with open(path, 'r') as f:
                    new_config += f.read()

            hatch_level = int(os.environ.get('_HATCH_LEVEL_', 1))

            if nest and hatch_level > 1:
                new_config += (
                    '\n$PROMPT_FIELDS["env_name"] = "{hatch_level} ({env_name})"\n'
                    ''.format(hatch_level=hatch_level, env_name=env_name))
            else:
                new_config += (
                    '\n$PROMPT_FIELDS["env_name"] = "({env_name})"\n'
                    ''.format(env_name=env_name))

            new_config_path = os.path.join(d, 'new.xonshrc')
            with open(new_config_path, 'w') as f:
                f.write(new_config)
            yield [shell_path or 'xonsh', '--rc', new_config_path]
Пример #29
0
def test_temp_move_path_not_exist():
    with temp_chdir() as d:
        with temp_move_path(os.path.join(d, 'test'), d):
            pass