MCPcopy Create free account
hub / github.com/PyO3/pyo3 / use_pyfunction

Function use_pyfunction

tests/test_pyfunction.rs:582–605  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

580
581#[test]
582fn use_pyfunction() {
583 mod function_in_module {
584 use pyo3::prelude::*;
585
586 #[pyfunction]
587 pub fn foo(x: i32) -> i32 {
588 x
589 }
590 }
591
592 Python::attach(|py| {
593 use function_in_module::foo;
594
595 // check imported name can be wrapped
596 let f = wrap_pyfunction!(foo, py).unwrap();
597 assert_eq!(f.call1((5,)).unwrap().extract::<i32>().unwrap(), 5);
598 assert_eq!(f.call1((42,)).unwrap().extract::<i32>().unwrap(), 42);
599
600 // check path import can be wrapped
601 let f2 = wrap_pyfunction!(function_in_module::foo, py).unwrap();
602 assert_eq!(f2.call1((5,)).unwrap().extract::<i32>().unwrap(), 5);
603 assert_eq!(f2.call1((42,)).unwrap().extract::<i32>().unwrap(), 42);
604 })
605}
606
607#[pyclass]
608struct Key(String);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected