Test for .venv symlink (#6597)

For various reasons, I have a preference for out of tree virtual
environments. Things just work if I symlink, but I don't know that this
is guaranteed, so I thought I'd add a test for it. It looks like there's
another code path that matters (`FoundInterpreter::discover ->
PythonEnvironment::from_root`) for the higher level commands, but
couldn't spot a good place to test that.

Related discussion:
https://github.com/astral-sh/uv/issues/1495#issuecomment-1950442191 /
https://github.com/astral-sh/uv/issues/1578#issuecomment-1949911871
This commit is contained in:
Shantanu 2024-08-26 09:44:19 -07:00 committed by GitHub
parent 50997bcb41
commit 6220532373
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1562,6 +1562,32 @@ mod tests {
Ok(())
}
#[test]
fn find_python_venv_symlink() -> Result<()> {
let context = TestContext::new()?;
let venv = context.tempdir.child("target").child("env");
TestContext::mock_venv(&venv, "3.10.6")?;
let symlink = context.tempdir.child("proj").child(".venv");
context.tempdir.child("proj").create_dir_all()?;
symlink.symlink_to_dir(venv)?;
let python = context.run(|| {
find_python_installation(
&PythonRequest::parse("../proj/.venv"),
EnvironmentPreference::Any,
PythonPreference::OnlySystem,
&context.cache,
)
})??;
assert_eq!(
python.interpreter().python_full_version().to_string(),
"3.10.6",
"We should find the symlinked venv"
);
Ok(())
}
#[test]
fn find_python_treats_missing_file_path_as_file() -> Result<()> {
let context = TestContext::new()?;