# HG changeset patch # User Georges Racinet # Date 1695995509 -7200 # Node ID 52bbb57a76ad1bc9ac8d64fc50e0edc0c277b759 # Parent bc4d83047c6c5faf5fd2259f329e6589f55b87d4 rust-index: results comparison helper with details This is a bit simpler to call and has the advantage of systematically log the encountered deviation. To avoid committing dead code, we apply it to the `pack_header` method, that was already returning the Rust result. diff -r bc4d83047c6c -r 52bbb57a76ad rust/hg-cpython/src/revlog.rs --- a/rust/hg-cpython/src/revlog.rs Wed Sep 27 10:59:04 2023 +0200 +++ b/rust/hg-cpython/src/revlog.rs Fri Sep 29 15:51:49 2023 +0200 @@ -13,7 +13,7 @@ use cpython::{ buffer::{Element, PyBuffer}, exc::{IndexError, ValueError}, - ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyInt, PyModule, + ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyInt, PyModule, PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject, }; use hg::{ @@ -218,10 +218,10 @@ def pack_header(&self, *args, **kw) -> PyResult { let rindex = self.index(py).borrow(); let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?); - let packed = PyBytes::new(py, &packed); + let packed = PyBytes::new(py, &packed).into_object(); let cpacked = self.call_cindex(py, "pack_header", args, kw)?; - assert!(packed.as_object().compare(py, cpacked)?.is_eq()); - Ok(packed.into_object()) + assert_py_eq(py, "pack_header", &packed, &cpacked)?; + Ok(packed) } /// get an index entry @@ -630,6 +630,27 @@ } } +fn assert_py_eq( + py: Python, + method: &str, + rust: &PyObject, + c: &PyObject, +) -> PyResult<()> { + let locals = PyDict::new(py); + locals.set_item(py, "rust".into_py_object(py).into_object(), rust)?; + locals.set_item(py, "c".into_py_object(py).into_object(), c)?; + let is_eq: PyBool = + py.eval("rust == c", None, Some(&locals))?.extract(py)?; + assert!( + is_eq.is_true(), + "{} results differ. Rust: {:?} C: {:?}", + method, + rust, + c + ); + Ok(()) +} + /// Create the module, with __package__ given from parent pub fn init_module(py: Python, package: &str) -> PyResult { let dotted_name = &format!("{}.revlog", package);