-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove hypothesis (at least for now) #586
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d413c03
begin eliminating hypothesis
glyph f6a9a3b
checkpoint
glyph d3276bc
and that's a wrap
glyph bb90e25
almost there
glyph 8a9a992
explanation, formatting
glyph f3ed65b
thanks linters
glyph 3cff379
don't need this parameter yet, so get rid of uncovered line
glyph 9110cd2
min_size parameter not used, let's skip the coverage problem
glyph c555bfb
address some coverage gaps
glyph 8464368
Merge branch 'master' into falsified
glyph 7e1d354
Merge branch 'master' into falsified
glyph 87c08f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
*~ | ||
.DS_Store | ||
/.eggs | ||
/.hypothesis/ | ||
/.tox/ | ||
/apidocs/ | ||
/build/ | ||
|
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
treq==22.2.0 | ||
hypothesis==6.48.2 | ||
idna==3.3 |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,175 @@ | ||
""" | ||
We have had a history of U{bad | ||
experiences<https://github.com/twisted/klein/issues/561>} with Hypothesis in | ||
Klein, and maybe it's not actually a good application of this tool at all. As | ||
such we have removed it, at least for now. This module presents a vaguely | ||
Hypothesis-like stub, to keep the structure of our tests in a | ||
Hypothesis-friendly shape, in case we want to put it back. | ||
""" | ||
|
||
from functools import wraps | ||
from itertools import product | ||
from string import ascii_uppercase | ||
from typing import Callable, Iterable, Optional, Tuple, TypeVar | ||
|
||
from hyperlink import DecodedURL | ||
|
||
|
||
T = TypeVar("T") | ||
S = TypeVar("S") | ||
|
||
|
||
def given( | ||
*args: Callable[[], Iterable[T]], | ||
**kwargs: Callable[[], Iterable[T]], | ||
) -> Callable[[Callable[..., None]], Callable[..., None]]: | ||
def decorator(testMethod: Callable[..., None]) -> Callable[..., None]: | ||
@wraps(testMethod) | ||
def realTestMethod(self: S) -> None: | ||
everyPossibleArgs = product( | ||
*[eachFactory() for eachFactory in args] | ||
) | ||
everyPossibleKwargs = product( | ||
*[ | ||
[(name, eachValue) for eachValue in eachFactory()] | ||
for (name, eachFactory) in kwargs.items() | ||
] | ||
) | ||
everyPossibleSignature = product( | ||
everyPossibleArgs, everyPossibleKwargs | ||
) | ||
# not quite the _full_ cartesian product but the whole point is | ||
# that we're making a feeble attempt at this rather than bringing | ||
# in hypothesis. | ||
for computedArgs, computedPairs in everyPossibleSignature: | ||
computedKwargs = dict(computedPairs) | ||
testMethod(self, *computedArgs, **computedKwargs) | ||
|
||
return realTestMethod | ||
|
||
return decorator | ||
|
||
|
||
def binary() -> Callable[[], Iterable[bytes]]: | ||
""" | ||
Generate some binary data. | ||
""" | ||
|
||
def params() -> Iterable[bytes]: | ||
return [b"data", b"data data data", b"\x00" * 50, b""] | ||
|
||
return params | ||
|
||
|
||
def ascii_text(min_size: int) -> Callable[[], Iterable[str]]: | ||
""" | ||
Generate some ASCII strs. | ||
""" | ||
|
||
def params() -> Iterable[str]: | ||
yield from [ | ||
"ascii-text", | ||
"some more ascii text", | ||
] | ||
assert min_size, "nothing needs 0-length strings right now" | ||
|
||
return params | ||
|
||
|
||
def latin1_text(min_size: int = 0) -> Callable[[], Iterable[str]]: | ||
""" | ||
Generate some strings encodable as latin1 | ||
""" | ||
|
||
def params() -> Iterable[str]: | ||
yield from [ | ||
"latin1-text", | ||
"some more latin1 text", | ||
"hére is latin1 text", | ||
] | ||
if not min_size: | ||
yield "" | ||
|
||
return params | ||
|
||
|
||
def text( | ||
min_size: int = 0, alphabet: Optional[str] = None | ||
) -> Callable[[], Iterable[str]]: | ||
""" | ||
Generate some text. | ||
""" | ||
|
||
def params() -> Iterable[str]: | ||
if alphabet == ascii_uppercase: | ||
yield from ascii_text(min_size)() | ||
return | ||
yield from latin1_text(min_size)() | ||
yield "\N{SNOWMAN}" | ||
|
||
return params | ||
|
||
|
||
def textHeaderPairs() -> Callable[[], Iterable[Iterable[Tuple[str, str]]]]: | ||
""" | ||
Generate some pairs of headers with text values. | ||
""" | ||
|
||
def params() -> Iterable[Iterable[Tuple[str, str]]]: | ||
return [[], [("text", "header")]] | ||
|
||
return params | ||
|
||
|
||
def bytesHeaderPairs() -> Callable[[], Iterable[Iterable[Tuple[str, bytes]]]]: | ||
""" | ||
Generate some pairs of headers with bytes values. | ||
""" | ||
|
||
def params() -> Iterable[Iterable[Tuple[str, bytes]]]: | ||
return [[], [("bytes", b"header")]] | ||
|
||
return params | ||
|
||
|
||
def booleans() -> Callable[[], Iterable[bool]]: | ||
def parameters() -> Iterable[bool]: | ||
yield True | ||
yield False | ||
|
||
return parameters | ||
|
||
|
||
def jsonObjects() -> Callable[[], Iterable[object]]: | ||
def parameters() -> Iterable[object]: | ||
yield {} | ||
yield {"hello": "world"} | ||
yield {"here is": {"some": "nesting"}} | ||
yield { | ||
"and": "multiple", | ||
"keys": { | ||
"with": "nesting", | ||
"and": 1234, | ||
"numbers": ["with", "lists", "too"], | ||
"also": ("tuples", "can", "serialize"), | ||
}, | ||
} | ||
|
||
return parameters | ||
|
||
|
||
def decoded_urls() -> Callable[[], Iterable[DecodedURL]]: | ||
""" | ||
Generate a few URLs U{with only path and domain names | ||
<https://github.com/python-hyper/hyperlink/issues/181>} kind of like | ||
Hyperlink's own hypothesis strategy. | ||
""" | ||
|
||
def parameters() -> Iterable[DecodedURL]: | ||
yield DecodedURL.from_text("https://example.com/") | ||
yield DecodedURL.from_text("https://example.com") | ||
yield DecodedURL.from_text("http://example.com/") | ||
yield DecodedURL.from_text("https://example.com/é") | ||
yield DecodedURL.from_text("https://súbdomain.example.com/ascii/path/") | ||
|
||
return parameters |
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want a URL str that has a %-encoded path element here?