Skip to content

Commit

Permalink
property rename via macro
Browse files Browse the repository at this point in the history
  • Loading branch information
gilescope authored and davidhewitt committed Jun 24, 2021
1 parent 2688e26 commit 08802e2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ macro_rules! fn_macro {

fn_macro!("(a, b=None, *, c=42)", a, b = "None", c = 42);

macro_rules! property_rename_via_macro {
($prop_name:ident) => {
#[pyclass]
struct ClassWithProperty {
member: u64,
}

#[pymethods]
impl ClassWithProperty {
#[getter($prop_name)]
fn get_member(&self) -> u64 {
self.member
}

#[setter($prop_name)]
fn set_member(&mut self, member: u64) {
self.member = member;
}
}
};
}

property_rename_via_macro!(my_new_property_name);

#[test]
fn test_macro_rules_interactions() {
Python::with_gil(|py| {
Expand All @@ -56,5 +80,12 @@ fn test_macro_rules_interactions() {
my_func,
"my_func.__text_signature__ == '(a, b=None, *, c=42)'"
);

let renamed_prop = py.get_type::<ClassWithProperty>();
py_assert!(
py,
renamed_prop,
"hasattr(renamed_prop, 'my_new_property_name')"
);
});
}

0 comments on commit 08802e2

Please sign in to comment.