Skip to content

Commit

Permalink
Silencing mmap mypy warning on windows (#11570)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nitneuqr committed Sep 12, 2024
1 parent 2bf6ed8 commit 1c32edc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions tests/hazmat/primitives/test_aead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/hazmat/primitives/test_ciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


import binascii
import mmap
import os
import sys

Expand All @@ -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():
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 1c32edc

Please sign in to comment.