Beispiel #1
0
def test_guess_python_requires_from_classifiers(tmpdir):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 2\n'
        '    Programming Language :: Python :: 2.7\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3.6\n', )

    main((str(setup_cfg), '--min-py3-version=3.4', '--max-py-version=3.7'))

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 2\n'
        '    Programming Language :: Python :: 2.7\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3.4\n'
        '    Programming Language :: Python :: 3.5\n'
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '\n'
        '[options]\n'
        'python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*\n')
Beispiel #2
0
def test_rewrite_requires(which, input_tpl, expected_tpl, tmpdir):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(input_tpl.format(which))

    main((str(setup_cfg), ))

    assert setup_cfg.read() == expected_tpl.format(which)
Beispiel #3
0
def test_rewrite(input_s, expected, tmpdir):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(input_s)

    main((str(setup_cfg), ))

    assert setup_cfg.read() == expected
def test_rewrite_extras(tmpdir):
    setup_cfg_content = (
        '[metadata]\n'
        'name = test\n'
        '[options.extras_require]\n'
        'dev =\n'
        '    pytest\n'
        '    hypothesis\n'
        'ci =\n'
        '    hypothesis\n'
        '    pytest\n'
        'arg =\n'
    )
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(setup_cfg_content)

    main((str(setup_cfg),))

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = test\n'
        '\n'
        '[options.extras_require]\n'
        'ci =\n'
        '    hypothesis\n'
        '    pytest\n'
        'dev =\n'
        '    hypothesis\n'
        '    pytest\n'
    )
Beispiel #5
0
def test_min_version_removes_classifiers(tmpdir):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.2\n'
        '    Programming Language :: Python :: 3.3\n'
        '    Programming Language :: Python :: 3.4\n'
        '    Programming Language :: Python :: 3.5\n'
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.2, !=3.6.*\n', )

    main((str(setup_cfg), '--min-py3-version=3.4', '--max-py-version=3.7'))

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.4\n'
        '    Programming Language :: Python :: 3.5\n'
        '    Programming Language :: Python :: 3.7\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.4, !=3.6.*\n')
Beispiel #6
0
def test_sets_license_file_if_license_exists(filename, tmpdir):
    tmpdir.join(filename).write('COPYRIGHT (C) 2019 ME')
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write('[metadata]\n' 'name = pkg\n' 'version = 1.0\n', )

    main((str(setup_cfg), ))

    assert setup_cfg.read() == (f'[metadata]\n'
                                f'name = pkg\n'
                                f'version = 1.0\n'
                                f'license_file = {filename}\n')
Beispiel #7
0
def test_strips_empty_options_and_sections(tmpdir, section, expected):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        f'{section}', )

    main((str(setup_cfg), ))
    assert setup_cfg.read() == ('[metadata]\n'
                                'name = pkg\n'
                                'version = 1.0\n'
                                f'{expected}')
Beispiel #8
0
def test_adds_long_description_with_readme(filename, content_type, tmpdir):
    tmpdir.join(filename).write('my project!')
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write('[metadata]\n' 'name = pkg\n' 'version = 1.0\n', )

    main((str(setup_cfg), ))

    assert setup_cfg.read() == (
        f'[metadata]\n'
        f'name = pkg\n'
        f'version = 1.0\n'
        f'long_description = file: {filename}\n'
        f'long_description_content_type = {content_type}\n')
Beispiel #9
0
def test_rewrite_sets_license_type_and_classifier(tmpdir):
    with open('LICENSE') as f:
        tmpdir.join('LICENSE').write(f.read())
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write('[metadata]\n' 'name = pkg\n' 'version = 1.0\n', )

    main((str(setup_cfg), ))

    assert setup_cfg.read() == ('[metadata]\n'
                                'name = pkg\n'
                                'version = 1.0\n'
                                'license = MIT\n'
                                'license_file = LICENSE\n'
                                'classifiers =\n'
                                '    License :: OSI Approved :: MIT License\n')
def test_imp_classifiers_pypy_only(tmpdir):
    tmpdir.join('tox.ini').write('[tox]\nenvlist = pypy3\n')
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = test\n'
        'classifiers =\n'
        '    License :: OSI Approved :: MIT License\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.9\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.9\n',
    )

    args = (str(setup_cfg), '--min-py3-version=3.9', '--max-py-version=3.9')
    assert main(args)

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = test\n'
        'classifiers =\n'
        '    License :: OSI Approved :: MIT License\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.9\n'
        '    Programming Language :: Python :: Implementation :: PyPy\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.9\n'
    )
def test_min_py3_version_greater_than_minimum(tmpdir):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.2\n',
    )

    args = (str(setup_cfg), '--min-py3-version=3.4', '--max-py-version=3.7')
    assert main(args)

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.4\n'
        '    Programming Language :: Python :: 3.5\n'
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.4\n'
    )
def test_min_py3_version_less_than_minimum(tmpdir):
    tmpdir.join('tox.ini').write('[tox]\nenvlist=py36\n')
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n',
    )

    args = (str(setup_cfg), '--min-py3-version=3.4', '--max-py-version=3.7')
    assert main(args)

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '    Programming Language :: Python :: Implementation :: CPython\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.6\n'
    )
