Returns the existing tests in the given directory.
(dir: &Path)
| 289 | |
| 290 | /// Returns the existing tests in the given directory. |
| 291 | fn existing_tests(dir: &Path) -> Result<HashMap<String, PathBuf>> { |
| 292 | let mut tests = HashMap::new(); |
| 293 | |
| 294 | for file in fs::read_dir(dir)? { |
| 295 | let path = file?.path(); |
| 296 | if path.extension().unwrap_or_default() != "py" { |
| 297 | continue; |
| 298 | } |
| 299 | let name = path |
| 300 | .file_stem() |
| 301 | .map(|x| x.to_string_lossy().to_string()) |
| 302 | .unwrap(); |
| 303 | if let Some(old) = tests.insert(name, path) { |
| 304 | anyhow::bail!("Multiple test file exists for {old:?}"); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | Ok(tests) |
| 309 | } |