Skip to content

Commit

Permalink
improve coverage of Py2 trait implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Oct 12, 2023
1 parent 3f6089f commit 454c923
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,8 @@ where
{
#[inline]
fn from(other: Py2<'_, T>) -> Self {
unsafe { Self::from_non_null(other.into_non_null()) }
let py = other.py();
other.into_py(py)
}
}

Expand Down Expand Up @@ -1335,7 +1336,7 @@ impl PyObject {

#[cfg(test)]
mod tests {
use super::{Py, PyObject};
use super::{Py, Py2, PyObject};
use crate::types::{PyDict, PyString};
use crate::{PyAny, PyResult, Python, ToPyObject};

Expand Down Expand Up @@ -1451,6 +1452,27 @@ a = A()
})
}

#[test]
fn test_py2_from_py_object() {
Python::with_gil(|py| {
let instance: &PyAny = py.eval("object()", None, None).unwrap();
let ptr = instance.as_ptr();
let instance: Py2<'_, PyAny> = instance.extract().unwrap();
assert_eq!(instance.as_ptr(), ptr);
})
}

#[test]
fn test_py2_into_py_object() {
Python::with_gil(|py| {
let instance: Py2<'_, PyAny> =
Py2::borrowed_from_gil_ref(&py.eval("object()", None, None).unwrap()).clone();
let ptr = instance.as_ptr();
let instance: PyObject = instance.clone().into();
assert_eq!(instance.as_ptr(), ptr);
})
}

#[test]
fn test_is_ellipsis() {
Python::with_gil(|py| {
Expand Down

0 comments on commit 454c923

Please sign in to comment.