File: test_dict_iter.rs

package info (click to toggle)
rust-pyo3 0.22.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,420 kB
  • sloc: makefile: 58; python: 39; sh: 1
file content (17 lines) | stat: -rw-r--r-- 491 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use pyo3::prelude::*;
use pyo3::types::IntoPyDict;

#[test]
#[cfg_attr(target_arch = "wasm32", ignore)] // Not sure why this fails.
fn iter_dict_nosegv() {
    Python::with_gil(|py| {
        const LEN: usize = 10_000_000;
        let dict = (0..LEN as u64).map(|i| (i, i * 2)).into_py_dict_bound(py);
        let mut sum = 0;
        for (k, _v) in dict {
            let i: u64 = k.extract().unwrap();
            sum += i;
        }
        assert_eq!(sum, 49_999_995_000_000);
    });
}