Skip to content

Commit 57df0bc

Browse files
committed
Use #[cfg(test)]
1 parent f81df0a commit 57df0bc

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

src/array.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,20 +1074,25 @@ impl<T: Element + AsPrimitive<f64>> PyArray<T, Ix1> {
10741074
}
10751075
}
10761076

1077-
#[test]
1078-
fn test_get_unchecked() {
1079-
pyo3::Python::with_gil(|py| {
1080-
let array = PyArray::from_slice(py, &[1i32, 2, 3]);
1081-
unsafe {
1082-
assert_eq!(*array.uget([1]), 2);
1083-
}
1084-
})
1085-
}
1077+
#[cfg(test)]
1078+
mod tests {
1079+
use super::PyArray;
1080+
1081+
#[test]
1082+
fn test_get_unchecked() {
1083+
pyo3::Python::with_gil(|py| {
1084+
let array = PyArray::from_slice(py, &[1i32, 2, 3]);
1085+
unsafe {
1086+
assert_eq!(*array.uget([1]), 2);
1087+
}
1088+
})
1089+
}
10861090

1087-
#[test]
1088-
fn test_dyn_to_owned_array() {
1089-
pyo3::Python::with_gil(|py| {
1090-
let array = PyArray::from_vec2(py, &[vec![1, 2], vec![3, 4]]).unwrap();
1091-
array.to_dyn().to_owned_array();
1092-
})
1091+
#[test]
1092+
fn test_dyn_to_owned_array() {
1093+
pyo3::Python::with_gil(|py| {
1094+
let array = PyArray::from_vec2(py, &[vec![1, 2], vec![3, 4]]).unwrap();
1095+
array.to_dyn().to_owned_array();
1096+
})
1097+
}
10931098
}

src/npyffi/array.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,17 @@ pub unsafe fn PyArray_CheckExact(op: *mut PyObject) -> c_int {
386386
(ffi::Py_TYPE(op) == PY_ARRAY_API.get_type_object(NpyTypes::PyArray_Type)) as _
387387
}
388388

389-
#[test]
390-
fn call_api() {
391-
pyo3::Python::with_gil(|_py| unsafe {
392-
assert_eq!(
393-
PY_ARRAY_API.PyArray_MultiplyIntList([1, 2, 3].as_mut_ptr(), 3),
394-
6
395-
);
396-
})
389+
#[cfg(test)]
390+
mod tests {
391+
use super::PY_ARRAY_API;
392+
393+
#[test]
394+
fn call_api() {
395+
pyo3::Python::with_gil(|_py| unsafe {
396+
assert_eq!(
397+
PY_ARRAY_API.PyArray_MultiplyIntList([1, 2, 3].as_mut_ptr(), 3),
398+
6
399+
);
400+
})
401+
}
397402
}

0 commit comments

Comments
 (0)