Esempio n. 1
0
def test_update(
    capsys, tmp_path, shared_datadir, source_pipfile_dirname, update_count
):  # type: (Any, Path, Path, str, int) -> None
    """
    test updating setup.py (when it already exists)
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "Pipfile.lock", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)
    with data(source_pipfile_dirname, tmp_path):
        cmd(argv=["", "sync"])
        generated_setup = Path("setup.py")
        assert generated_setup.exists()
        generated_setup_text = generated_setup.read_text()
        expected_setup_text = Path("setup.py").read_text()
    for kw_arg_names in ("install_requires", "dependency_links"):

        assert compare_list_of_string_kw_arg(
            generated_setup_text,
            expected_setup_text,
            kw_arg_names,
            ordering_matters=False,
        )
    captured = capsys.readouterr()
    assert msg_formatter.update_success(update_count) in captured.out
Esempio n. 2
0
def test_only_setup_missing(
    capsys, tmp_path, shared_datadir, source_pipfile_dirname, update_count
):  # type: (Any, Path, Path, str, int) -> None
    """
    test generate setup.py (when it is missing)
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    with data(source_pipfile_dirname, tmp_path):
        # delete the setup.py file that was copied to the tmp_path
        (tmp_path / "setup.py").unlink()
        cmd(argv=["", "sync"])
        generated_setup = Path("setup.py")
        assert generated_setup.exists()
        generated_setup_text = generated_setup.read_text()
        expected_setup_text = Path("setup.py").read_text()
    for kw_arg_names in ("install_requires", "dependency_links"):

        assert compare_list_of_string_kw_arg(
            generated_setup_text,
            expected_setup_text,
            kw_arg_names,
            ordering_matters=False,
        )
    captured = capsys.readouterr()
    assert msg_formatter.generate_success(update_count) in captured.out, captured.out
Esempio n. 3
0
def test_sync_pipfile_no_original(capsys, tmp_path, shared_datadir,
                                  source_pipfile_dirname, update_count):
    """
    sync --pipfile should reference Pipfile (not Pipfile.lock) when printing results
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    for filename in ("Pipfile", "Pipfile.lock", "setup.py"):
        copy_file(pipfile_dir / filename, tmp_path)

    with data(str(pipfile_dir), tmp_path) as path:
        setup_file = path / "setup.py"  # type: Path
        cmd(["", "sync", "--pipfile"])
        text = setup_file.read_text()
        generated_setup = Path("setup.py")
        assert generated_setup.exists()
        generated_setup_text = generated_setup.read_text()
        expected_setup_text = Path("setup.py").read_text()

    for kw_arg_names in ("install_requires", "dependency_links"):
        assert compare_list_of_string_kw_arg(
            generated_setup_text,
            expected_setup_text,
            kw_arg_names,
            ordering_matters=False,
        )

    captured = capsys.readouterr()
    assert "Pipfile.lock" not in captured.out, captured.out
    assert "Pipfile" in captured.out, captured.out
Esempio n. 4
0
def is_installable_dir(path):
    # type: (STRING_TYPE) -> bool
    if pip_shims.shims.is_installable_dir(path):
        return True
    pyproject_path = os.path.join(path, "pyproject.toml")
    if os.path.exists(pyproject_path):
        pyproject = Path(pyproject_path)
        pyproject_toml = tomlkit.loads(pyproject.read_text())
        build_system = pyproject_toml.get("build-system",
                                          {}).get("build-backend", "")
        if build_system:
            return True
    return False
Esempio n. 5
0
def test_keep_outdated_keeps_markers_not_removed(PipenvInstance):
    with PipenvInstance(chdir=True) as p:
        c = p.pipenv("install six click")
        assert c.ok
        lockfile = Path(p.lockfile_path)
        lockfile_content = lockfile.read_text()
        lockfile_json = json.loads(lockfile_content)
        assert "six" in lockfile_json["default"]
        lockfile_json["default"]["six"]["markers"] = "python_version >= '2.7'"
        lockfile.write_text(to_text(json.dumps(lockfile_json)))
        c = p.pipenv("lock --keep-outdated")
        assert c.ok
        assert p.lockfile["default"]["six"].get("markers", "") == "python_version >= '2.7'"
Esempio n. 6
0
def test_generation(tmp_path, shared_datadir,
                    source_pipfile_dirname):  # type: (Path, Path, str) -> None
    """
    test boilerplate
    """
    pipfile_dir = shared_datadir / source_pipfile_dirname
    copy_pipfiles(pipfile_dir, tmp_path)
    with data(source_pipfile_dirname, tmp_path):

        cmd(argv=["", "sync"])
        generated_setup = Path("setup.py")
        assert generated_setup.exists()
        generated_setup_text = generated_setup.read_text()
        expected_setup_text = Path("setup.py").read_text()
        for kw_arg_names in ("install_requires", "dependency_links"):

            assert compare_list_of_string_kw_arg(
                generated_setup_text,
                expected_setup_text,
                kw_arg_names,
                ordering_matters=False,
            )