def test_python_requires_left_alone(tmpdir, s):
    tmpdir.join('tox.ini').ensure()  # present, but not useful
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        f'[metadata]\n'
        f'name = pkg\n'
        f'version = 1.0\n'
        f'\n'
        f'[options]\n'
        f'python_requires = {s}\n',
    )

    assert not main((
        str(setup_cfg), '--min-py3-version=3.2',
        '--max-py-version=0.0',  # disable classifier generation
    ))

    assert setup_cfg.read() == (
        f'[metadata]\n'
        f'name = pkg\n'
        f'version = 1.0\n'
        f'\n'
        f'[options]\n'
        f'python_requires = {s}\n'
    )
def test_guess_python_requires_python2_tox_ini(tmpdir):
    tmpdir.join('tox.ini').write('[tox]\nenvlist=py36,py27,py37,pypy\n')
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n',
    )

    args = (str(setup_cfg), '--min-py3-version=3.4', '--max-py-version=3.7')
    assert main(args)

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 2\n'
        '    Programming Language :: Python :: 2.7\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3.4\n'
        '    Programming Language :: Python :: 3.5\n'
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '    Programming Language :: Python :: Implementation :: CPython\n'
        '    Programming Language :: Python :: Implementation :: PyPy\n'
        '\n'
        '[options]\n'
        'python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*\n'
    )
Beispiel #15
0
def test_noop(tmpdir):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        '\n'
        '[bdist_wheel]\n'
        'universal = true\n', )

    main((str(setup_cfg), ))

    assert setup_cfg.read() == ('[metadata]\n'
                                'name = pkg\n'
                                'version = 1.0\n'
                                '\n'
                                '[bdist_wheel]\n'
                                'universal = true\n')
Beispiel #16
0
def test_guess_python_requires_tox_ini_dashed_name(tmpdir):
    tmpdir.join('tox.ini').write('[tox]\nenvlist = py37-flake8\n')
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write('[metadata]\n' 'name = pkg\n' 'version = 1.0\n', )

    main((str(setup_cfg), '--min-py3-version=3.4', '--max-py-version=3.7'))

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.7\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.7\n')
def test_readme_discover_prefers_file_over_directory(tmpdir):
    tmpdir.join('README').mkdir()
    tmpdir.join('README.md').write('my project!')
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write('[metadata]\n' 'name = pkg\n', )
    assert main((str(setup_cfg), ))

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'long_description = file: README.md\n'
        'long_description_content_type = text/markdown\n')
Beispiel #18
0
def test_guess_python_requires_ignores_insufficient_version_envs(tmpdir):
    tmpdir.join('tox.ini').write('[tox]\nenvlist = py,py2,py3\n')
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write('[metadata]\n' 'name = pkg\n' 'version = 1.0\n', )

    assert not main((
        str(setup_cfg),
        '--min-py3-version=3.4',
        '--max-py-version=3.7',
    ))

    assert setup_cfg.read() == ('[metadata]\n'
                                'name = pkg\n'
                                'version = 1.0\n')
Beispiel #19
0
def test_rewrite_identifies_license(tmpdir):
    zlib_license = '''\
zlib License

(C) 2019 Anthony Sottile

This software is provided 'as-is', without any express or implied
warranty.  In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
   claim that you wrote the original software. If you use this software
   in a product, an acknowledgment in the product documentation would be
   appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
'''
    tmpdir.join('LICENSE').write(zlib_license)
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write('[metadata]\n' 'name = pkg\n' 'version = 1.0\n', )

    main((str(setup_cfg), ))

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'license = Zlib\n'
        'license_file = LICENSE\n'
        'classifiers =\n'
        '    License :: OSI Approved :: zlib/libpng License\n')
def test_classifiers_left_alone_for_odd_python_requires(tmpdir):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.2\n'
        '    Programming Language :: Python :: 3.3\n'
        '    Programming Language :: Python :: 3.4\n'
        '    Programming Language :: Python :: 3.5\n'
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '\n'
        '[options]\n'
        'python_requires = ~=3.2\n',
    )

    args = (str(setup_cfg), '--min-py3-version=3.4', '--max-py-version=3.7')
    assert not main(args)

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.2\n'
        '    Programming Language :: Python :: 3.3\n'
        '    Programming Language :: Python :: 3.4\n'
        '    Programming Language :: Python :: 3.5\n'
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '\n'
        '[options]\n'
        'python_requires = ~=3.2\n'
    )
def test_python_requires_with_patch_version(tmpdir):
    setup_cfg = tmpdir.join('setup.cfg')
    setup_cfg.write(
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        # added this to make sure that it doesn't revert to 3.6
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.6.1\n',
    )

    # added this to make sure it doesn't revert to 3.6
    tmpdir.join('tox.ini').write('[tox]\nenvlist=py36\n')

    args = (str(setup_cfg), '--min-py3-version=3.4', '--max-py-version=3.8')
    assert main(args)

    assert setup_cfg.read() == (
        '[metadata]\n'
        'name = pkg\n'
        'version = 1.0\n'
        'classifiers =\n'
        '    Programming Language :: Python :: 3\n'
        '    Programming Language :: Python :: 3 :: Only\n'
        '    Programming Language :: Python :: 3.6\n'
        '    Programming Language :: Python :: 3.7\n'
        '    Programming Language :: Python :: 3.8\n'
        '    Programming Language :: Python :: Implementation :: CPython\n'
        '\n'
        '[options]\n'
        'python_requires = >=3.6.1\n'
    )