-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests for cargo stress on free-threaded build (#4469)
* make it possible to run test_bad_datetime_module_panic under 'cargo stress' * weaken assertions in tests of the pending decrefs pool on free-threaded builds * use the tempfile crate to create a temporary directory
- Loading branch information
Showing
3 changed files
with
21 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
#![cfg(not(Py_LIMITED_API))] | ||
|
||
use pyo3::{prelude::*, types::PyDate}; | ||
use tempfile::Builder; | ||
|
||
#[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(); | ||
let tmpdir = Builder::new() | ||
.prefix("pyo3_test_data_check") | ||
.tempdir() | ||
.unwrap(); | ||
std::fs::File::create(tmpdir.path().join("datetime.py")).unwrap(); | ||
|
||
Python::with_gil(|py: Python<'_>| { | ||
let sys = py.import("sys").unwrap(); | ||
sys.getattr("path") | ||
.unwrap() | ||
.call_method1("insert", (0, tmpdir)) | ||
.call_method1("insert", (0, tmpdir.path())) | ||
.unwrap(); | ||
|
||
// This should panic because the "datetime" module is empty | ||
PyDate::new(py, 2018, 1, 1).unwrap(); | ||
}); | ||
tmpdir.close().unwrap(); | ||
} |