Skip to content

Commit

Permalink
Ensure that the struct holding enum case is tested
Browse files Browse the repository at this point in the history
  • Loading branch information
ricohageman committed Mar 27, 2023
1 parent 42b0a4e commit 82353cc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,37 @@ fn test_enum_compare_by_identity() {
})
}

#[pyclass]
struct MyEnumHoldingStruct {
#[pyo3(get)]
my_enum: MyEnum,
}

#[pymethods]
impl MyEnumHoldingStruct {
#[new]
fn new() -> Self {
Self {
my_enum: MyEnum::Variant,
}
}
}

#[test]
fn test_struct_holding_enum_compare_enum_by_identity() {
Python::with_gil(|py| {
#[allow(non_snake_case)]
let MyEnum = py.get_type::<MyEnum>();
#[allow(non_snake_case)]
let MyEnumHoldingStruct = py.get_type::<MyEnumHoldingStruct>();
py_run!(py, MyEnumHoldingStruct MyEnum, r#"
my_enum_holding_struct = MyEnumHoldingStruct()
assert my_enum_holding_struct.my_enum is MyEnum.Variant
assert my_enum_holding_struct.my_enum is not MyEnum.OtherVariant
"#);
})
}

#[pyclass]
enum CustomDiscriminant {
One = 1,
Expand Down

0 comments on commit 82353cc

Please sign in to comment.