forked from auracaster/bumble_mirror
Following up on the [loose end from the initial PR](https://github.com/google/bumble/pull/207#discussion_r1278015116), we can avoid accessing the Python company id map at runtime by doing code gen ahead of time. Using an example to do the code gen avoids even the small build slowdown from invoking the code gen logic in build.rs, but more importantly, means that it's still a totally boring normal build that won't require any IDE setup, etc, to work for everyone. Since the company ID list changes rarely, and there's a test to ensure it always matches, this seems like a good trade.
31 lines
1021 B
Rust
31 lines
1021 B
Rust
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(())
|
|
}
|