From 4cc06f2850d172559fbd9b396df0036649ec9c9b Mon Sep 17 00:00:00 2001 From: Daniil Konovalenko Date: Thu, 11 Feb 2021 20:08:48 +0300 Subject: [PATCH] add test with failing conversion --- tests/test_pyfunction.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/test_pyfunction.rs b/tests/test_pyfunction.rs index 8a4cf1f4803..5602b037584 100644 --- a/tests/test_pyfunction.rs +++ b/tests/test_pyfunction.rs @@ -113,7 +113,7 @@ fn test_functions_with_function_args() { #[cfg(not(Py_LIMITED_API))] fn datetime_to_timestamp(dt: &PyAny) -> PyResult { - let dt: &PyDateTime = dt.extract()?; + let dt: &PyDateTime = dt.extract(); let ts: f64 = dt.call_method0("timestamp")?.extract()?; Ok(ts as i64) @@ -147,6 +147,23 @@ fn test_function_with_custom_conversion() { ) } +#[cfg(not(Py_LIMITED_API))] +#[test] +fn test_function_with_custom_conversion_error() { + let gil = Python::acquire_gil(); + let py = gil.python(); + + let custom_conv_func = wrap_pyfunction!(function_with_custom_conversion)(py).unwrap(); + + py_expect_exception!( + py, + custom_conv_func, + "custom_conv_func(['a'])", + PyTypeError, + "argument 'timestamp': 'list' object cannot be converted to 'PyDateTime'" + ); +} + #[test] fn test_raw_function() { let gil = Python::acquire_gil();