From 3c83f9a8dc2ba0e4f537bac0af6867826bceb06d Mon Sep 17 00:00:00 2001 From: Miles Granger Date: Mon, 5 Feb 2024 18:11:20 +0100 Subject: [PATCH] Impl __eq__ for python Buffer --- Cargo.lock | 22 ++++++++++++++++++++-- cramjam-python/src/io.rs | 3 +++ cramjam-python/tests/test_variants.py | 6 ++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d75deed4..f86bf36b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -295,14 +295,14 @@ version = "0.1.1" dependencies = [ "bytesize", "clap 4.2.7", - "libcramjam", + "libcramjam 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cramjam-python" version = "2.8.1" dependencies = [ - "libcramjam", + "libcramjam 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "pyo3", ] @@ -526,6 +526,24 @@ dependencies = [ "zstd", ] +[[package]] +name = "libcramjam" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1122d475df7c0461d2ed3af60e609512e4ec0c1c98156be1f320513b84fd9510" +dependencies = [ + "brotli", + "bzip2", + "cbindgen", + "flate2", + "libdeflater", + "lz4", + "snap", + "xz2", + "zstd", + "zstd-safe", +] + [[package]] name = "libdeflate-sys" version = "1.19.0" diff --git a/cramjam-python/src/io.rs b/cramjam-python/src/io.rs index 32f35126..d9561204 100644 --- a/cramjam-python/src/io.rs +++ b/cramjam-python/src/io.rs @@ -432,6 +432,9 @@ impl RustyBuffer { fn __repr__(&self) -> String { format!("cramjam.Buffer", self.len()) } + fn __eq__(&self, other: &Self) -> bool { + self.inner == other.inner + } fn __bool__(&self) -> bool { self.len() > 0 } diff --git a/cramjam-python/tests/test_variants.py b/cramjam-python/tests/test_variants.py index a24e81c1..ecc9181b 100644 --- a/cramjam-python/tests/test_variants.py +++ b/cramjam-python/tests/test_variants.py @@ -360,3 +360,9 @@ def test_variants_stream_decompressors(variant_str): # Calling .finish renders decompressor unusable after. (API consistency with other libs) with pytest.raises(cramjam.DecompressionError): decompressor.finish() + + +def test_buffer_cmp(): + assert cramjam.Buffer() == cramjam.Buffer() + assert cramjam.Buffer(b"some bytes") == cramjam.Buffer(b"some bytes") + assert cramjam.Buffer(b"some bytes") != cramjam.Buffer(b"other bytes")