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

Function opt_args

tests/test_function.rs:129–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127
128#[test]
129fn opt_args() {
130 let gil = Python::acquire_gil();
131 let py = gil.python();
132 let obj = py_fn!(py, f(a: Option<&str>, b: &str, c: Option<&str> = None) -> PyResult<String> {
133 drop(py);
134 Ok(format!("a: {:?} b: {:?} c: {:?}", a, b, c))
135 });
136
137 assert_eq!(
138 obj.call(py, (PyNone, "string"), None)
139 .unwrap()
140 .extract::<String>(py)
141 .unwrap(),
142 r#"a: None b: "string" c: None"#,
143 );
144 assert_eq!(
145 obj.call(py, ("double", "string", PyNone), None)
146 .unwrap()
147 .extract::<String>(py)
148 .unwrap(),
149 r#"a: Some("double") b: "string" c: None"#,
150 );
151 assert_eq!(
152 obj.call(py, ("triple", "string", "args"), None)
153 .unwrap()
154 .extract::<String>(py)
155 .unwrap(),
156 r#"a: Some("triple") b: "string" c: Some("args")"#,
157 );
158}
159
160#[test]
161fn none_return() {

Callers

nothing calls this directly

Calls 1

pythonMethod · 0.80

Tested by

no test coverage detected