2021-12-03 00:03:32 +00:00
|
|
|
#![cfg(feature = "macros")]
|
|
|
|
|
2019-01-24 22:09:24 +00:00
|
|
|
use pyo3::prelude::*;
|
|
|
|
use pyo3::types::{PyDict, PyTuple};
|
|
|
|
|
2023-09-24 12:34:53 +00:00
|
|
|
#[path = "../src/tests/common.rs"]
|
2019-01-24 22:09:24 +00:00
|
|
|
mod common;
|
|
|
|
|
|
|
|
#[pyclass]
|
|
|
|
struct MyClass {}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[staticmethod]
|
2022-10-25 06:23:21 +00:00
|
|
|
#[pyo3(signature = (*args))]
|
2021-02-11 21:37:38 +00:00
|
|
|
fn test_args(args: &PyTuple) -> &PyTuple {
|
|
|
|
args
|
2019-01-24 22:09:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[staticmethod]
|
2022-10-25 06:23:21 +00:00
|
|
|
#[pyo3(signature = (**kwargs))]
|
2021-02-11 21:37:38 +00:00
|
|
|
fn test_kwargs(kwargs: Option<&PyDict>) -> Option<&PyDict> {
|
|
|
|
kwargs
|
2019-01-24 22:09:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn variable_args() {
|
2022-07-19 17:34:23 +00:00
|
|
|
Python::with_gil(|py| {
|
2024-02-18 18:27:19 +00:00
|
|
|
let my_obj = py.get_type_bound::<MyClass>();
|
2022-07-19 17:34:23 +00:00
|
|
|
py_assert!(py, my_obj, "my_obj.test_args() == ()");
|
|
|
|
py_assert!(py, my_obj, "my_obj.test_args(1) == (1,)");
|
|
|
|
py_assert!(py, my_obj, "my_obj.test_args(1, 2) == (1, 2)");
|
|
|
|
});
|
2019-01-24 22:09:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn variable_kwargs() {
|
2022-07-19 17:34:23 +00:00
|
|
|
Python::with_gil(|py| {
|
2024-02-18 18:27:19 +00:00
|
|
|
let my_obj = py.get_type_bound::<MyClass>();
|
2022-07-19 17:34:23 +00:00
|
|
|
py_assert!(py, my_obj, "my_obj.test_kwargs() == None");
|
|
|
|
py_assert!(py, my_obj, "my_obj.test_kwargs(test=1) == {'test': 1}");
|
|
|
|
py_assert!(
|
|
|
|
py,
|
|
|
|
my_obj,
|
|
|
|
"my_obj.test_kwargs(test1=1, test2=2) == {'test1':1, 'test2':2}"
|
|
|
|
);
|
|
|
|
});
|
2019-01-24 22:09:24 +00:00
|
|
|
}
|