2024-02-10 13:57:20 +00:00
|
|
|
#![cfg(not(Py_LIMITED_API))]
|
|
|
|
|
2024-02-14 00:24:37 +00:00
|
|
|
use pyo3::{prelude::*, types::PyDate};
|
2024-02-10 13:57:20 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic(expected = "module 'datetime' has no attribute 'datetime_CAPI'")]
|
|
|
|
fn test_bad_datetime_module_panic() {
|
|
|
|
// Create an empty temporary directory
|
|
|
|
// with an empty "datetime" module which we'll put on the sys.path
|
|
|
|
let tmpdir = std::env::temp_dir();
|
|
|
|
let tmpdir = tmpdir.join("pyo3_test_date_check");
|
|
|
|
let _ = std::fs::remove_dir_all(&tmpdir);
|
|
|
|
std::fs::create_dir(&tmpdir).unwrap();
|
|
|
|
std::fs::File::create(tmpdir.join("datetime.py")).unwrap();
|
|
|
|
|
|
|
|
Python::with_gil(|py: Python<'_>| {
|
2024-02-14 00:24:37 +00:00
|
|
|
let sys = py.import_bound("sys").unwrap();
|
2024-02-10 13:57:20 +00:00
|
|
|
sys.getattr("path")
|
|
|
|
.unwrap()
|
|
|
|
.call_method1("insert", (0, tmpdir))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// This should panic because the "datetime" module is empty
|
2024-02-12 20:49:58 +00:00
|
|
|
PyDate::new_bound(py, 2018, 1, 1).unwrap();
|
2024-02-10 13:57:20 +00:00
|
|
|
});
|
|
|
|
}
|