Пример #1
0
def test_name():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['name'] = 'Don Quixote'
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'setup.py'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['name'] == 'Don Quixote'
Пример #2
0
def test_package_name():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['readme']['format'] = 'rst'
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'README.rst'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['package_name'] == 'ok'
Пример #3
0
def test_license_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, 'setup.py'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['license'] == 'MIT/Apache-2.0'
Пример #4
0
def test_supported_versions_py3():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['pyversions'] = ['3.5', '3.6', '3.3', '3.4']
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'README.rst'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['supported_versions'] == '3.3+'
Пример #5
0
def test_supported_versions_none():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['pyversions'] = []
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'README.rst'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['supported_versions'] == '2.7/3.5+ and PyPy'
Пример #6
0
def test_package_name():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['vc'] = 'git'
        create_package(d, 'invalid-name', settings)

        contents = read_file(os.path.join(d, '.gitignore'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['package_name_normalized'] == 'invalid_name'
Пример #7
0
def test_name_none():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['name'] = ''
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'setup.py'))
        parsed = parse(TEMPLATE, contents)
        expected_author = get_user() or 'U.N. Owen'

        assert parsed['name'] == expected_author
Пример #8
0
def test_pypy():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['pyversions'] = ['3.6', 'pypy3']
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'setup.py'))
        parsed = parse(TEMPLATE, contents)

        assert parsed[
            'pypy'] == "\n        'Programming Language :: Python :: Implementation :: PyPy',\n"
Пример #9
0
def test_supported_versions_all():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['readme']['format'] = 'md'
        settings['pyversions'] = ['pypy3', 'pypy', '3.4', '3.3', '3.6', '3.5', '2.7']
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'README.md'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['supported_versions'] == '2.7/3.3+ and PyPy'
Пример #10
0
def test_badges_none():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['basic'] = False
        settings['readme']['badges'] = []
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'README.rst'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['badges'] == '\n'
Пример #11
0
def test_licenses_single():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['licenses'] = ['mit']
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'README.rst'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['license_info'] == (
            'the\n`MIT License <https://choosealicense.com/licenses/mit>`_')
Пример #12
0
def test_license_classifiers_single():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['licenses'] = ['mit']
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'setup.py'))
        parsed = parse(TEMPLATE, contents)

        assert parsed[
            'license_classifiers'] == "\n        'License :: OSI Approved :: MIT License',"
Пример #13
0
def test_name():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['licenses'] = ['mpl']
        settings['name'] = 'Red Panda'
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'LICENSE-MPL'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['name'] == 'Red Panda'
Пример #14
0
def test_project_class_add_package():
    with temp_chdir() as d:
        settings = copy_default_settings()
        create_package(d, 'ok', settings)

        project_file = os.path.join(d, 'pyproject.toml')
        project = Project(project_file)
        project.add_package('requests', '>=1.9.0')
        project.add_package('pytest', '>=1.5.0', dev=True)
        assert project.packages == {'requests': '>=1.9.0'}
        assert project.dev_packages == {'pytest': '>=1.5.0'}
Пример #15
0
def test_coverage_package_none():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['basic'] = False
        settings['coverage'] = ''
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'tox.ini'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['coverage_package'] == '\n'
Пример #16
0
def test_pyversions_multiple():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['pyversions'] = ['3.6', '2.7']
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, 'setup.py'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['pyversions'] == (
            "\n        'Programming Language :: Python :: 2.7',"
            "\n        'Programming Language :: Python :: 3.6',")
Пример #17
0
def test_coverage_command():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['basic'] = False
        settings['ci'] = ['travis']
        settings['coverage'] = 'codecov'
        create_package(d, 'ok', settings)

        contents = read_file(os.path.join(d, '.travis.yml'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['coverage_command'] == '\n\nafter_success:\n  - codecov'
Пример #18
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
Пример #19
0
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,'
        )
Пример #20
0
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')
Пример #21
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
Пример #22
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
Пример #23
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
Пример #24
0
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')
Пример #25
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
Пример #26
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
Пример #27
0
def test_cli():
    with temp_chdir() as d:
        settings = copy_default_settings()
        settings['cli'] = True
        create_package(d, 'invalid-name', settings)

        contents = read_file(os.path.join(d, 'setup.py'))
        parsed = parse(TEMPLATE, contents)

        assert parsed['entry_point'] == (
            '\n'
            '    entry_points={\n'
            "        'console_scripts': [\n"
            "            'invalid-name = invalid_name.cli:invalid_name',\n"
            '        ],\n'
            '    },\n')
Пример #28
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
Пример #29
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
Пример #30
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