2022-12-28 22:11:39 +00:00
|
|
|
#![cfg(feature = "macros")]
|
|
|
|
|
|
|
|
use pyo3::prelude::*;
|
|
|
|
|
|
|
|
#[pyclass]
|
|
|
|
struct CfgClass {
|
|
|
|
#[pyo3(get, set)]
|
|
|
|
#[cfg(any())]
|
|
|
|
pub a: u32,
|
|
|
|
#[pyo3(get, set)]
|
2023-07-11 09:55:57 +00:00
|
|
|
// This is always true
|
|
|
|
#[cfg(any(
|
|
|
|
target_family = "unix",
|
|
|
|
target_family = "windows",
|
|
|
|
target_family = "wasm"
|
|
|
|
))]
|
2022-12-28 22:11:39 +00:00
|
|
|
pub b: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cfg() {
|
|
|
|
Python::with_gil(|py| {
|
|
|
|
let cfg = CfgClass { b: 3 };
|
|
|
|
let py_cfg = Py::new(py, cfg).unwrap();
|
2024-02-22 22:38:42 +00:00
|
|
|
assert!(py_cfg.bind(py).getattr("a").is_err());
|
|
|
|
let b: u32 = py_cfg.bind(py).getattr("b").unwrap().extract().unwrap();
|
2022-12-28 22:11:39 +00:00
|
|
|
assert_eq!(b, 3);
|
|
|
|
});
|
|
|
|
}
|