Repository: astral-sh/uv
File: crates/uv/tests/it/common/mod.rs (Rust)

Code before:
            versions.iter().join(" ").into(),
        ));

        self
    }

    /// Add a custom filter to the `TestContext`.
    pub fn with_filter(mut self, filter: (String, String)) -> Self {
        self.filters.push(filter);
        self
    }

    // Unsets the git credential helper using temp home gitconfig
    pub fn with_git_credential_helper_blocked(self) -> Self {
        let path = self.home_dir.join(".gitconfig");
        let mut file = fs_err::OpenOptions::new()
            .create(true)
            .append(true)
            .open(&path)
            .expect("Failed to open gitconfig file");

        writeln!(file, "[credential]\n\thelper =\n")
            .expect("Failed to write credential helper to gitconfig");

        self
    }

    /// Clear filters on `TestContext`.
    pub fn clear_filters(mut self) -> Self {
        self.filters.clear();
        self
    }

    /// Default to the canonicalized path to the temp directory. We need to do this because on
    /// macOS (and Windows on GitHub Actions) the standard temp dir is a symlink. (On macOS, the
    /// temporary directory is, like `/var/...`, which resolves to `/private/var/...`.)
    ///
    /// It turns out that, at least on macOS, if we pass a symlink as `current_dir`, it gets
    /// _immediately_ resolved (such that if you call `current_dir` in the running `Command`, it
    /// returns resolved symlink). This breaks some snapshot tests, since we _don't_ want to
    /// resolve symlinks for user-provided paths.
    pub fn test_bucket_dir() -> PathBuf {
        std::env::temp_dir()
            .simple_canonicalize()
            .expect("failed to canonicalize temp dir")
            .join("uv")
            .join("tests")
    }

    /// Create a new test context with multiple Python versions.
    ///

Review comment (bug):
We may be able to leverage the existing assert_fs support, e.g.

```suggestion
    pub fn with_unset_git_credential_helper(self) -> Self {
        let git_config = self.home_dir.child(".gitconfig");
        git_config
            .write_str(indoc! {r"
                [credential]
                    helper =
            "})
            .expect("Failed to unset git credential helper");
        self
    }
```

Code after:
        self.extra_env.push((
            EnvVars::UV_INTERNAL__TEST_PYTHON_MANAGED.into(),
            versions.iter().join(" ").into(),
        ));

        self
    }

    /// Add a custom filter to the `TestContext`.
    pub fn with_filter(mut self, filter: (String, String)) -> Self {
        self.filters.push(filter);
        self
    }

    // Unsets the git credential helper using temp home gitconfig
    pub fn with_unset_git_credential_helper(self) -> Self {
        let git_config = self.home_dir.child(".gitconfig");
        git_config
            .write_str(indoc! {r"
                [credential]
                    helper =
            "})
            .expect("Failed to unset git credential helper");

        self
    }

    /// Clear filters on `TestContext`.
    pub fn clear_filters(mut self) -> Self {
        self.filters.clear();
        self
    }

    /// Default to the canonicalized path to the temp directory. We need to do this because on
    /// macOS (and Windows on GitHub Actions) the standard temp dir is a symlink. (On macOS, the
    /// temporary directory is, like `/var/...`, which resolves to `/private/var/...`.)
    ///
    /// It turns out that, at least on macOS, if we pass a symlink as `current_dir`, it gets
    /// _immediately_ resolved (such that if you call `current_dir` in the running `Command`, it
    /// returns resolved symlink). This breaks some snapshot tests, since we _don't_ want to
    /// resolve symlinks for user-provided paths.
    pub fn test_bucket_dir() -> PathBuf {
        std::env::temp_dir()
            .simple_canonicalize()
            .expect("failed to canonicalize temp dir")
            .join("uv")
            .join("tests")
    }

    /// Create a new test context with multiple Python versions.
    ///