Skip to content

Commit

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

#[test]
#[cfg(all(Py_3_9, feature = "chrono-tz", not(windows)))]
fn test_pyo3_datetime_into_pyobject_tz() {
let datetime = NaiveDate::from_ymd_opt(2024, 12, 11)
.unwrap()
.and_hms_opt(23, 03, 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,
03,
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 +1414,16 @@ mod tests {
.unwrap()
}

#[cfg(Py_3_9)]
fn python_zoneinfo(py: Python<'_>, timezone: &str) -> Bound<'_, 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 c200fb1

Please sign in to comment.