Skip to content

Commit c2ccc2c

Browse files
authored
Support copy_dir_all in unit tests too (#9124)
Refactoring for #9091
1 parent 50cfbd9 commit c2ccc2c

File tree

9 files changed

+29
-29
lines changed

9 files changed

+29
-29
lines changed

crates/uv-fs/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,18 @@ impl<Reader: tokio::io::AsyncRead + Unpin, Callback: Fn(usize) + Unpin> tokio::i
443443
})
444444
}
445445
}
446+
447+
/// Recursively copy a directory and its contents.
448+
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
449+
fs_err::create_dir_all(&dst)?;
450+
for entry in fs_err::read_dir(src.as_ref())? {
451+
let entry = entry?;
452+
let ty = entry.file_type()?;
453+
if ty.is_dir() {
454+
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
455+
} else {
456+
fs_err::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
457+
}
458+
}
459+
Ok(())
460+
}

crates/uv/tests/it/common/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,21 +1289,6 @@ pub fn run_and_format_with_status<T: AsRef<str>>(
12891289
(snapshot, output, status)
12901290
}
12911291

1292-
/// Recursively copy a directory and its contents.
1293-
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
1294-
fs_err::create_dir_all(&dst)?;
1295-
for entry in fs_err::read_dir(src.as_ref())? {
1296-
let entry = entry?;
1297-
let ty = entry.file_type()?;
1298-
if ty.is_dir() {
1299-
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
1300-
} else {
1301-
fs_err::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
1302-
}
1303-
}
1304-
Ok(())
1305-
}
1306-
13071292
/// Recursively copy a directory and its contents, skipping gitignored files.
13081293
pub fn copy_dir_ignore(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<()> {
13091294
for entry in ignore::Walk::new(&src) {

crates/uv/tests/it/pip_freeze.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn freeze_many() -> Result<()> {
3939
#[test]
4040
#[cfg(unix)]
4141
fn freeze_duplicate() -> Result<()> {
42-
use crate::common::copy_dir_all;
42+
use uv_fs::copy_dir_all;
4343

4444
// Sync a version of `pip` into a virtual environment.
4545
let context1 = TestContext::new("3.12");
@@ -72,7 +72,7 @@ fn freeze_duplicate() -> Result<()> {
7272
)?;
7373

7474
// Run `pip freeze`.
75-
uv_snapshot!(context1.filters(), context1.pip_freeze().arg("--strict"), @r#"
75+
uv_snapshot!(context1.filters(), context1.pip_freeze().arg("--strict"), @r###"
7676
success: true
7777
exit_code: 0
7878
----- stdout -----
@@ -83,7 +83,7 @@ fn freeze_duplicate() -> Result<()> {
8383
warning: The package `pip` has multiple installed distributions:
8484
- [SITE_PACKAGES]/pip-21.3.1.dist-info
8585
- [SITE_PACKAGES]/pip-22.1.1.dist-info
86-
"#
86+
"###
8787
);
8888

8989
Ok(())

crates/uv/tests/it/pip_install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,7 +3183,7 @@ fn config_settings() {
31833183
/// Reinstall a duplicate package in a virtual environment.
31843184
#[test]
31853185
fn reinstall_duplicate() -> Result<()> {
3186-
use crate::common::copy_dir_all;
3186+
use uv_fs::copy_dir_all;
31873187

31883188
// Sync a version of `pip` into a virtual environment.
31893189
let context1 = TestContext::new("3.12");
@@ -5399,7 +5399,7 @@ fn already_installed_local_version_of_remote_package() {
53995399
#[cfg(unix)]
54005400
fn already_installed_multiple_versions() -> Result<()> {
54015401
fn prepare(context: &TestContext) -> Result<()> {
5402-
use crate::common::copy_dir_all;
5402+
use uv_fs::copy_dir_all;
54035403

54045404
// Install into the base environment
54055405
context.pip_install().arg("anyio==3.7.0").assert().success();

crates/uv/tests/it/pip_sync.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ use predicates::Predicate;
1212
use url::Url;
1313

1414
use crate::common::{
15-
copy_dir_all, download_to_disk, site_packages_path, uv_snapshot, venv_to_interpreter,
16-
TestContext,
15+
download_to_disk, site_packages_path, uv_snapshot, venv_to_interpreter, TestContext,
1716
};
18-
use uv_fs::Simplified;
17+
use uv_fs::{copy_dir_all, Simplified};
1918
use uv_static::EnvVars;
2019

2120
fn check_command(venv: &Path, command: &str, temp_dir: &Path) {

crates/uv/tests/it/pip_uninstall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn uninstall_duplicate_by_path() -> Result<()> {
327327
/// Uninstall a duplicate package in a virtual environment.
328328
#[test]
329329
fn uninstall_duplicate() -> Result<()> {
330-
use crate::common::copy_dir_all;
330+
use uv_fs::copy_dir_all;
331331

332332
// Sync a version of `pip` into a virtual environment.
333333
let context1 = TestContext::new("3.12");

crates/uv/tests/it/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use indoc::indoc;
77
use insta::assert_snapshot;
88
use predicates::str::contains;
99
use std::path::Path;
10-
10+
use uv_fs::copy_dir_all;
1111
use uv_python::PYTHON_VERSION_FILENAME;
1212
use uv_static::EnvVars;
1313

14-
use crate::common::{copy_dir_all, uv_snapshot, TestContext};
14+
use crate::common::{uv_snapshot, TestContext};
1515

1616
#[test]
1717
fn run_with_python_version() -> Result<()> {

crates/uv/tests/it/tool_install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use assert_fs::{
88
use indoc::indoc;
99
use insta::assert_snapshot;
1010
use predicates::prelude::predicate;
11-
11+
use uv_fs::copy_dir_all;
1212
use uv_static::EnvVars;
1313

14-
use crate::common::{copy_dir_all, uv_snapshot, TestContext};
14+
use crate::common::{uv_snapshot, TestContext};
1515

1616
#[test]
1717
fn tool_install() {

crates/uv/tests/it/tool_run.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::common::{copy_dir_all, uv_snapshot, TestContext};
1+
use crate::common::{uv_snapshot, TestContext};
22
use assert_cmd::prelude::*;
33
use assert_fs::prelude::*;
44
use indoc::indoc;
5+
use uv_fs::copy_dir_all;
56
use uv_static::EnvVars;
67

78
#[test]

0 commit comments

Comments
 (0)