2018-09-03 18:50:18 +00:00
|
|
|
//! Useful tips for writing tests:
|
|
|
|
//! - Tests are run in parallel; There's still a race condition in test_owned with some other test
|
|
|
|
//! - You need to use flush=True to get any output from print
|
|
|
|
|
2018-05-02 18:49:40 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! py_assert {
|
2018-06-15 19:21:12 +00:00
|
|
|
($py:expr, $val:ident, $assertion:expr) => {
|
2019-06-13 09:09:17 +00:00
|
|
|
pyo3::py_run!($py, $val, concat!("assert ", $assertion))
|
2018-06-15 19:21:12 +00:00
|
|
|
};
|
2018-05-02 18:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! py_expect_exception {
|
|
|
|
($py:expr, $val:ident, $code:expr, $err:ident) => {{
|
2019-03-20 18:37:27 +00:00
|
|
|
use pyo3::types::IntoPyDict;
|
|
|
|
let d = [(stringify!($val), &$val)].into_py_dict($py);
|
|
|
|
|
2018-05-02 18:49:40 +00:00
|
|
|
let res = $py.run($code, None, Some(d));
|
|
|
|
let err = res.unwrap_err();
|
2018-09-21 21:32:48 +00:00
|
|
|
if !err.matches($py, $py.get_type::<pyo3::exceptions::$err>()) {
|
2018-05-02 18:49:40 +00:00
|
|
|
panic!(format!("Expected {} but got {:?}", stringify!($err), err))
|
|
|
|
}
|
2018-06-15 19:21:12 +00:00
|
|
|
}};
|
2018-05-02 18:49:40 +00:00
|
|
|
}
|