From 1c32edcabc8363fe6dc401e6d2afe0788a136dc6 Mon Sep 17 00:00:00 2001 From: Quentin Retourne <32574188+nitneuqr@users.noreply.github.com> Date: Thu, 12 Sep 2024 02:43:26 +0200 Subject: [PATCH] Silencing mmap mypy warning on windows (#11570) * silencing the mmap mypy warning on windows even though the lib doesn't exist on this platform * better way without coverage issues * trying with pragma no cover :( * using type: ignore * another test with pragma: no cover * testing type: ignore with specific exclusions --- tests/hazmat/primitives/test_aead.py | 6 ++++-- tests/hazmat/primitives/test_ciphers.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/hazmat/primitives/test_aead.py b/tests/hazmat/primitives/test_aead.py index 2f0d52d82682..80850b689d35 100644 --- a/tests/hazmat/primitives/test_aead.py +++ b/tests/hazmat/primitives/test_aead.py @@ -37,8 +37,10 @@ def _aead_supported(cls): return False -def large_mmap(): - return mmap.mmap(-1, 2**32, prot=mmap.PROT_READ) +def large_mmap(length: int = 2**32): + # Silencing mypy prot argument warning on Windows, even though this + # function is only used in non-Windows-based tests. + return mmap.mmap(-1, length, prot=mmap.PROT_READ) # type: ignore[call-arg,attr-defined,unused-ignore] @pytest.mark.skipif( diff --git a/tests/hazmat/primitives/test_ciphers.py b/tests/hazmat/primitives/test_ciphers.py index 5fef25b86c0e..20dcb54d1b1d 100644 --- a/tests/hazmat/primitives/test_ciphers.py +++ b/tests/hazmat/primitives/test_ciphers.py @@ -4,7 +4,6 @@ import binascii -import mmap import os import sys @@ -20,6 +19,7 @@ ) from ...utils import load_nist_vectors, load_vectors_from_file +from .test_aead import large_mmap def test_deprecated_ciphers_import_with_warning(): @@ -255,7 +255,7 @@ def test_update_into_buffer_too_small_gcm(self, backend): sys.platform not in {"linux", "darwin"}, reason="mmap required" ) def test_update_auto_chunking(): - large_data = mmap.mmap(-1, 2**29 + 2**20, prot=mmap.PROT_READ) + large_data = large_mmap(length=2**29 + 2**20) key = b"\x00" * 16 c = ciphers.Cipher(AES(key), modes.ECB())