From 08802e20242d49fdc5fc25e85bb8108414170863 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Mon, 13 Apr 2020 07:12:04 +0100 Subject: [PATCH] property rename via macro --- tests/test_macros.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_macros.rs b/tests/test_macros.rs index 093aa8e3d55..46c31b4c980 100644 --- a/tests/test_macros.rs +++ b/tests/test_macros.rs @@ -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| { @@ -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::(); + py_assert!( + py, + renamed_prop, + "hasattr(renamed_prop, 'my_new_property_name')" + ); }); }