From 49d530c3bc4000d9630177596a07f8893f210e50 Mon Sep 17 00:00:00 2001 From: Heyuan Zeng Date: Tue, 23 Jul 2024 05:41:52 +0100 Subject: [PATCH] Fix user-defined warning testing in ABI3 --- src/tests/hygiene/pymethods.rs | 4 ++++ tests/test_methods.rs | 10 +++++++++- tests/test_pyfunction.rs | 10 +++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/tests/hygiene/pymethods.rs b/src/tests/hygiene/pymethods.rs index 358f96b03d4..2e22365836e 100644 --- a/src/tests/hygiene/pymethods.rs +++ b/src/tests/hygiene/pymethods.rs @@ -425,9 +425,11 @@ struct WarningDummy { value: i32, } +#[cfg(not(Py_LIMITED_API))] #[crate::pyclass(crate = "crate", extends=crate::exceptions::PyWarning)] pub struct UserDefinedWarning {} +#[cfg(not(Py_LIMITED_API))] #[crate::pymethods(crate = "crate")] impl UserDefinedWarning { #[new] @@ -454,6 +456,7 @@ impl WarningDummy { #[pyo3(warn(message = "this method raises warning", category = crate::exceptions::PyFutureWarning))] fn method_with_warning_and_custom_category(_slf: crate::PyRef<'_, Self>) {} + #[cfg(not(Py_LIMITED_API))] #[pyo3(warn(message = "this method raises user-defined warning", category = UserDefinedWarning))] fn method_with_warning_and_user_defined_category(&self) {} @@ -523,6 +526,7 @@ impl WarningDummy2 { #[pyo3(warn(message = "this class-method raises future warning", category = crate::exceptions::PyFutureWarning))] fn multiple_warnings_fn(&self) {} + #[cfg(not(Py_LIMITED_API))] #[pyo3(warn(message = "this class-method raises future warning", category = crate::exceptions::PyFutureWarning))] #[pyo3(warn(message = "this class-method raises user-defined warning", category = UserDefinedWarning))] fn multiple_warnings_fn_with_custom_category(&self) {} diff --git a/tests/test_methods.rs b/tests/test_methods.rs index 59745da205e..a9ac6ff4a0c 100644 --- a/tests/test_methods.rs +++ b/tests/test_methods.rs @@ -1,6 +1,8 @@ #![cfg(feature = "macros")] -use pyo3::exceptions::{PyDeprecationWarning, PyFutureWarning, PyUserWarning, PyWarning}; +#[cfg(not(Py_LIMITED_API))] +use pyo3::exceptions::PyWarning; +use pyo3::exceptions::{PyDeprecationWarning, PyFutureWarning, PyUserWarning}; use pyo3::prelude::*; use pyo3::py_run; use pyo3::types::PySequence; @@ -1164,9 +1166,11 @@ fn test_issue_2988() { } } +#[cfg(not(Py_LIMITED_API))] #[pyclass(extends=PyWarning)] pub struct UserDefinedWarning {} +#[cfg(not(Py_LIMITED_API))] #[pymethods] impl UserDefinedWarning { #[new] @@ -1200,6 +1204,7 @@ fn test_pymethods_warn() { #[pyo3(warn(message = "this method raises warning", category = PyFutureWarning))] fn method_with_warning_and_custom_category(_slf: PyRef<'_, Self>) {} + #[cfg(not(Py_LIMITED_API))] #[pyo3(warn(message = "this method raises user-defined warning", category = UserDefinedWarning))] fn method_with_warning_and_user_defined_category(&self) {} @@ -1262,6 +1267,7 @@ fn test_pymethods_warn() { ); // FnType::Fn, user-defined warning + #[cfg(not(Py_LIMITED_API))] py_expect_warning!( py, obj, @@ -1423,6 +1429,7 @@ fn test_py_methods_multiple_warn() { #[pyo3(deprecated = "this method is deprecated")] fn multiple_warn_deprecated_method(&self) {} + #[cfg(not(Py_LIMITED_API))] #[pyo3(warn(message = "this method raises FutureWarning", category = pyo3::exceptions::PyFutureWarning))] #[pyo3(warn(message = "this method raises UserDefinedWarning", category = UserDefinedWarning))] fn multiple_warn_custom_category_method(&self) {} @@ -1452,6 +1459,7 @@ fn test_py_methods_multiple_warn() { ] ); + #[cfg(not(Py_LIMITED_API))] py_expect_warning!( py, obj, diff --git a/tests/test_pyfunction.rs b/tests/test_pyfunction.rs index dc164534e75..b35b01299f3 100644 --- a/tests/test_pyfunction.rs +++ b/tests/test_pyfunction.rs @@ -4,7 +4,9 @@ use std::collections::HashMap; #[cfg(not(Py_LIMITED_API))] use pyo3::buffer::PyBuffer; -use pyo3::exceptions::{PyDeprecationWarning, PyFutureWarning, PyUserWarning, PyWarning}; +#[cfg(not(Py_LIMITED_API))] +use pyo3::exceptions::PyWarning; +use pyo3::exceptions::{PyDeprecationWarning, PyFutureWarning, PyUserWarning}; use pyo3::ffi::c_str; use pyo3::prelude::*; #[cfg(not(Py_LIMITED_API))] @@ -606,9 +608,11 @@ fn test_pyfunction_raw_ident() { }) } +#[cfg(not(Py_LIMITED_API))] #[pyclass(extends=PyWarning)] pub struct UserDefinedWarning {} +#[cfg(not(Py_LIMITED_API))] #[pymethods] impl UserDefinedWarning { #[new] @@ -656,10 +660,12 @@ fn test_pyfunction_warn() { )] ); + #[cfg(not(Py_LIMITED_API))] #[pyfunction] #[pyo3(warn(message = "this function raises user-defined warning", category = UserDefinedWarning))] fn function_with_warning_and_user_defined_category() {} + #[cfg(not(Py_LIMITED_API))] py_expect_warning_for_fn!( function_with_warning_and_user_defined_category, f, @@ -699,11 +705,13 @@ fn test_pyfunction_multiple_warnings() { ] ); + #[cfg(not(Py_LIMITED_API))] #[pyfunction] #[pyo3(warn(message = "this function raises FutureWarning", category = PyFutureWarning))] #[pyo3(warn(message = "this function raises user-defined warning", category = UserDefinedWarning))] fn function_with_multiple_custom_warnings() {} + #[cfg(not(Py_LIMITED_API))] py_expect_warning_for_fn!( function_with_multiple_custom_warnings, f,