MCPcopy Index your code
hub / github.com/dgrunwald/rust-cpython / test_eval

Function test_eval

src/python.rs:371–401  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

369
370 #[test]
371 fn test_eval() {
372 let gil = Python::acquire_gil();
373 let py = gil.python();
374
375 // Make sure builtin names are accessible
376 let v: i32 = py
377 .eval("min(1, 2)", None, None)
378 .unwrap()
379 .extract(py)
380 .unwrap();
381 assert_eq!(v, 1);
382
383 let d = PyDict::new(py);
384 d.set_item(py, "foo", 13).unwrap();
385
386 // Inject our own local namespace
387 let v: i32 = py
388 .eval("foo + 29", None, Some(&d))
389 .unwrap()
390 .extract(py)
391 .unwrap();
392 assert_eq!(v, 42);
393
394 // Make sure builtin names are still accessible when using a local namespace
395 let v: i32 = py
396 .eval("min(foo, 2)", None, Some(&d))
397 .unwrap()
398 .extract(py)
399 .unwrap();
400 assert_eq!(v, 2);
401 }
402}

Callers

nothing calls this directly

Calls 4

pythonMethod · 0.80
evalMethod · 0.80
extractMethod · 0.45
set_itemMethod · 0.45

Tested by

no test coverage detected