MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / one_arg

Function one_arg

tests/test_function.rs:50–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48
49#[test]
50fn one_arg() {
51 fn f(_py: Python, i: usize) -> PyResult<usize> {
52 Ok(i * 2)
53 }
54
55 let gil = Python::acquire_gil();
56 let py = gil.python();
57 let obj = py_fn!(py, f(i: usize));
58
59 assert!(obj.call(py, NoArgs, None).is_err());
60 assert_eq!(
61 obj.call(py, (1,), None)
62 .unwrap()
63 .extract::<i32>(py)
64 .unwrap(),
65 2
66 );
67 assert!(obj.call(py, (1, 2), None).is_err());
68
69 let dict = PyDict::new(py);
70 dict.set_item(py, "i", 42).unwrap();
71 assert_eq!(
72 obj.call(py, NoArgs, Some(&dict))
73 .unwrap()
74 .extract::<i32>(py)
75 .unwrap(),
76 84
77 );
78 assert!(obj.call(py, (1,), Some(&dict)).is_err());
79 dict.set_item(py, "j", 10).unwrap();
80 assert!(obj.call(py, NoArgs, Some(&dict)).is_err());
81}
82
83#[test]
84fn trailing_comma() {

Callers

nothing calls this directly

Calls 2

pythonMethod · 0.80
set_itemMethod · 0.45

Tested by

no test coverage detected