()
| 88 | |
| 89 | #[test] |
| 90 | fn test_get_buffer_errors() { |
| 91 | Python::attach(|py| { |
| 92 | let instance = Py::new( |
| 93 | py, |
| 94 | TestBufferErrors { |
| 95 | buf: vec![0, 1, 2, 3], |
| 96 | error: None, |
| 97 | }, |
| 98 | ) |
| 99 | .unwrap(); |
| 100 | |
| 101 | assert!(PyBuffer::<u32>::get(instance.bind(py)).is_ok()); |
| 102 | |
| 103 | instance.borrow_mut(py).error = Some(TestGetBufferError::NullShape); |
| 104 | assert_eq!( |
| 105 | PyBuffer::<u32>::get(instance.bind(py)) |
| 106 | .unwrap_err() |
| 107 | .to_string(), |
| 108 | "BufferError: shape is null" |
| 109 | ); |
| 110 | |
| 111 | instance.borrow_mut(py).error = Some(TestGetBufferError::NullStrides); |
| 112 | assert_eq!( |
| 113 | PyBuffer::<u32>::get(instance.bind(py)) |
| 114 | .unwrap_err() |
| 115 | .to_string(), |
| 116 | "BufferError: strides is null" |
| 117 | ); |
| 118 | |
| 119 | instance.borrow_mut(py).error = Some(TestGetBufferError::IncorrectItemSize); |
| 120 | assert_eq!( |
| 121 | PyBuffer::<u32>::get(instance.bind(py)) |
| 122 | .unwrap_err() |
| 123 | .to_string(), |
| 124 | "BufferError: buffer contents are not compatible with u32" |
| 125 | ); |
| 126 | |
| 127 | instance.borrow_mut(py).error = Some(TestGetBufferError::IncorrectFormat); |
| 128 | assert_eq!( |
| 129 | PyBuffer::<u32>::get(instance.bind(py)) |
| 130 | .unwrap_err() |
| 131 | .to_string(), |
| 132 | "BufferError: buffer contents are not compatible with u32" |
| 133 | ); |
| 134 | |
| 135 | instance.borrow_mut(py).error = Some(TestGetBufferError::IncorrectAlignment); |
| 136 | assert_eq!( |
| 137 | PyBuffer::<u32>::get(instance.bind(py)) |
| 138 | .unwrap_err() |
| 139 | .to_string(), |
| 140 | "BufferError: buffer contents are insufficiently aligned for u32" |
| 141 | ); |
| 142 | }); |
| 143 | } |
nothing calls this directly
no test coverage detected