def test_failure(pipfile_dir):
    pipfile_location = pipfile_dir / "Pipfile.both-sections"
    with pytest.raises(PipfileNotFound):
        Lockfile.lockfile_from_pipfile("some_fake_pipfile_path")
    with pytest.raises(MissingParameter):
        Lockfile.from_data(None, None)
    with pytest.raises(MissingParameter):
        Lockfile.from_data(pipfile_location.as_posix(), None)
    with pytest.raises(MissingParameter):
        Lockfile.from_data(None, {})
    with pytest.raises(TypeError):
        Lockfile.from_data(pipfile_location.as_posix(), True)
def test_pipfile_loader(
    pathlib_tmpdir, pipfile_dir, extension, default_len, dev_len, requires_python
):
    pipfile_location = pipfile_dir / "Pipfile.{0}".format(extension)
    pyproject_location = pipfile_dir / "pyproject.toml"
    pipfile_path = pathlib_tmpdir.joinpath(pipfile_location.stem)
    pyproject_path = pathlib_tmpdir.joinpath(pyproject_location.name)
    pipfile_path.write_text(pipfile_location.read_text())
    pyproject_path.write_text(pyproject_location.read_text())
    pipfile = Pipfile.load(pipfile_path.absolute().as_posix())
    assert len(pipfile.requirements) == len(pipfile.packages) == default_len
    assert len(pipfile.dev_requirements) == len(pipfile.dev_packages) == dev_len
    assert len(pipfile.sources) != 0
    for dev, only in itertools.product((True, False), (True, False)):
        expected_len = dev_len if dev else default_len
        if dev and not only:
            expected_len += default_len
        assert len(pipfile.get_deps(dev=dev, only=only)) == expected_len
    if default_len > 0:
        assert pipfile["packages"] is not None
    if dev_len > 0:
        assert pipfile["dev-packages"] is not None
    if (default_len + dev_len) > 0:
        assert "requests" in pipfile
    assert pipfile.path.as_posix() == pipfile_path.absolute().as_posix()
    assert pipfile.requires_python == requires_python
    assert pipfile.allow_prereleases is True
    assert isinstance(pipfile.build_requires, list)
    assert pipfile.build_backend is not None
    lockfile_from_pipfile = Lockfile.lockfile_from_pipfile(pipfile.path.as_posix())
    assert lockfile_from_pipfile is not None
    pipfile["dev-packages"]["six"] = "*"
    pipfile.write()