-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Move all strategies to their own file * Rewrite start_game tests to use hypothesis Note that test_start_game_with_teams will fail. * Bypass the ascii check when setting matchmaker game names Since the name was generated internally, we can trust it to be ok. The ascii check is really meant to prevent encoding errors accross different system configurations and to encourage the use of English titles. Clan names will be guaranteed to be valid utf8, and the rest of the game title will be in English since we created it that way. * Refactor player_factory to generate connection mocks with spec or autospec * Update codecov to get statuses to post
- Loading branch information
Showing
14 changed files
with
205 additions
and
159 deletions.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
comment: false | ||
comment: | ||
layout: "files" | ||
|
||
coverage: | ||
status: | ||
|
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
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
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,56 @@ | ||
# Custom hypothesis strategies | ||
|
||
import string | ||
|
||
from hypothesis import strategies as st | ||
|
||
from server.matchmaker import Search | ||
from tests.conftest import make_player | ||
|
||
|
||
@st.composite | ||
def st_rating(draw): | ||
"""Strategy for generating rating tuples""" | ||
return ( | ||
draw(st.floats(min_value=-100., max_value=2500.)), | ||
draw(st.floats(min_value=0.001, max_value=500.)) | ||
) | ||
|
||
|
||
@st.composite | ||
def st_players(draw, name=None, **kwargs): | ||
"""Strategy for generating Player objects""" | ||
return make_player( | ||
ladder_rating=(draw(st_rating())), | ||
ladder_games=draw(st.integers(0, 1000)), | ||
login=draw(st.text( | ||
alphabet=list(string.ascii_letters + string.digits + "_-"), | ||
min_size=1, | ||
max_size=42 | ||
)) if name is None else name, | ||
clan=draw(st.text(min_size=1, max_size=3)), | ||
**kwargs | ||
) | ||
|
||
|
||
@st.composite | ||
def st_searches(draw, num_players=1): | ||
"""Strategy for generating Search objects""" | ||
return Search([ | ||
draw(st_players(f"p{i}")) for i in range(num_players) | ||
]) | ||
|
||
|
||
@st.composite | ||
def st_searches_list(draw, min_players=1, max_players=10, max_size=30): | ||
"""Strategy for generating a list of Search objects""" | ||
return draw( | ||
st.lists( | ||
st_searches( | ||
num_players=draw( | ||
st.integers(min_value=min_players, max_value=max_players) | ||
) | ||
), | ||
max_size=max_size | ||
) | ||
) |
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.