Skip to content

Commit

Permalink
Recover lost coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed Mar 17, 2022
1 parent 872a598 commit 4c89dee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ fn to_owned_works() {

#[test]
fn copy_to_works() {
pyo3::Python::with_gil(|py| {
Python::with_gil(|py| {
let arr1 = PyArray::arange(py, 2.0, 5.0, 1.0);
let arr2 = unsafe { PyArray::<i64, _>::new(py, [3], false) };

Expand All @@ -470,3 +470,22 @@ fn copy_to_works() {
assert_eq!(arr2.readonly().as_slice().unwrap(), &[2, 3, 4]);
});
}

#[test]
fn get_works() {
Python::with_gil(|py| {
let array = pyarray![py, [[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]];

unsafe {
assert_eq!(array.get([0, 0, 0]), Some(&1));
assert_eq!(array.get([2, 1, 1]), Some(&12));
assert_eq!(array.get([0, 0, 2]), None);
assert_eq!(array.get([0, 2, 0]), None);
assert_eq!(array.get([3, 0, 0]), None);

assert_eq!(*array.uget([1, 0, 0]), 5);
assert_eq!(*array.uget_mut([0, 1, 0]), 3);
assert_eq!(*array.uget_raw([0, 0, 1]), 2);
}
});
}
21 changes: 20 additions & 1 deletion tests/to_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ fn to_pyarray_vec() {
});
}

#[test]
fn to_pyarray_boxed_slice() {
Python::with_gil(|py| {
let arr = vec![1, 2, 3].into_boxed_slice().to_pyarray(py);

assert_eq!(arr.shape(), [3]);
assert_eq!(arr.readonly().as_slice().unwrap(), &[1, 2, 3])
});
}

#[test]
fn to_pyarray_array() {
Python::with_gil(|py| {
Expand All @@ -31,7 +41,7 @@ fn to_pyarray_array() {
.map(|dim| dim * size_of::<f64>() as isize)
.collect::<Vec<_>>();

let py_arr = arr.to_pyarray(py);
let py_arr = PyArray::from_array(py, &arr);

assert_eq!(py_arr.shape(), shape.as_slice());
assert_eq!(py_arr.strides(), strides.as_slice());
Expand Down Expand Up @@ -105,6 +115,15 @@ fn into_pyarray_vec() {
});
}

#[test]
fn into_pyarray_boxed_slice() {
Python::with_gil(|py| {
let arr = vec![1, 2, 3].into_boxed_slice().into_pyarray(py);

assert_eq!(arr.readonly().as_slice().unwrap(), &[1, 2, 3])
});
}

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

0 comments on commit 4c89dee

Please sign in to comment.