From bf07c7bb724cc40c8fc793c88b98ebd14e9f6b9d Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 3 Mar 2024 13:01:41 -0800 Subject: [PATCH] Add tests for empty index URL environment variable (#2141) --- crates/uv/tests/pip_compile.rs | 121 +++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index a51be6067..7ae410042 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -4517,3 +4517,124 @@ fn editable_direct_dependency() -> Result<()> { Ok(()) } + +/// Setting `UV_INDEX_URL` to the empty string should treat it as "unset". +#[test] +fn empty_index_url_env_var() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("anyio")?; + + uv_snapshot!(context.compile() + .arg("requirements.in") + .arg("--emit-index-url") + .env("UV_INDEX_URL", ""), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --emit-index-url + --index-url https://pypi.org/simple + + anyio==4.0.0 + idna==3.4 + # via anyio + sniffio==1.3.0 + # via anyio + + ----- stderr ----- + Resolved 3 packages in [TIME] + "### + ); + + Ok(()) +} + +/// Setting `EXTRA_UV_INDEX_URL` to the empty string should treat it as "unset". +#[test] +fn empty_extra_index_url_env_var() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("anyio")?; + + uv_snapshot!(context.compile() + .arg("requirements.in") + .arg("--emit-index-url") + .env("EXTRA_UV_INDEX_URL", ""), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --emit-index-url + --index-url https://pypi.org/simple + + anyio==4.0.0 + idna==3.4 + # via anyio + sniffio==1.3.0 + # via anyio + + ----- stderr ----- + Resolved 3 packages in [TIME] + "### + ); + + Ok(()) +} + +/// Setting `UV_INDEX_URL` to the empty string should treat it as "unset", and so should be +/// overridden by an `--index-url` in a requirements file. +#[test] +fn empty_index_url_env_var_override() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("--index-url https://test.pypi.org/simple\nidna")?; + + uv_snapshot!(context.compile() + .arg("requirements.in") + .arg("--emit-index-url") + .env("UV_INDEX_URL", ""), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --emit-index-url + --index-url https://test.pypi.org/simple + + idna==2.7 + + ----- stderr ----- + Resolved 1 package in [TIME] + "### + ); + + Ok(()) +} + +/// The `UV_INDEX_URL` should override an `--index-url` in a requirements file. +#[test] +fn index_url_env_var_override() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("--index-url https://pypi.org/simple\nidna")?; + + uv_snapshot!(context.compile() + .arg("requirements.in") + .arg("--emit-index-url") + .env("UV_INDEX_URL", "https://test.pypi.org/simple"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --emit-index-url + --index-url https://test.pypi.org/simple + + idna==2.7 + + ----- stderr ----- + Resolved 1 package in [TIME] + "### + ); + + Ok(()) +}