| 1196 | |
| 1197 | #[test] |
| 1198 | fn 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 | |
| 1220 | py_class!(class Properties |py| { |
| 1221 | data value: Cell<i32>; |