Skip to content

Commit

Permalink
Add testcase for unsendable, dict, weakref pyclass.
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu authored and sebpuetz committed Jul 21, 2020
1 parent 43d1f43 commit 4563e00
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_unsendable_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,27 @@ fn test_unsendable_dict() {
let inst = Py::new(py, UnsendableDictClass {}).unwrap();
py_run!(py, inst, "assert inst.__dict__ == {}");
}

#[pyclass(dict, unsendable, weakref)]
struct UnsendableDictClassWithWeakRef {}

#[pymethods]
impl UnsendableDictClassWithWeakRef {
#[new]
fn new() -> Self {
Self {}
}
}

#[test]
fn test_unsendable_dict_with_weakref() {
let gil = Python::acquire_gil();
let py = gil.python();
let inst = Py::new(py, UnsendableDictClassWithWeakRef {}).unwrap();
py_run!(py, inst, "assert inst.__dict__ == {}");
py_run!(
py,
inst,
"import weakref; assert weakref.ref(inst)() is inst; inst.a = 1; assert inst.a == 1"
);
}

0 comments on commit 4563e00

Please sign in to comment.