Skip to content

Commit

Permalink
add test with failing conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-konovalenko committed Feb 14, 2021
1 parent 29c42f8 commit 4cc06f2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/test_pyfunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn test_functions_with_function_args() {

#[cfg(not(Py_LIMITED_API))]
fn datetime_to_timestamp(dt: &PyAny) -> PyResult<i64> {
let dt: &PyDateTime = dt.extract()?;
let dt: &PyDateTime = dt.extract();
let ts: f64 = dt.call_method0("timestamp")?.extract()?;

Ok(ts as i64)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4cc06f2

Please sign in to comment.