FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Avoid composite for fixed IDNA test data by Mirochill · Pull Request #191 · python-hyper/hyperlink · GitHub

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 6 additions & 7 deletions src/hyperlink/test/test_hypothesis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL