Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Feb 18, 2024
1 parent 52ea1de commit 00d8f58
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ jobs:
with:
command: build
- name: Install pep440_rs
run: pip install --no-index --find-links target/wheels pep440_rs
run: pip install --no-index --find-links target/wheels pep508_rs
- run: pytest
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ rkyv = { version = "0.7.44", features = ["strict"], optional = true }
serde = { version = "1.0.196", features = ["derive"], optional = true }
serde_json = { version = "1.0.113", optional = true }
thiserror = "1.0.57"
tracing = { version = "0.1.40", features = ["log"] }
tracing = { version = "0.1.40", optional = true }
unicode-width = "0.1.11"
url = { version = "2.5.0", features = ["serde"] }
url = { version = "2.5.0" }
urlencoding = "2.1.3"

[dev-dependencies]
Expand All @@ -36,9 +36,10 @@ serde_json = "1.0.113"
testing_logger = "0.1.1"

[features]
pyo3 = ["dep:pyo3", "pep440_rs/pyo3", "pyo3-log"]
pyo3 = ["dep:pyo3", "pep440_rs/pyo3", "pyo3-log", "tracing", "tracing/log"]
rkyv = ["dep:rkyv", "pep440_rs/rkyv"]
serde = ["dep:serde", "pep440_rs/serde"]
serde = ["dep:serde", "pep440_rs/serde", "url/serde"]
tracing = ["dep:tracing", "pep440_rs/tracing"]
# PEP 508 allows only URLs such as `foo @ https://example.org/foo` or `foo @ file:///home/ferris/foo`, and
# arguably does not allow relative paths in file URLs (`foo @ file://./foo`,
# `foo @ file:foo-3.0.0-py3-none-any.whl`, `foo @ file://foo-3.0.0-py3-none-any.whl`), as they are not part of the
Expand Down
17 changes: 9 additions & 8 deletions src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::collections::HashSet;
use std::fmt::{Display, Formatter};
use std::ops::Deref;
use std::str::FromStr;
use tracing::warn;

/// Ways in which marker evaluation can fail
#[derive(Debug, Eq, Hash, Ord, PartialOrd, PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -942,8 +941,10 @@ impl FromStr for MarkerTree {
impl MarkerTree {
/// Does this marker apply in the given environment?
pub fn evaluate(&self, env: &MarkerEnvironment, extras: &[ExtraName]) -> bool {
let mut reporter = |_kind, message, _marker_expression: &MarkerExpression| {
warn!("{}", message);
let mut reporter = |_kind, _message, _marker_expression: &MarkerExpression| {
#[cfg(feature = "tracing")] {
tracing::warn!("{}", _message);
}
};
self.report_deprecated_options(&mut reporter);
match self {
Expand Down Expand Up @@ -1345,7 +1346,6 @@ mod test {
use crate::marker::{MarkerEnvironment, StringVersion};
use crate::{MarkerExpression, MarkerOperator, MarkerTree, MarkerValue, MarkerValueString};
use indoc::indoc;
use log::Level;
use std::str::FromStr;

fn assert_err(input: &str, error: &str) {
Expand Down Expand Up @@ -1441,6 +1441,7 @@ mod test {
}

#[test]
#[cfg(feature = "tracing")]
fn warnings() {
let env37 = env37();
testing_logger::setup();
Expand All @@ -1451,7 +1452,7 @@ mod test {
captured_logs[0].body,
"Comparing two markers with each other doesn't make any sense, evaluating to false"
);
assert_eq!(captured_logs[0].level, Level::Warn);
assert_eq!(captured_logs[0].level, log::Level::Warn);
assert_eq!(captured_logs.len(), 1);
});
let non_pep440 = MarkerTree::from_str("python_version >= '3.9.'").unwrap();
Expand All @@ -1463,7 +1464,7 @@ mod test {
evaluating to false: after parsing 3.9, found \".\" after it, \
which is not part of a valid version"
);
assert_eq!(captured_logs[0].level, Level::Warn);
assert_eq!(captured_logs[0].level, log::Level::Warn);
assert_eq!(captured_logs.len(), 1);
});
let string_string = MarkerTree::from_str("'b' >= 'a'").unwrap();
Expand All @@ -1473,7 +1474,7 @@ mod test {
captured_logs[0].body,
"Comparing two quoted strings with each other doesn't make sense: 'b' >= 'a', evaluating to false"
);
assert_eq!(captured_logs[0].level, Level::Warn);
assert_eq!(captured_logs[0].level, log::Level::Warn);
assert_eq!(captured_logs.len(), 1);
});
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();
Expand All @@ -1482,7 +1483,7 @@ mod test {
let messages: Vec<_> = captured_logs
.iter()
.map(|message| {
assert_eq!(message.level, Level::Warn);
assert_eq!(message.level, log::Level::Warn);
&message.body
})
.collect();
Expand Down
9 changes: 5 additions & 4 deletions test/test_pep508.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ def test_warnings(caplog):
Requirement("numpy; python_version >= '3.9.'").evaluate_markers(env, [])
assert caplog.messages == [
"Expected PEP 440 version to compare with python_version, found '3.9.', "
"evaluating to false: Version `3.9.` doesn't match PEP 440 rules"
'evaluating to false: after parsing 3.9, found "." after it, which is not '
"part of a valid version",
]
caplog.clear()
# pickleshare 0.7.5
Requirement("numpy; python_version in '2.6 2.7 3.2 3.3'").evaluate_markers(env, [])
assert caplog.messages == [
"Expected PEP 440 version to compare with python_version, "
"found '2.6 2.7 3.2 3.3', "
"evaluating to false: Version `2.6 2.7 3.2 3.3` doesn't match PEP 440 rules"
"Expected PEP 440 version to compare with python_version, found '2.6 2.7 "
'3.2 3.3\', evaluating to false: after parsing 2.6, found "2.7 3.2 3.3" '
"after it, which is not part of a valid version",
]

0 comments on commit 00d8f58

Please sign in to comment.