Fix default handling in PEP 792 status markers (#17671)

This commit is contained in:
William Woodruff
2026-01-23 12:48:52 -05:00
committed by GitHub
parent 6e3ba2f03d
commit 73410fad33
@@ -54,7 +54,9 @@ impl<'de> Deserialize<'de> for Status {
#[derive(Clone, Debug, Default, Deserialize, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
#[rkyv(derive(Debug))]
pub struct ProjectStatus {
#[serde(default)]
pub status: Status,
#[serde(default)]
pub reason: Option<SmallString>,
}
@@ -75,6 +77,31 @@ mod tests {
assert_eq!(Status::new("acTiVe"), None);
}
/// An empty project status should default to Active with no reason.
#[test]
fn test_deserialize_empty() {
let json = "{}";
let project_status: ProjectStatus = serde_json::from_str(json).unwrap();
assert_eq!(project_status.status, Status::Active);
assert_eq!(project_status.reason, None);
}
/// A project status with explicitly null reason should default to Active with no reason.
#[test]
fn test_deserialize_null() {
let json = r#"
{
"reason": null
}
"#;
let project_status: ProjectStatus = serde_json::from_str(json).unwrap();
assert_eq!(project_status.status, Status::Active);
assert_eq!(project_status.reason, None);
}
/// A project status with known status and reason.
#[test]
fn test_deserialize() {
let json = r#"
@@ -92,6 +119,7 @@ mod tests {
);
}
/// A project status with an unknown status should default to Active.
#[test]
fn test_deserialize_unknown_status() {
let json = r#"