Skip to content

Commit 24c45d4

Browse files
committed
updates
1 parent 7b22622 commit 24c45d4

File tree

8 files changed

+15
-123
lines changed

8 files changed

+15
-123
lines changed

crates/pet-python-utils/tests/cache_test.rs

Lines changed: 14 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// Licensed under the MIT License.
33

44
mod common;
5-
use std::{path::PathBuf, sync::Once};
5+
use std::{env, path::PathBuf, sync::Once, time::SystemTime};
66

77
use common::resolve_test_path;
8+
use pet_python_utils::cache::{get_cache_directory, set_cache_directory};
89

910
static INIT: Once = Once::new();
1011

@@ -14,6 +15,8 @@ fn setup() {
1415
env_logger::builder()
1516
.filter(None, log::LevelFilter::Trace)
1617
.init();
18+
19+
set_cache_directory(env::temp_dir().join("pet_cache"));
1720
});
1821
}
1922

@@ -30,19 +33,17 @@ fn setup() {
3033
)]
3134
#[allow(dead_code)]
3235
fn verify_cache() {
33-
use std::{env, fs};
36+
use std::fs;
3437

3538
use pet_python_utils::{
36-
cache::{clear_cache, create_cache, set_cache_directory},
39+
cache::{clear_cache, create_cache},
3740
env::ResolvedPythonEnv,
3841
fs_cache::generate_cache_file,
3942
};
4043

4144
setup();
4245

43-
let cache_dir = env::temp_dir().join("pet_cache");
44-
set_cache_directory(cache_dir.clone());
45-
46+
let cache_dir = get_cache_directory().unwrap();
4647
let prefix: PathBuf = resolve_test_path(&["unix", "executables", ".venv"]).into();
4748
let bin = prefix.join("bin");
4849
let python = bin.join("python");
@@ -77,67 +78,6 @@ fn verify_cache() {
7778
let cache = create_cache(resolve_env.executable.clone());
7879
let cache = cache.lock().unwrap();
7980

80-
assert!(cache.get().is_some());
81-
assert!(cache_file.exists());
82-
drop(cache);
83-
84-
// Deleting the cache file and Creating a new cache should not load the value from the file.
85-
let _ = clear_cache();
86-
let cache = create_cache(resolve_env.executable.clone());
87-
let cache = cache.lock().unwrap();
88-
89-
assert!(cache.get().is_none());
90-
assert!(!cache_file.exists());
91-
}
92-
93-
#[cfg_attr(
94-
any(
95-
feature = "ci", // Try to run this in all ci jobs/environments
96-
feature = "ci-jupyter-container",
97-
feature = "ci-homebrew-container",
98-
feature = "ci-poetry-global",
99-
feature = "ci-poetry-project",
100-
feature = "ci-poetry-custom",
101-
),
102-
test
103-
)]
104-
#[allow(dead_code)]
105-
fn verify_invalidating_cache() {
106-
use std::{env, fs, time::SystemTime};
107-
108-
use pet_python_utils::{
109-
cache::{create_cache, set_cache_directory},
110-
env::ResolvedPythonEnv,
111-
fs_cache::generate_cache_file,
112-
};
113-
114-
setup();
115-
116-
let cache_dir = env::temp_dir().join("pet_cache");
117-
set_cache_directory(cache_dir.clone());
118-
119-
let prefix: PathBuf = resolve_test_path(&["unix", "executables", ".venv2"]).into();
120-
let bin = prefix.join("bin");
121-
let python = bin.join("python");
122-
let python3 = bin.join("python3");
123-
let resolve_env = ResolvedPythonEnv {
124-
executable: python.clone(),
125-
version: "3.9.9".to_string(),
126-
prefix: prefix.clone(),
127-
is64_bit: true,
128-
symlinks: Some(vec![python.clone(), python3.clone()]),
129-
};
130-
131-
// Ensure the file does not exist.
132-
let cache_file = generate_cache_file(&cache_dir, &resolve_env.executable);
133-
let _ = fs::remove_file(&cache_file);
134-
135-
let cache = create_cache(resolve_env.executable.clone());
136-
let cache = cache.lock().unwrap();
137-
138-
// Store the value in cache and verify the file exists.
139-
cache.store(resolve_env.clone());
140-
14181
assert!(cache.get().is_some());
14282
assert!(cache_file.exists());
14383

@@ -146,59 +86,20 @@ fn verify_invalidating_cache() {
14686
let _ = fs::write(python.clone(), format!("{:?}", SystemTime::now()));
14787
assert!(cache.get().is_none());
14888
assert!(!cache_file.exists());
149-
}
150-
151-
#[cfg_attr(
152-
any(
153-
feature = "ci", // Try to run this in all ci jobs/environments
154-
feature = "ci-jupyter-container",
155-
feature = "ci-homebrew-container",
156-
feature = "ci-poetry-global",
157-
feature = "ci-poetry-project",
158-
feature = "ci-poetry-custom",
159-
),
160-
test
161-
)]
162-
#[allow(dead_code)]
163-
fn verify_invalidating_cache_due_to_hash_conflicts() {
164-
use std::{env, fs};
165-
166-
use pet_python_utils::{
167-
cache::{clear_cache, create_cache, set_cache_directory},
168-
env::ResolvedPythonEnv,
169-
fs_cache::generate_cache_file,
170-
};
171-
172-
setup();
173-
174-
let cache_dir = env::temp_dir().join("pet_cache");
175-
set_cache_directory(cache_dir.clone());
176-
177-
let prefix: PathBuf = resolve_test_path(&["unix", "executables", ".venv3"]).into();
178-
let bin = prefix.join("bin");
179-
let python = bin.join("python");
180-
let python3 = bin.join("python3");
181-
let resolve_env = ResolvedPythonEnv {
182-
executable: python.clone(),
183-
version: "3.9.9".to_string(),
184-
prefix: prefix.clone(),
185-
is64_bit: true,
186-
symlinks: Some(vec![python.clone(), python3.clone()]),
187-
};
188-
189-
// Ensure the file does not exist.
190-
let cache_file = generate_cache_file(&cache_dir, &resolve_env.executable);
191-
let _ = fs::remove_file(&cache_file);
89+
drop(cache);
19290

91+
// Deleting the cache file and Creating a new cache should not load the value from the file.
92+
let _ = clear_cache();
19393
let cache = create_cache(resolve_env.executable.clone());
19494
let cache = cache.lock().unwrap();
19595

196-
// Store the value in cache and verify the file exists.
197-
cache.store(resolve_env.clone());
96+
assert!(cache.get().is_none());
97+
assert!(!cache_file.exists());
19898

99+
// Now store in cache again
100+
cache.store(resolve_env.clone());
199101
assert!(cache.get().is_some());
200102
assert!(cache_file.exists());
201-
drop(cache);
202103

203104
// Simulate a hash collision by changing the executable to a different value.
204105
// I.e. the cached file points to another executable.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SystemTime { tv_sec: 1721186754, tv_nsec: 324707000 }

crates/pet-python-utils/tests/unix/executables/.venv2/bin/python

Whitespace-only changes.

crates/pet-python-utils/tests/unix/executables/.venv2/bin/python3

Whitespace-only changes.

crates/pet-python-utils/tests/unix/executables/.venv2/pyvenv.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

crates/pet-python-utils/tests/unix/executables/.venv3/bin/python

Whitespace-only changes.

crates/pet-python-utils/tests/unix/executables/.venv3/bin/python3

Whitespace-only changes.

crates/pet-python-utils/tests/unix/executables/.venv3/pyvenv.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)