mirror of https://github.com/astral-sh/uv
Support `copy_dir_all` in unit tests too (#9124)
Refactoring for https://github.com/astral-sh/uv/pull/9091
This commit is contained in:
parent
50cfbd904c
commit
c2ccc2c5dc
|
|
@ -443,3 +443,18 @@ impl<Reader: tokio::io::AsyncRead + Unpin, Callback: Fn(usize) + Unpin> tokio::i
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Recursively copy a directory and its contents.
|
||||||
|
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
|
||||||
|
fs_err::create_dir_all(&dst)?;
|
||||||
|
for entry in fs_err::read_dir(src.as_ref())? {
|
||||||
|
let entry = entry?;
|
||||||
|
let ty = entry.file_type()?;
|
||||||
|
if ty.is_dir() {
|
||||||
|
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
||||||
|
} else {
|
||||||
|
fs_err::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1289,21 +1289,6 @@ pub fn run_and_format_with_status<T: AsRef<str>>(
|
||||||
(snapshot, output, status)
|
(snapshot, output, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively copy a directory and its contents.
|
|
||||||
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
|
|
||||||
fs_err::create_dir_all(&dst)?;
|
|
||||||
for entry in fs_err::read_dir(src.as_ref())? {
|
|
||||||
let entry = entry?;
|
|
||||||
let ty = entry.file_type()?;
|
|
||||||
if ty.is_dir() {
|
|
||||||
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
|
||||||
} else {
|
|
||||||
fs_err::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Recursively copy a directory and its contents, skipping gitignored files.
|
/// Recursively copy a directory and its contents, skipping gitignored files.
|
||||||
pub fn copy_dir_ignore(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<()> {
|
pub fn copy_dir_ignore(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<()> {
|
||||||
for entry in ignore::Walk::new(&src) {
|
for entry in ignore::Walk::new(&src) {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ fn freeze_many() -> Result<()> {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn freeze_duplicate() -> Result<()> {
|
fn freeze_duplicate() -> Result<()> {
|
||||||
use crate::common::copy_dir_all;
|
use uv_fs::copy_dir_all;
|
||||||
|
|
||||||
// Sync a version of `pip` into a virtual environment.
|
// Sync a version of `pip` into a virtual environment.
|
||||||
let context1 = TestContext::new("3.12");
|
let context1 = TestContext::new("3.12");
|
||||||
|
|
@ -72,7 +72,7 @@ fn freeze_duplicate() -> Result<()> {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Run `pip freeze`.
|
// Run `pip freeze`.
|
||||||
uv_snapshot!(context1.filters(), context1.pip_freeze().arg("--strict"), @r#"
|
uv_snapshot!(context1.filters(), context1.pip_freeze().arg("--strict"), @r###"
|
||||||
success: true
|
success: true
|
||||||
exit_code: 0
|
exit_code: 0
|
||||||
----- stdout -----
|
----- stdout -----
|
||||||
|
|
@ -83,7 +83,7 @@ fn freeze_duplicate() -> Result<()> {
|
||||||
warning: The package `pip` has multiple installed distributions:
|
warning: The package `pip` has multiple installed distributions:
|
||||||
- [SITE_PACKAGES]/pip-21.3.1.dist-info
|
- [SITE_PACKAGES]/pip-21.3.1.dist-info
|
||||||
- [SITE_PACKAGES]/pip-22.1.1.dist-info
|
- [SITE_PACKAGES]/pip-22.1.1.dist-info
|
||||||
"#
|
"###
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -3183,7 +3183,7 @@ fn config_settings() {
|
||||||
/// Reinstall a duplicate package in a virtual environment.
|
/// Reinstall a duplicate package in a virtual environment.
|
||||||
#[test]
|
#[test]
|
||||||
fn reinstall_duplicate() -> Result<()> {
|
fn reinstall_duplicate() -> Result<()> {
|
||||||
use crate::common::copy_dir_all;
|
use uv_fs::copy_dir_all;
|
||||||
|
|
||||||
// Sync a version of `pip` into a virtual environment.
|
// Sync a version of `pip` into a virtual environment.
|
||||||
let context1 = TestContext::new("3.12");
|
let context1 = TestContext::new("3.12");
|
||||||
|
|
@ -5399,7 +5399,7 @@ fn already_installed_local_version_of_remote_package() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn already_installed_multiple_versions() -> Result<()> {
|
fn already_installed_multiple_versions() -> Result<()> {
|
||||||
fn prepare(context: &TestContext) -> Result<()> {
|
fn prepare(context: &TestContext) -> Result<()> {
|
||||||
use crate::common::copy_dir_all;
|
use uv_fs::copy_dir_all;
|
||||||
|
|
||||||
// Install into the base environment
|
// Install into the base environment
|
||||||
context.pip_install().arg("anyio==3.7.0").assert().success();
|
context.pip_install().arg("anyio==3.7.0").assert().success();
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,9 @@ use predicates::Predicate;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::common::{
|
use crate::common::{
|
||||||
copy_dir_all, download_to_disk, site_packages_path, uv_snapshot, venv_to_interpreter,
|
download_to_disk, site_packages_path, uv_snapshot, venv_to_interpreter, TestContext,
|
||||||
TestContext,
|
|
||||||
};
|
};
|
||||||
use uv_fs::Simplified;
|
use uv_fs::{copy_dir_all, Simplified};
|
||||||
use uv_static::EnvVars;
|
use uv_static::EnvVars;
|
||||||
|
|
||||||
fn check_command(venv: &Path, command: &str, temp_dir: &Path) {
|
fn check_command(venv: &Path, command: &str, temp_dir: &Path) {
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,7 @@ fn uninstall_duplicate_by_path() -> Result<()> {
|
||||||
/// Uninstall a duplicate package in a virtual environment.
|
/// Uninstall a duplicate package in a virtual environment.
|
||||||
#[test]
|
#[test]
|
||||||
fn uninstall_duplicate() -> Result<()> {
|
fn uninstall_duplicate() -> Result<()> {
|
||||||
use crate::common::copy_dir_all;
|
use uv_fs::copy_dir_all;
|
||||||
|
|
||||||
// Sync a version of `pip` into a virtual environment.
|
// Sync a version of `pip` into a virtual environment.
|
||||||
let context1 = TestContext::new("3.12");
|
let context1 = TestContext::new("3.12");
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ use indoc::indoc;
|
||||||
use insta::assert_snapshot;
|
use insta::assert_snapshot;
|
||||||
use predicates::str::contains;
|
use predicates::str::contains;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use uv_fs::copy_dir_all;
|
||||||
use uv_python::PYTHON_VERSION_FILENAME;
|
use uv_python::PYTHON_VERSION_FILENAME;
|
||||||
use uv_static::EnvVars;
|
use uv_static::EnvVars;
|
||||||
|
|
||||||
use crate::common::{copy_dir_all, uv_snapshot, TestContext};
|
use crate::common::{uv_snapshot, TestContext};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_with_python_version() -> Result<()> {
|
fn run_with_python_version() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ use assert_fs::{
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use insta::assert_snapshot;
|
use insta::assert_snapshot;
|
||||||
use predicates::prelude::predicate;
|
use predicates::prelude::predicate;
|
||||||
|
use uv_fs::copy_dir_all;
|
||||||
use uv_static::EnvVars;
|
use uv_static::EnvVars;
|
||||||
|
|
||||||
use crate::common::{copy_dir_all, uv_snapshot, TestContext};
|
use crate::common::{uv_snapshot, TestContext};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tool_install() {
|
fn tool_install() {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
use crate::common::{copy_dir_all, uv_snapshot, TestContext};
|
use crate::common::{uv_snapshot, TestContext};
|
||||||
use assert_cmd::prelude::*;
|
use assert_cmd::prelude::*;
|
||||||
use assert_fs::prelude::*;
|
use assert_fs::prelude::*;
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
|
use uv_fs::copy_dir_all;
|
||||||
use uv_static::EnvVars;
|
use uv_static::EnvVars;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue