def test_test_top_level_dependencies_no_requirements_dev_minimal(
    in_tmpdir,
    capsys,
):
    """If there's no requirements-dev-minimal.txt, we should suggest you create
    a requirements-dev-minimal.txt but not fail.
    """
    in_tmpdir.join('requirements-minimal.txt').ensure()
    in_tmpdir.join('requirements.txt').ensure()
    in_tmpdir.join('requirements-dev.txt').write('pkg-dep-1\n'
                                                 'pkg-dep-2==2.0.0\n')
    main.test_top_level_dependencies()  # should not raise
    assert (
        'Warning: check-requirements is *not* checking your dev dependencies.'
        in capsys.readouterr()[0])
def test_test_top_level_dependencies_too_muchh_pinned(in_tmpdir):
    # So we don't skip
    in_tmpdir.join('requirements-minimal.txt').write('pkg-dep-1')
    in_tmpdir.join('requirements.txt').write(
        'pkg-dep-1==1.0.0\n'
        'other-dep-1==1.0.0\n', )
    with pytest.raises(AssertionError) as excinfo:
        main.test_top_level_dependencies()
    assert excinfo.value.args[0] == (
        'Requirements are pinned in requirements.txt but are not depended on in requirements-minimal.txt!\n'  # noqa
        '\n'
        'Usually this happens because you upgraded some other dependency, and now no longer require these.\n'  # noqa
        "If that's the case, you should remove these from requirements.txt.\n"  # noqa
        'Otherwise, if you *do* need these packages, then add them to requirements-minimal.txt.\n'  # noqa
        '\t- other-dep-1==1.0.0')
def test_test_top_level_dependencies_prod_dep_is_only_in_dev_deps(in_tmpdir):
    """If we've defined a prod dependency only in requirements-dev.txt, we
    should tell the user to put it in requirements.txt instead.
    """
    in_tmpdir.join('requirements-minimal.txt').write('pkg-with-deps')
    in_tmpdir.join('requirements.txt').write('pkg-with-deps==0.1.0\n'
                                             'pkg-dep-1==1.0.0\n')
    in_tmpdir.join('requirements-dev-minimal.txt').write('pkg-dep-2')
    in_tmpdir.join('requirements-dev.txt').write('pkg-dep-2==2.0.0')
    with pytest.raises(AssertionError) as excinfo:
        main.test_top_level_dependencies()
    assert excinfo.value.args == (
        'Dependencies derived from requirements-minimal.txt are not '
        'pinned in requirements.txt\n'
        '(Probably need to add something to requirements.txt):\n'
        '\t- pkg-dep-2==2.0.0', )
def test_test_top_level_dependencies_overlapping_prod_dev_deps(in_tmpdir):
    """If we have a dep which is both a prod and dev dep, we should complain if
    it appears in requirements-dev.txt.
    """
    in_tmpdir.join('requirements-minimal.txt').write('pkg-dep-1')
    in_tmpdir.join('requirements.txt').write('pkg-dep-1==1.0.0')
    in_tmpdir.join('requirements-dev-minimal.txt').write('pkg-dep-1')
    in_tmpdir.join('requirements-dev.txt').write('pkg-dep-1==1.0.0')
    with pytest.raises(AssertionError) as excinfo:
        main.test_top_level_dependencies()
    # TODO: this exception is misleading, ideally it should tell you that
    # you don't need to pin it in reqs-dev.txt if it's also a prod dep
    assert excinfo.value.args == (
        'Requirements are pinned in requirements-dev.txt but are not depended on in requirements-dev-minimal.txt!\n'  # noqa
        '\n'
        'Usually this happens because you upgraded some other dependency, and now no longer require these.\n'  # noqa
        "If that's the case, you should remove these from requirements-dev.txt.\n"  # noqa
        'Otherwise, if you *do* need these packages, then add them to requirements-dev-minimal.txt.\n'  # noqa
        '\t- pkg-dep-1==1.0.0', )
def test_test_top_level_dependencies_no_dev_deps_pinned(in_tmpdir):
    """If there's a requirements-dev-minimal.txt but no requirements-dev.txt,
    we should tell you to pin everything there.
    """
    in_tmpdir.join('requirements-minimal.txt').ensure()
    in_tmpdir.join('requirements.txt').ensure()
    in_tmpdir.join('requirements-dev-minimal.txt').write('pkg-dep-1\n'
                                                         'pkg-dep-2\n')
    with pytest.raises(AssertionError) as excinfo:
        main.test_top_level_dependencies()
    assert excinfo.value.args == (
        'Dependencies derived from requirements-dev-minimal.txt are '
        'not pinned in requirements-dev.txt\n'
        '(Probably need to add something to requirements-dev.txt):\n'
        '\t- pkg-dep-1==1.0.0\n'
        '\t- pkg-dep-2==2.0.0', )

    # and when you do pin it, now the tests pass! :D
    in_tmpdir.join('requirements-dev.txt').write(
        'pkg-dep-1==1.0.0\npkg-dep-2==2.0.0\n', )
    main.test_top_level_dependencies()
def test_prerelease_name_normalization(in_tmpdir, version):
    in_tmpdir.join('requirements-minimal.txt').write('prerelease-pkg')
    in_tmpdir.join('requirements.txt').write(
        'prerelease-pkg=={}'.format(version), )
    main.test_top_level_dependencies()
def test_test_top_level_dependencies_with_extras(in_tmpdir):
    in_tmpdir.join('requirements-minimal.txt').write('pkg-with-extras[extra1]')
    in_tmpdir.join('requirements.txt').write('pkg-with-extras==0.1.0\n'
                                             'pkg-dep-1==1.0.0\n')
    # Should pass
    main.test_top_level_dependencies()