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

Function test_module_from_code_bound

tests/test_module.rs:246–268  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

244
245#[test]
246fn test_module_from_code_bound() {
247 Python::attach(|py| {
248 let adder_mod = PyModule::from_code(
249 py,
250 c"def add(a,b):\n\treturn a+b",
251 c"adder_mod.py",
252 &test_utils::generate_unique_module_name("adder_mod"),
253 )
254 .expect("Module code should be loaded");
255
256 let add_func = adder_mod
257 .getattr("add")
258 .expect("Add function should be in the module");
259
260 let ret_value: i32 = add_func
261 .call1((1, 2))
262 .expect("A value should be returned")
263 .extract()
264 .expect("The value should be able to be converted to an i32");
265
266 assert_eq!(ret_value, 3);
267 });
268}
269
270#[pyfunction]
271fn r#move() -> usize {

Callers

nothing calls this directly

Calls 4

getattrMethod · 0.45
extractMethod · 0.45
call1Method · 0.45

Tested by

no test coverage detected