Skip to content

Commit

Permalink
Fix pep508 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Oct 30, 2024
1 parent 509dda5 commit 7a3dbbe
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 52 deletions.
32 changes: 22 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/uv-pep508/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ version-ranges = { workspace = true }
insta = { version = "1.40.0" }
log = { version = "0.4.22" }
serde_json = { version = "1.0.128" }
testing_logger = { version = "0.1.1" }
tracing-test = { version = "0.2.5" }

[features]
tracing = ["dep:tracing", "uv-pep440/tracing"]
Expand Down
89 changes: 48 additions & 41 deletions crates/uv-pep508/src/marker/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,59 +1937,66 @@ mod test {

#[test]
#[cfg(feature = "tracing")]
fn warnings() {
#[tracing_test::traced_test]
fn warnings1() {
let env37 = env37();
testing_logger::setup();
let compare_keys = MarkerTree::from_str("platform_version == sys_platform").unwrap();
compare_keys.evaluate(&env37, &[]);
testing_logger::validate(|captured_logs| {
assert_eq!(
captured_logs[0].body,
"Comparing two markers with each other doesn't make any sense, will evaluate to false"
);
assert_eq!(captured_logs[0].level, log::Level::Warn);
assert_eq!(captured_logs.len(), 1);
});
logs_contain(
"Comparing two markers with each other doesn't make any sense, will evaluate to false",
);
}

#[test]
#[cfg(feature = "tracing")]
#[tracing_test::traced_test]
fn warnings2() {
let env37 = env37();
let non_pep440 = MarkerTree::from_str("python_version >= '3.9.'").unwrap();
non_pep440.evaluate(&env37, &[]);
testing_logger::validate(|captured_logs| {
assert_eq!(
captured_logs[0].body,
"Expected PEP 440 version to compare with python_version, found `3.9.`, \
will evaluate to false: after parsing `3.9`, found `.`, which is \
not part of a valid version"
);
assert_eq!(captured_logs[0].level, log::Level::Warn);
assert_eq!(captured_logs.len(), 1);
});
logs_contain(
"Expected PEP 440 version to compare with python_version, found `3.9.`, \
will evaluate to false: after parsing `3.9`, found `.`, which is \
not part of a valid version",
);
}

#[test]
#[cfg(feature = "tracing")]
#[tracing_test::traced_test]
fn warnings3() {
let env37 = env37();
let string_string = MarkerTree::from_str("'b' >= 'a'").unwrap();
string_string.evaluate(&env37, &[]);
testing_logger::validate(|captured_logs| {
assert_eq!(
captured_logs[0].body,
"Comparing two quoted strings with each other doesn't make sense: 'b' >= 'a', will evaluate to false"
);
assert_eq!(captured_logs[0].level, log::Level::Warn);
assert_eq!(captured_logs.len(), 1);
});
logs_contain(
"Comparing two quoted strings with each other doesn't make sense: 'b' >= 'a', will evaluate to false"
);
}

#[test]
#[cfg(feature = "tracing")]
#[tracing_test::traced_test]
fn warnings4() {
let env37 = env37();
let string_string = MarkerTree::from_str(r"os.name == 'posix' and platform.machine == 'x86_64' and platform.python_implementation == 'CPython' and 'Ubuntu' in platform.version and sys.platform == 'linux'").unwrap();
string_string.evaluate(&env37, &[]);
testing_logger::validate(|captured_logs| {
let messages: Vec<_> = captured_logs
logs_assert(|lines: &[&str]| {
let lines: Vec<_> = lines
.iter()
.map(|message| {
assert_eq!(message.level, log::Level::Warn);
&message.body
})
.map(|s| s.split_once(" ").unwrap().1)
.collect();
let expected = [
"os.name is deprecated in favor of os_name",
"platform.machine is deprecated in favor of platform_machine",
"platform.python_implementation is deprecated in favor of platform_python_implementation",
"platform.version is deprecated in favor of platform_version",
"sys.platform is deprecated in favor of sys_platform"
let expected = [
"WARN warnings4: uv_pep508: os.name is deprecated in favor of os_name",
"WARN warnings4: uv_pep508: platform.machine is deprecated in favor of platform_machine",
"WARN warnings4: uv_pep508: platform.python_implementation is deprecated in favor of",
"WARN warnings4: uv_pep508: sys.platform is deprecated in favor of sys_platform",
"WARN warnings4: uv_pep508: Comparing linux and posix lexicographically"
];
assert_eq!(messages, &expected);
if lines == expected {
Ok(())
} else {
Err(format!("{:?}", lines))
}
});
}

Expand Down

0 comments on commit 7a3dbbe

Please sign in to comment.