2021-12-03 00:03:32 +00:00
|
|
|
#![cfg(feature = "macros")]
|
|
|
|
|
2021-11-21 17:08:24 +00:00
|
|
|
use pyo3::prelude::*;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
// Test default generated __repr__.
|
|
|
|
#[pyclass]
|
|
|
|
enum TestDefaultRepr {
|
|
|
|
Var,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_default_slot_exists() {
|
|
|
|
Python::with_gil(|py| {
|
|
|
|
let test_object = Py::new(py, TestDefaultRepr::Var).unwrap();
|
|
|
|
py_assert!(
|
|
|
|
py,
|
|
|
|
test_object,
|
|
|
|
"repr(test_object) == 'TestDefaultRepr.Var'"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pyclass]
|
|
|
|
enum OverrideSlot {
|
|
|
|
Var,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl OverrideSlot {
|
|
|
|
fn __repr__(&self) -> &str {
|
|
|
|
"overriden"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_override_slot() {
|
|
|
|
Python::with_gil(|py| {
|
|
|
|
let test_object = Py::new(py, OverrideSlot::Var).unwrap();
|
|
|
|
py_assert!(py, test_object, "repr(test_object) == 'overriden'");
|
|
|
|
})
|
|
|
|
}
|