Add test cases for new TryFrom
impls
This commit is contained in:
parent
d4ed66fff0
commit
f4e64aadef
|
@ -43,8 +43,8 @@ impl BytesExtractor {
|
|||
|
||||
#[pyfunction]
|
||||
fn return_memoryview(py: Python<'_>) -> PyResult<&PyMemoryView> {
|
||||
let bytes = PyBytes::new(py, b"hello world");
|
||||
let memoryview = PyMemoryView::from(bytes)?;
|
||||
let bytes: &PyAny = PyBytes::new(py, b"hello world").into();
|
||||
let memoryview = TryInto::try_into(bytes)?;
|
||||
Ok(memoryview)
|
||||
}
|
||||
|
||||
|
|
|
@ -253,8 +253,8 @@ impl<'py> TryFrom<&'py PyAny> for &'py PyByteArray {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::exceptions;
|
||||
use crate::types::PyByteArray;
|
||||
use crate::{exceptions, PyAny};
|
||||
use crate::{PyObject, Python};
|
||||
|
||||
#[test]
|
||||
|
@ -332,6 +332,17 @@ mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_from() {
|
||||
Python::with_gil(|py| {
|
||||
let src = b"Hello Python";
|
||||
let bytearray: &PyAny = PyByteArray::new(py, src).into();
|
||||
let bytearray: &PyByteArray = TryInto::try_into(bytearray).unwrap();
|
||||
|
||||
assert_eq!(src, unsafe { bytearray.as_bytes() });
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_resize() {
|
||||
Python::with_gil(|py| {
|
||||
|
|
Loading…
Reference in a new issue