Address clippy::float_cmp issues

This commit is contained in:
Samuele Maci 2019-08-17 14:10:36 +02:00
parent f008c569a6
commit 6b4a221d61
4 changed files with 14 additions and 5 deletions

View File

@ -706,6 +706,7 @@ mod test {
assert_eq!(buffer.to_vec::<u8>(py).unwrap(), b"abcde"); assert_eq!(buffer.to_vec::<u8>(py).unwrap(), b"abcde");
} }
#[allow(clippy::float_cmp)] // The test wants to ensure that no precision was lost on the Python round-trip
#[test] #[test]
fn test_array_buffer() { fn test_array_buffer() {
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();

View File

@ -196,6 +196,7 @@ mod complex_conversion {
complex_conversion!(f32); complex_conversion!(f32);
complex_conversion!(f64); complex_conversion!(f64);
#[allow(clippy::float_cmp)] // The test wants to ensure that no precision was lost on the Python round-trip
#[test] #[test]
fn from_complex() { fn from_complex() {
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
@ -230,11 +231,13 @@ mod test {
#[test] #[test]
fn test_from_double() { fn test_from_double() {
use assert_approx_eq::assert_approx_eq;
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
let complex = PyComplex::from_doubles(py, 3.0, 1.2); let complex = PyComplex::from_doubles(py, 3.0, 1.2);
assert_eq!(complex.real(), 3.0); assert_approx_eq!(complex.real(), 3.0);
assert_eq!(complex.imag(), 1.2); assert_approx_eq!(complex.imag(), 1.2);
} }
#[cfg(not(Py_LIMITED_API))] #[cfg(not(Py_LIMITED_API))]

View File

@ -91,11 +91,13 @@ mod test {
($func_name:ident, $t1:ty, $t2:ty) => ( ($func_name:ident, $t1:ty, $t2:ty) => (
#[test] #[test]
fn $func_name() { fn $func_name() {
use assert_approx_eq::assert_approx_eq;
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
let val = 123 as $t1; let val = 123 as $t1;
let obj = val.to_object(py); let obj = val.to_object(py);
assert_eq!(obj.extract::<$t2>(py).unwrap(), val as $t2); assert_approx_eq!(obj.extract::<$t2>(py).unwrap(), val as $t2);
} }
) )
); );
@ -106,10 +108,12 @@ mod test {
#[test] #[test]
fn test_as_double_macro() { fn test_as_double_macro() {
use assert_approx_eq::assert_approx_eq;
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
let v = 1.23f64; let v = 1.23f64;
let obj = v.to_object(py); let obj = v.to_object(py);
assert_eq!(v, unsafe { PyFloat_AS_DOUBLE(obj.as_ptr()) }); assert_approx_eq!(v, unsafe { PyFloat_AS_DOUBLE(obj.as_ptr()) });
} }
} }

View File

@ -102,6 +102,7 @@ fn test_delta_check() {
#[test] #[test]
fn test_datetime_utc() { fn test_datetime_utc() {
use assert_approx_eq::assert_approx_eq;
use pyo3::types::PyDateTime; use pyo3::types::PyDateTime;
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
@ -120,7 +121,7 @@ fn test_datetime_utc() {
.unwrap() .unwrap()
.extract() .extract()
.unwrap(); .unwrap();
assert_eq!(offset, 0f32); assert_approx_eq!(offset, 0f32);
} }
#[cfg(Py_3_6)] #[cfg(Py_3_6)]