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

Function context_manager

tests/test_class.rs:1198–1218  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1196
1197#[test]
1198fn context_manager() {
1199 let gil = Python::acquire_gil();
1200 let py = gil.python();
1201
1202 let c = ContextManager::create_instance(py, Cell::new(false)).unwrap();
1203 py_run!(py, c, "with c as x:\n assert x == 42");
1204 assert!(c.exit_called(py).get());
1205
1206 c.exit_called(py).set(false);
1207 py_run!(py, c, "with c as x:\n raise ValueError");
1208 assert!(c.exit_called(py).get());
1209
1210 c.exit_called(py).set(false);
1211 py_expect_exception!(
1212 py,
1213 c,
1214 "with c as x:\n raise NotImplementedError",
1215 NotImplementedError
1216 );
1217 assert!(c.exit_called(py).get());
1218}
1219
1220py_class!(class Properties |py| {
1221 data value: Cell<i32>;

Callers

nothing calls this directly

Calls 1

pythonMethod · 0.80

Tested by

no test coverage detected