aboutsummaryrefslogtreecommitdiff
path: root/rust/pytests/assigned_numbers.rs
blob: 10e7f3e8c6a09e8bfee51fdfee9c1f47d24f2769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use bumble::wrapper::{self, core::Uuid16};
use pyo3::{intern, prelude::*, types::PyDict};
use std::collections;

#[pyo3_asyncio::tokio::test]
async fn company_ids_matches_python() -> PyResult<()> {
    let ids_from_python = Python::with_gil(|py| {
        PyModule::import(py, intern!(py, "bumble.company_ids"))?
            .getattr(intern!(py, "COMPANY_IDENTIFIERS"))?
            .downcast::<PyDict>()?
            .into_iter()
            .map(|(k, v)| {
                Ok((
                    Uuid16::from_be_bytes(k.extract::<u16>()?.to_be_bytes()),
                    v.str()?.to_str()?.to_string(),
                ))
            })
            .collect::<PyResult<collections::HashMap<_, _>>>()
    })?;

    assert_eq!(
        wrapper::assigned_numbers::COMPANY_IDS
            .iter()
            .map(|(id, name)| (*id, name.to_string()))
            .collect::<collections::HashMap<_, _>>(),
        ids_from_python,
        "Company ids do not match -- re-run gen_assigned_numbers?"
    );
    Ok(())
}