Repository: pypa/pip
File: tests/functional/test_install_script.py (Python)

Code before:
    """

    other_lib_name, other_lib_version = "peppercorn", "0.6"
    script_path = script.scratch_path.joinpath("script.py")
    script_path.write_text(
        textwrap.dedent(
            f"""\
            # /// script
            # dependencies = [
            #   "INITools==0.2",
            #   "{other_lib_name}<={other_lib_version}",
            # ]
            # ///

            print("Hello world from a dummy program")
            """
        )
    )
    result = script.pip("install", "--requirements-from-script", script_path)

    # NOTE:2024-10-05:snoopj:assertions same as in test_requirements_file
    result.did_create(script.site_packages / "initools-0.2.dist-info")
    result.did_create(script.site_packages / "initools")
    assert result.files_created[script.site_packages / other_lib_name].dir
    fn = f"{other_lib_name}-{other_lib_version}.dist-info"
    assert result.files_created[script.site_packages / fn].dir


def test_multiple_scripts(script: PipTestEnvironment) -> None:
    """
    Test that --requirements-from-script can only be given once in an install command.
    """
    result = script.pip(
        "install",
        "--requirements-from-script",
        "does_not_exist.py",
        "--requirements-from-script",
        "also_does_not_exist.py",
        allow_stderr_error=True,
        expect_error=True,
    )

    assert (
        "ERROR: --requirements-from-script can only be given once" in result.stderr
    ), ("multiple script did not fail as expected -- " + result.stderr)


@pytest.mark.network
def test_script_file_python_version(script: PipTestEnvironment) -> None:
    """
    Test installing from a script with an incompatible `requires-python`

Review comment (suggestion):
The `result.assert_installed()` can be used instead:

- `result.assert_installed("package")` to simply do a name check
- `result.assert_installed(package="1.0.0")` to do a name and version check 

Code after:
    script_path.write_text(
        textwrap.dedent(
            """\
            # /// script
            # dependencies = [
            #   "INITools==0.2",
            #   "simple==1.0",
            # ]
            # ///

            print("Hello world from a dummy program")
            """
        )
    )
    script.pip_install_local("--requirements-from-script", script_path)
    script.assert_installed(initools="0.2", simple="1.0")


def test_multiple_scripts(script: PipTestEnvironment) -> None:
    """
    Test that --requirements-from-script can only be given once in an install command.
    """
    result = script.pip(
        "install",
        "--requirements-from-script",
        "does_not_exist.py",
        "--requirements-from-script",
        "also_does_not_exist.py",
        allow_stderr_error=True,
        expect_error=True,
    )

    assert (
        "ERROR: --requirements-from-script can only be given once" in result.stderr
    ), ("multiple script did not fail as expected -- " + result.stderr)


def test_script_file_python_version(script: PipTestEnvironment) -> None:
    """
    Test installing from a script with an incompatible `requires-python`
    """

    script_path = script.scratch_path.joinpath("script.py")

    script_path.write_text(
        textwrap.dedent(
            f"""\
            # /// script
            # requires-python = "!={sys.version_info.major}.{sys.version_info.minor}.*"
            # dependencies = [
            #   "INITools==0.2",