Skip to content

Commit bf64216

Browse files
committed
test: normalize Windows JSONRPC path assertions
1 parent 2b1c75d commit bf64216

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

crates/pet/tests/jsonrpc_server_test.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
use pet_fs::path::norm_case;
45
use serde_json::json;
56
use std::fs;
67
use std::path::{Path, PathBuf};
@@ -79,6 +80,10 @@ fn cache_dir(root: &TempDir) -> PathBuf {
7980
root.path().join("cache")
8081
}
8182

83+
fn normalized_notification_path(path: &Option<String>) -> Option<PathBuf> {
84+
path.as_ref().map(|path| norm_case(PathBuf::from(path)))
85+
}
86+
8287
fn assert_single_environment(
8388
environments: &[EnvironmentNotification],
8489
expected_executable: &Path,
@@ -95,16 +100,12 @@ fn assert_single_environment(
95100
assert_eq!(environment.kind.as_deref(), Some("Venv"));
96101
assert_eq!(environment.name.as_deref(), Some(expected_name));
97102
assert_eq!(
98-
environment
99-
.executable
100-
.as_ref()
101-
.map(PathBuf::from)
102-
.as_deref(),
103-
Some(expected_executable)
103+
normalized_notification_path(&environment.executable).as_deref(),
104+
Some(norm_case(expected_executable)).as_deref()
104105
);
105106
assert_eq!(
106-
environment.prefix.as_ref().map(PathBuf::from).as_deref(),
107-
Some(expected_prefix)
107+
normalized_notification_path(&environment.prefix).as_deref(),
108+
Some(norm_case(expected_prefix)).as_deref()
108109
);
109110
assert_eq!(environment.error, None);
110111
}
@@ -212,15 +213,14 @@ fn concurrent_identical_refresh_requests_share_one_notification_stream() {
212213
expected_names.sort();
213214
assert_eq!(names, expected_names);
214215
for venv in venvs {
215-
let expected_executable =
216-
python_executable_path(&venv.join(if cfg!(windows) { "Scripts" } else { "bin" }));
216+
let expected_executable = norm_case(python_executable_path(&venv.join(if cfg!(windows) {
217+
"Scripts"
218+
} else {
219+
"bin"
220+
})));
217221
assert!(
218222
environments.iter().any(|environment| {
219-
environment
220-
.executable
221-
.as_ref()
222-
.map(PathBuf::from)
223-
.as_deref()
223+
normalized_notification_path(&environment.executable).as_deref()
224224
== Some(expected_executable.as_path())
225225
}),
226226
"expected to find notification for {:?}; notifications: {:?}; stderr: {}",
@@ -292,27 +292,27 @@ fn concurrent_distinct_refresh_requests_run_separately() {
292292
assert_eq!(environments[0].kind.as_deref(), Some("Venv"));
293293
assert_eq!(environments[0].name.as_deref(), Some("first-env"));
294294
assert_eq!(
295-
environments[0]
296-
.executable
297-
.as_ref()
298-
.map(PathBuf::from)
299-
.as_deref(),
295+
normalized_notification_path(&environments[0].executable).as_deref(),
300296
Some(
301-
python_executable_path(&venv_a.join(if cfg!(windows) { "Scripts" } else { "bin" }))
302-
.as_path()
297+
norm_case(python_executable_path(&venv_a.join(if cfg!(windows) {
298+
"Scripts"
299+
} else {
300+
"bin"
301+
}),))
302+
.as_path()
303303
)
304304
);
305305
assert_eq!(environments[1].kind.as_deref(), Some("Venv"));
306306
assert_eq!(environments[1].name.as_deref(), Some("second-env"));
307307
assert_eq!(
308-
environments[1]
309-
.executable
310-
.as_ref()
311-
.map(PathBuf::from)
312-
.as_deref(),
308+
normalized_notification_path(&environments[1].executable).as_deref(),
313309
Some(
314-
python_executable_path(&venv_b.join(if cfg!(windows) { "Scripts" } else { "bin" }))
315-
.as_path()
310+
norm_case(python_executable_path(&venv_b.join(if cfg!(windows) {
311+
"Scripts"
312+
} else {
313+
"bin"
314+
}),))
315+
.as_path()
316316
)
317317
);
318318
assert_eq!(

0 commit comments

Comments
 (0)