Skip to content

Commit

Permalink
Use [N] in lieu of exact prune counts (#8992)
Browse files Browse the repository at this point in the history
## Summary

These can seemingly vary.
  • Loading branch information
charliermarsh authored Nov 10, 2024
1 parent 874aa29 commit 13c3a70
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions crates/uv/tests/it/cache_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ fn prune_no_op() -> Result<()> {
.assert()
.success();

uv_snapshot!(context.filters(), context.prune().arg("--verbose"), @r###"
let filters: Vec<_> = context
.filters()
.into_iter()
.chain(std::iter::once((r"Removed \d+ files", "Removed [N] files")))
.collect();

uv_snapshot!(&filters, context.prune().arg("--verbose"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down Expand Up @@ -56,7 +62,13 @@ fn prune_stale_directory() -> Result<()> {
let simple = context.cache_dir.child("simple-v4");
simple.create_dir_all()?;

uv_snapshot!(context.filters(), context.prune().arg("--verbose"), @r###"
let filters: Vec<_> = context
.filters()
.into_iter()
.chain(std::iter::once((r"Removed \d+ files", "Removed [N] files")))
.collect();

uv_snapshot!(&filters, context.prune().arg("--verbose"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand All @@ -78,7 +90,13 @@ fn prune_cached_env() {
let tool_dir = context.temp_dir.child("tools");
let bin_dir = context.temp_dir.child("bin");

uv_snapshot!(context.filters(), context.tool_run()
let filters: Vec<_> = context
.filters()
.into_iter()
.chain(std::iter::once((r"Removed \d+ files", "Removed [N] files")))
.collect();

uv_snapshot!(&filters, context.tool_run()
.arg("[email protected]")
.arg("--version")
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
Expand Down Expand Up @@ -181,8 +199,12 @@ fn prune_unzipped() -> Result<()> {
iniconfig
" })?;

let filters: Vec<_> = std::iter::once((r"Removed \d+ files", "Removed [N] files"))
.chain(context.filters())
.collect();

// Install a requirement, to populate the cache.
uv_snapshot!(context.filters(), context.pip_install().arg("-r").env_remove(EnvVars::UV_EXCLUDE_NEWER).arg("requirements.txt").arg("--reinstall"), @r###"
uv_snapshot!(&filters, context.pip_install().arg("-r").env_remove(EnvVars::UV_EXCLUDE_NEWER).arg("requirements.txt").arg("--reinstall"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand All @@ -195,14 +217,14 @@ fn prune_unzipped() -> Result<()> {
+ source-distribution==0.0.1
"###);

uv_snapshot!(context.filters(), context.prune().arg("--ci"), @r###"
uv_snapshot!(&filters, context.prune().arg("--ci"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Pruning cache at: [CACHE_DIR]/
Removed 169 files ([SIZE])
Removed [N] files ([SIZE])
"###);

context.venv().assert().success();
Expand All @@ -212,7 +234,7 @@ fn prune_unzipped() -> Result<()> {
requirements_txt.write_str(indoc! { r"
source-distribution==0.0.1
" })?;
uv_snapshot!(context.filters(), context.pip_install().arg("-r").env_remove(EnvVars::UV_EXCLUDE_NEWER).arg("requirements.txt").arg("--offline"), @r###"
uv_snapshot!(&filters, context.pip_install().arg("-r").env_remove(EnvVars::UV_EXCLUDE_NEWER).arg("requirements.txt").arg("--offline"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand All @@ -228,7 +250,7 @@ fn prune_unzipped() -> Result<()> {
requirements_txt.write_str(indoc! { r"
iniconfig
" })?;
uv_snapshot!(context.filters(), context.pip_install().arg("-r").env_remove(EnvVars::UV_EXCLUDE_NEWER).arg("requirements.txt").arg("--offline"), @r###"
uv_snapshot!(&filters, context.pip_install().arg("-r").env_remove(EnvVars::UV_EXCLUDE_NEWER).arg("requirements.txt").arg("--offline"), @r###"
success: false
exit_code: 1
----- stdout -----
Expand Down Expand Up @@ -275,8 +297,14 @@ fn prune_stale_revision() -> Result<()> {
context.temp_dir.child("src").child("__init__.py").touch()?;
context.temp_dir.child("README").touch()?;

let filters: Vec<_> = context
.filters()
.into_iter()
.chain(std::iter::once((r"Removed \d+ files", "Removed [N] files")))
.collect();

// Install the same package twice, with `--reinstall`.
uv_snapshot!(context.filters(), context
uv_snapshot!(&filters, context
.pip_install()
.arg(".")
.arg("--reinstall"), @r###"
Expand All @@ -291,7 +319,7 @@ fn prune_stale_revision() -> Result<()> {
+ project==0.1.0 (from file://[TEMP_DIR]/)
"###);

uv_snapshot!(context.filters(), context
uv_snapshot!(&filters, context
.pip_install()
.arg(".")
.arg("--reinstall"), @r###"
Expand All @@ -307,8 +335,7 @@ fn prune_stale_revision() -> Result<()> {
~ project==0.1.0 (from file://[TEMP_DIR]/)
"###);

let filters: Vec<_> = context
.filters()
let filters: Vec<_> = filters
.into_iter()
.chain([
// The cache entry does not have a stable key, so we filter it out
Expand All @@ -330,11 +357,11 @@ fn prune_stale_revision() -> Result<()> {
Pruning cache at: [CACHE_DIR]/
DEBUG Removing dangling source revision: [CACHE_DIR]/sdists-v6/[ENTRY]
DEBUG Removing dangling cache archive: [CACHE_DIR]/archive-v0/[ENTRY]
Removed 8 files ([SIZE])
Removed [N] files ([SIZE])
"###);

// Uninstall and reinstall the package. We should use the cached version.
uv_snapshot!(context.filters(), context
uv_snapshot!(&filters, context
.pip_uninstall()
.arg("."), @r###"
success: true
Expand All @@ -346,7 +373,7 @@ fn prune_stale_revision() -> Result<()> {
- project==0.1.0 (from file://[TEMP_DIR]/)
"###);

uv_snapshot!(context.filters(), context
uv_snapshot!(&filters, context
.pip_install()
.arg("."), @r###"
success: true
Expand Down

0 comments on commit 13c3a70

Please sign in to comment.