Reduce visibility of CaptureStdErr type to avoid warnings on older toolchains.

This commit is contained in:
Adam Reichold 2023-02-18 16:33:07 +01:00
parent c7cc48f8e4
commit 577570e8c4
1 changed files with 35 additions and 35 deletions

View File

@ -1,6 +1,6 @@
#![cfg(feature = "macros")]
use pyo3::{prelude::*, types::PyString};
use pyo3::prelude::*;
mod common;
@ -98,37 +98,7 @@ fn recursive_class_attributes() {
#[test]
#[cfg(panic = "unwind")]
fn test_fallible_class_attribute() {
use pyo3::exceptions::PyValueError;
#[pyclass]
struct BrokenClass;
#[pymethods]
impl BrokenClass {
#[classattr]
fn fails_to_init() -> PyResult<i32> {
Err(PyValueError::new_err("failed to create class attribute"))
}
}
Python::with_gil(|py| {
let stderr = CaptureStdErr::new(py).unwrap();
assert!(std::panic::catch_unwind(|| py.get_type::<BrokenClass>()).is_err());
assert_eq!(
stderr.reset().unwrap().trim(),
"\
ValueError: failed to create class attribute
The above exception was the direct cause of the following exception:
RuntimeError: An error occurred while initializing `BrokenClass.fails_to_init`
The above exception was the direct cause of the following exception:
RuntimeError: An error occurred while initializing class BrokenClass"
)
})
}
use pyo3::{exceptions::PyValueError, types::PyString};
struct CaptureStdErr<'py> {
oldstderr: &'py PyAny,
@ -161,3 +131,33 @@ impl<'py> CaptureStdErr<'py> {
Ok(payload)
}
}
#[pyclass]
struct BrokenClass;
#[pymethods]
impl BrokenClass {
#[classattr]
fn fails_to_init() -> PyResult<i32> {
Err(PyValueError::new_err("failed to create class attribute"))
}
}
Python::with_gil(|py| {
let stderr = CaptureStdErr::new(py).unwrap();
assert!(std::panic::catch_unwind(|| py.get_type::<BrokenClass>()).is_err());
assert_eq!(
stderr.reset().unwrap().trim(),
"\
ValueError: failed to create class attribute
The above exception was the direct cause of the following exception:
RuntimeError: An error occurred while initializing `BrokenClass.fails_to_init`
The above exception was the direct cause of the following exception:
RuntimeError: An error occurred while initializing class BrokenClass"
)
});
}