Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bschoenmaeckers committed Dec 12, 2024
1 parent 1456bc1 commit 12ba32e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/conversions/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,35 @@ mod tests {
})
}

#[test]
#[cfg(all(Py_3_9, feature = "chrono-tz", not(windows)))]
fn test_pyo3_datetime_into_pyobject_tz() {
Python::with_gil(|py| {
let datetime = NaiveDate::from_ymd_opt(2024, 12, 11)
.unwrap()
.and_hms_opt(23, 3, 13)
.unwrap()
.and_local_timezone(chrono_tz::Tz::Europe__London)
.unwrap();
let datetime = datetime.into_pyobject(py).unwrap();
let py_datetime = new_py_datetime_ob(
py,
"datetime",
(
2024,
12,
11,
23,
3,
13,
0,
python_zoneinfo(py, "Europe/London"),
),
);
assert_eq!(datetime.compare(&py_datetime).unwrap(), Ordering::Equal);
})
}

#[test]
fn test_pyo3_datetime_frompyobject_utc() {
Python::with_gil(|py| {
Expand Down Expand Up @@ -1387,6 +1416,16 @@ mod tests {
.unwrap()
}

#[cfg(Py_3_9)]
fn python_zoneinfo<'py>(py: Python<'py>, timezone: &str) -> Bound<'py, PyAny> {
py.import("zoneinfo")
.unwrap()
.getattr("ZoneInfo")
.unwrap()
.call1((timezone,))
.unwrap()
}

#[cfg(not(any(target_arch = "wasm32", Py_GIL_DISABLED)))]
mod proptests {
use super::*;
Expand Down

0 comments on commit 12ba32e

Please sign in to comment.