Compare the ".py" and ".pyc" count

This commit is contained in:
Tomasz (Tom) Kramkowski 2025-12-16 18:28:22 +00:00
parent 7cc9212051
commit 9693f2ef91
1 changed files with 16 additions and 14 deletions

View File

@ -3955,6 +3955,19 @@ fn python_install_upgrade_version_file() {
#[test] #[test]
fn python_install_compile_bytecode() -> anyhow::Result<()> { fn python_install_compile_bytecode() -> anyhow::Result<()> {
fn count_files_by_ext(dir: &Path, extension: &str) -> anyhow::Result<usize> {
let mut count = 0;
let walker = WalkDir::new(dir).into_iter();
for entry in walker {
let entry = entry?;
let path = entry.path();
if entry.metadata()?.is_file() && path.extension().is_some_and(|ext| ext == extension) {
count += 1;
}
}
Ok(count)
}
let context: TestContext = TestContext::new_with_versions(&[]) let context: TestContext = TestContext::new_with_versions(&[])
.with_filtered_python_keys() .with_filtered_python_keys()
.with_filtered_exe_suffix() .with_filtered_exe_suffix()
@ -3988,20 +4001,9 @@ fn python_install_compile_bytecode() -> anyhow::Result<()> {
.join("python3.14"); .join("python3.14");
// And the count should match // And the count should match
let count = { let pyc_count = count_files_by_ext(&stdlib, "pyc")?;
let mut count = 0; let py_count = count_files_by_ext(&stdlib, "py")?;
let walker = WalkDir::new(stdlib).into_iter(); assert_eq!(pyc_count, py_count);
for entry in walker {
let entry = entry?;
let path = entry.path();
if entry.metadata()?.is_file() && path.extension().is_some_and(|ext| ext == "pyc") {
count += 1;
}
}
count
};
insta::assert_snapshot!(count.to_string(), @"1052");
// Attempting to install with --compile-bytecode should (currently) // Attempting to install with --compile-bytecode should (currently)
// unconditionally re-run the bytecode compiler // unconditionally re-run the bytecode compiler