Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/hyperlink/test/test_hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
from mock import patch # type: ignore[misc]

from hypothesis import given, settings
from hypothesis.strategies import SearchStrategy, data
from hypothesis.strategies import SearchStrategy, data, just

from idna import IDNAError, check_label, encode as idna_encode

from .common import HyperlinkTestCase
from .. import DecodedURL, EncodedURL
from ..hypothesis import (
DrawCallable,
composite,
decoded_urls,
encoded_urls,
hostname_labels,
Expand Down Expand Up @@ -102,15 +100,16 @@ def test_hostname_labels_long_idn_punycode(self, data):
that encoded to punycode ends up as longer than allowed.
"""

@composite
def mock_idna_text(draw, min_size, max_size):
# type: (DrawCallable, int, int) -> Text
def mock_idna_text(min_size, max_size):
# type: (int, int) -> SearchStrategy[Text]
# We want a string that does not exceed max_size, but when
# encoded to punycode, does exceed max_size.
# So use a unicode character that is larger when encoded,
# "á" being a great example, and use it max_size times, which
# will be max_size * 3 in size when encoded.
return u"\N{LATIN SMALL LETTER A WITH ACUTE}" * max_size
return just(
u"\N{LATIN SMALL LETTER A WITH ACUTE}" * max_size
)

with patch("hyperlink.hypothesis.idna_text", mock_idna_text):
label = data.draw(hostname_labels())
Expand Down