Skip to content

Commit

Permalink
Add test for too large major version
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Feb 8, 2025
1 parent 429f835 commit bd1f597
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions crates/red_knot_project/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,31 @@ expected `.`, `]`
Ok(())
}

#[test]
fn requires_python_too_large_major_version() -> anyhow::Result<()> {
let system = TestSystem::default();
let root = SystemPathBuf::from("/app");

system
.memory_file_system()
.write_file(
root.join("pyproject.toml"),
r#"
[project]
requires-python = ">=999.0"
"#,
)
.context("Failed to write file")?;

let Err(error) = ProjectMetadata::discover(&root, &system) else {
return Err(anyhow!("Expected project discovery to fail because of the requires-python major version that is larger than 255."));
};

assert_error_eq(&error, "the `requires-python` constraint in `/app/pyproject.toml` is invalid: The major version `999` is larger than the maximum supported value 255");

Ok(())
}

#[track_caller]
fn assert_error_eq(error: &ProjectDiscoveryError, message: &str) {
assert_eq!(error.to_string().replace('\\', "/"), message);
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_project/src/metadata/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Project {

tracing::debug!("Resolving requires-python constraint: `{requires_python}`");

let ranges = release_specifiers_to_ranges((&**requires_python).clone());
let ranges = release_specifiers_to_ranges((**requires_python).clone());
let Some((lower, _)) = ranges.bounding_range() else {
return Ok(None);
};
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_db/src/system.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use glob::PatternError;
pub use memory_fs::MemoryFileSystem;

#[cfg(all(feature = "testing", feature="os"))]
#[cfg(all(feature = "testing", feature = "os"))]
pub use os::testing::OsUserDirectoryOverride;

#[cfg(feature = "os")]
Expand Down

0 comments on commit bd1f597

Please sign in to comment.