fix: failing snapshot test on Windows

This commit is contained in:
Martin Fischer 2023-02-01 09:34:46 +01:00 committed by Charlie Marsh
parent 39b5fa0e24
commit faea478ca5
2 changed files with 6 additions and 1 deletions

View File

@ -81,7 +81,8 @@ pub fn normalize_path_to<P: AsRef<Path>, R: AsRef<Path>>(path: P, project_root:
}
/// Convert an absolute path to be relative to the current working directory.
pub fn relativize_path(path: &Path) -> String {
pub fn relativize_path(path: impl AsRef<Path>) -> String {
let path = path.as_ref();
if let Ok(path) = path.strip_prefix(&*path_dedot::CWD) {
return format!("{}", path.display());
}

View File

@ -21,6 +21,10 @@ impl Violation for ImplicitNamespacePackage {
/// INP001
pub fn implicit_namespace_package(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
if package.is_none() && path.extension().map_or(true, |ext| ext != "pyi") {
#[cfg(all(test, windows))]
let path = path
.to_string_lossy()
.replace(std::path::MAIN_SEPARATOR, "/"); // The snapshot test expects / as the path separator.
Some(Diagnostic::new(
ImplicitNamespacePackage(fs::relativize_path(path)),
Range::default(),