Skip to content

Commit 0b3a83e

Browse files
committed
Recover lost coverage.
1 parent 53df004 commit 0b3a83e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

tests/array.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ fn to_owned_works() {
461461

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

@@ -470,3 +470,22 @@ fn copy_to_works() {
470470
assert_eq!(arr2.readonly().as_slice().unwrap(), &[2, 3, 4]);
471471
});
472472
}
473+
474+
#[test]
475+
fn get_works() {
476+
Python::with_gil(|py| {
477+
let array = pyarray![py, [[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]];
478+
479+
unsafe {
480+
assert_eq!(array.get([0, 0, 0]), Some(&1));
481+
assert_eq!(array.get([2, 1, 1]), Some(&12));
482+
assert_eq!(array.get([0, 0, 2]), None);
483+
assert_eq!(array.get([0, 2, 0]), None);
484+
assert_eq!(array.get([3, 0, 0]), None);
485+
486+
assert_eq!(*array.uget([1, 0, 0]), 5);
487+
assert_eq!(*array.uget_mut([0, 1, 0]), 3);
488+
assert_eq!(*array.uget_raw([0, 0, 1]), 2);
489+
}
490+
});
491+
}

tests/to_py.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ fn to_pyarray_vec() {
1919
});
2020
}
2121

22+
#[test]
23+
fn to_pyarray_boxed_slice() {
24+
Python::with_gil(|py| {
25+
let arr = vec![1, 2, 3].into_boxed_slice().to_pyarray(py);
26+
27+
assert_eq!(arr.shape(), [3]);
28+
assert_eq!(arr.readonly().as_slice().unwrap(), &[1, 2, 3])
29+
});
30+
}
31+
2232
#[test]
2333
fn to_pyarray_array() {
2434
Python::with_gil(|py| {
@@ -31,7 +41,7 @@ fn to_pyarray_array() {
3141
.map(|dim| dim * size_of::<f64>() as isize)
3242
.collect::<Vec<_>>();
3343

34-
let py_arr = arr.to_pyarray(py);
44+
let py_arr = PyArray::from_array(py, &arr);
3545

3646
assert_eq!(py_arr.shape(), shape.as_slice());
3747
assert_eq!(py_arr.strides(), strides.as_slice());
@@ -118,6 +128,15 @@ fn into_pyarray_vec() {
118128
});
119129
}
120130

131+
#[test]
132+
fn into_pyarray_boxed_slice() {
133+
Python::with_gil(|py| {
134+
let arr = vec![1, 2, 3].into_boxed_slice().into_pyarray(py);
135+
136+
assert_eq!(arr.readonly().as_slice().unwrap(), &[1, 2, 3])
137+
});
138+
}
139+
121140
#[test]
122141
fn into_pyarray_array() {
123142
Python::with_gil(|py| {

0 commit comments

Comments
 (0)