예제 #1
0
def test_check_lockfile_vcs_branch(
    capsys, tmp_path, shared_datadir, source_pipfile_dirname
):  # type: (Any, Path, Path, str) -> None
    """
    When Pipfile specifies a VCS dependency with a `ref` that is a mutable reference
    (e.g. - a branch, not a tag or a commit hash), `setup.py` gets updated with the
    resolved `sha` of that branch from Pipfile.lock.

    This causes `check` to fail b/c setup.py doesn't match Pipfile.

    The `--lockfile` flag allows checking against `Pipefile.lock` instead, which
    fixes this check.
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "Pipfile.lock", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)
    # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py")
    with cwd(tmp_path):
        # Check will fail b/c `master` branch resolves to commit sha in setup.py
        with pytest.raises(SystemExit) as e:
            cmd(argv=["", "check"])
        assert e.value.code == 1

        # `check --lockfile` will pass because Pipfile.lock also has the resolved sha
        cmd(argv=["", "check", "--lockfile"])
예제 #2
0
def test_sync_no_setup_call(
    tmp_path, shared_datadir, source_pipfile_dirname
):  # type: (Path, Path, str) -> None
    """
    when setup call is not found, return code should be one
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "Pipfile.lock", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)
    with cwd(tmp_path):
        with pytest.raises(SystemExit) as e:
            cmd(argv=["", "sync"])
        assert e.value.code == 1
예제 #3
0
def test_check_file_many_conflicts(
    capsys, tmp_path, shared_datadir, source_pipfile_dirname
):  # type: (Any, Path, Path, str) -> None
    """
    many conflicts, return code should be one
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "Pipfile.lock", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)

    with cwd(tmp_path):
        with pytest.raises(SystemExit) as e:
            cmd(argv=["", "check"])
        assert e.value.code == 1
예제 #4
0
def test_check_file_install_requires_missing(
    capsys, tmp_path, shared_datadir, source_pipfile_dirname
):  # type: (Any, Path, Path, str) -> None
    """
    when Pipfile.lock is missing, return code should be one
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "Pipfile.lock", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)
    # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py")
    with cwd(tmp_path):
        with pytest.raises(SystemExit) as e:
            cmd(argv=["", "check"])
        assert e.value.code == 1
예제 #5
0
def test_sync_lock_file_package_broken(
        tmp_path, shared_datadir,
        source_pipfile_dirname):  # type: (Path, Path, str) -> None
    """
    when Pipfile.lock is missing, return code should be one
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)

    with cwd(tmp_path):
        with pytest.raises(SystemExit) as e:
            cmd(argv=["", "sync"])
        assert e.value.code == 1
예제 #6
0
def test_sync_lock_file_missing_messages(
    capfd, tmp_path, shared_datadir, source_pipfile_dirname
):  # type: (Any, Path, Path, str) -> None
    """
    when pipfile is missing, there should be error msgs
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    copy_file(pipfile_dir / "Pipfile", tmp_path)
    # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py")
    with cwd(tmp_path):
        with pytest.raises(SystemExit):
            cmd(argv=["", "sync"])
    captured = capfd.readouterr()
    assert msg_formatter.no_sync_performed() in captured.err
    assert msg_formatter.missing_file(Path("Pipfile.lock")) in captured.err
예제 #7
0
def test_check_file_missing_exit_code(
    capfd, tmp_path, shared_datadir, source_pipfile_dirname, missing_filenames
):  # type: (Any, Path, Path, str, List[str]) -> None
    """
    when Pipfile.lock is missing, return code should be one
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ["Pipfile", "Pipfile.lock", "setup.py"]:
        file = pipfile_dir / filename
        if filename not in missing_filenames:
            copy_file(file, tmp_path)
    # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py")
    with cwd(tmp_path):
        with pytest.raises(SystemExit) as e:
            cmd(argv=["", "check"])
        assert e.value.code == 1
예제 #8
0
def test_check_file_strict(
    capsys, tmp_path, shared_datadir, source_pipfile_dirname
):  # type: (Any, Path, Path, str) -> None
    """
    when --strict flag is passed. compatible but not identical versioning should fail
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "Pipfile.lock", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)
    with cwd(tmp_path):
        with pytest.raises(SystemExit) as e:
            cmd(argv=["", "check", "--strict"])
        assert e.value.code == 1

        cmd(argv=["", "check"])
        captured = capsys.readouterr()
        assert msg_formatter.checked_no_problem() in captured.out
예제 #9
0
def test_check_file_ignore_local(
    capsys, tmp_path, shared_datadir, source_pipfile_dirname
):  # type: (Any, Path, Path, str) -> None
    """
    when Pipfile.lock is missing, return code should be one
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "Pipfile.lock", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)
    # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py")
    with cwd(tmp_path):
        with pytest.raises(SystemExit) as e:
            cmd(argv=["", "check"])
        assert e.value.code == 1

        cmd(argv=["", "check", "--ignore-local"])
        captured = capsys.readouterr()
        assert msg_formatter.checked_no_problem() in captured.out