Skip to content
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

Fix whitespace issues #881

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion license.rtf
Original file line number Diff line number Diff line change
Expand Up @@ -676,4 +676,4 @@ Public License instead of this License. But first, please read\par
<http://www.gnu.org/philosophy/why-not-lgpl.html>.\par
\par
}
1 change: 1 addition & 0 deletions server/api/api_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SessionManager:
"""
Garantor for API access
"""

def __init__(self):
self.session = None # Instance of session

Expand Down
2 changes: 1 addition & 1 deletion server/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
Column("color", Integer, nullable=False),
Column("team", Integer, nullable=False),
Column("place", Integer, nullable=False),
# DEPRECATED: Use leaderboard_rating_journal instead. These columns should
# DEPRECATED: Use leaderboard_rating_journal instead. These columns should
# be dropped at some point.
Column("mean", Float, nullable=False),
Column("deviation", Float, nullable=False),
Expand Down
3 changes: 3 additions & 0 deletions server/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ClientError(Exception):
If recoverable is False, it is expected that the connection be terminated
immediately.
"""

def __init__(self, message, recoverable=True, *args, **kwargs):
super().__init__(*args, **kwargs)
self.message = message
Expand All @@ -24,6 +25,7 @@ class BanError(Exception):
"""
Signals that an operation could not be completed because the user is banned.
"""

def __init__(self, ban_expiry, ban_reason, *args, **kwargs):
super().__init__(*args, **kwargs)
self.ban_expiry = ban_expiry
Expand All @@ -50,6 +52,7 @@ class AuthenticationError(Exception):
"""
The operation failed to authenticate.
"""

def __init__(self, message, method, *args, **kwargs):
super().__init__(*args, **kwargs)
self.message = message
Expand Down
1 change: 1 addition & 0 deletions server/game_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GameService(Service):
"""
Utility class for maintaining lifecycle of games
"""

def __init__(
self,
database: FAFDatabase,
Expand Down
1 change: 1 addition & 0 deletions server/ice_servers/nts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TwilioNTS:

Creates new twilio NTS tokens
"""

def __init__(self, sid=None, token=None):
if sid is None:
sid = config.TWILIO_ACCOUNT_SID # pragma: no cover
Expand Down
1 change: 1 addition & 0 deletions server/ladder_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class LadderService(Service):
Service responsible for managing the 1v1 ladder. Does matchmaking, updates
statistics, and launches the games.
"""

def __init__(
self,
database: FAFDatabase,
Expand Down
1 change: 1 addition & 0 deletions server/matchmaker/algorithm/stable_marriage.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class StableMarriageMatchmaker(Matchmaker):
Runs stable marriage to produce a list of matches
and afterwards adds random matchups for previously unmatched new players.
"""

def find(
self, searches: Iterable[Search], team_size: int
) -> tuple[list[Match], list[Search]]:
Expand Down
1 change: 1 addition & 0 deletions server/matchmaker/algorithm/team_matchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TeamMatchMaker(Matchmaker):
8. pick the first game from the game list and remove all other games that contain the same players
9. repeat 8. until the list is empty
"""

def find(self, searches: Iterable[Search], team_size: int) -> tuple[list[Match], list[Search]]:
if not searches:
return [], []
Expand Down
1 change: 1 addition & 0 deletions server/matchmaker/pop_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PopTimer(object):
The player queue rate is based on a moving average over the last few pops.
The exact size can be set in config.
"""

def __init__(self, queue: "MatchmakerQueue"):
self.queue = queue
# Set up deque's for calculating a moving average
Expand Down
1 change: 1 addition & 0 deletions server/message_queue_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MessageQueueService(Service):
Service handling connection to the message queue
and providing an interface to publish messages.
"""

def __init__(self) -> None:
self._connection = None
self._channel = None
Expand Down
1 change: 1 addition & 0 deletions server/rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class InclusiveRange():
assert -1 not in InclusiveRange(0, 10)
assert 11 not in InclusiveRange(0, 10)
"""

def __init__(self, lo: Optional[float] = None, hi: Optional[float] = None):
self.lo = lo
self.hi = hi
Expand Down
2 changes: 1 addition & 1 deletion tests/data/game_stats_ai_game.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/game_stats_full_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/game_stats_no_army_for_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"name": "SomeoneElse"
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/game_stats_simple_win.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/game_stats_single_player.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion tests/data/uid11255492.log.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"teams": {"2": [1, 2, 3, 4, 5, 6], "3": [7, 8, 9, 10, 11, 12]}, "winning_team": 2, "results": [[1, 1, "defeat", 0], [4, 1, "defeat", 0], [10, 1, "defeat", 0], [5, 1, "defeat", 0], [8, 1, "defeat", 0], [2, 1, "defeat", 0], [11, 1, "defeat", 0], [3, 1, "defeat", 0], [6, 1, "defeat", 0], [9, 1, "defeat", 0], [7, 1, "defeat", 0], [5, 8, "defeat", 0], [7, 8, "defeat", 0], [10, 8, "defeat", 0], [3, 8, "defeat", 0], [4, 8, "defeat", 0], [1, 8, "defeat", 0], [9, 8, "defeat", 0], [8, 8, "defeat", 0], [6, 8, "defeat", 0], [11, 8, "defeat", 0], [2, 8, "defeat", 0], [5, 11, "defeat", 0], [5, 0, "defeat", 0], [5, 2, "defeat", 0], [5, 3, "defeat", 0], [5, 6, "defeat", 0], [5, 4, "defeat", 0], [5, 5, "defeat", 0], [5, 7, "defeat", 0], [10, 7, "defeat", 0], [7, 7, "defeat", 0], [1, 7, "defeat", 0], [3, 7, "defeat", 0], [11, 7, "defeat", 0], [9, 7, "defeat", 0], [6, 7, "defeat", 0], [8, 7, "defeat", 0], [2, 7, "defeat", 0], [10, 3, "defeat", 0], [1, 3, "defeat", 0], [3, 3, "defeat", 0], [2, 3, "defeat", 0], [8, 3, "defeat", 0], [7, 3, "defeat", 0], [9, 3, "defeat", 0], [11, 3, "defeat", 0], [6, 3, "defeat", 0], [1, 3, "defeat", 0], [10, 3, "defeat", 0], [7, 3, "defeat", 0], [8, 3, "defeat", 0], [9, 3, "defeat", 0], [3, 3, "defeat", 0], [11, 3, "defeat", 0], [2, 3, "defeat", 0], [6, 3, "defeat", 0], [7, 9, "defeat", 0], [8, 9, "defeat", 0], [9, 9, "defeat", 0], [10, 9, "defeat", 0], [3, 9, "defeat", 0], [2, 9, "defeat", 0], [11, 9, "defeat", 0], [1, 9, "defeat", 0], [6, 9, "defeat", 0], [10, 0, "defeat", 0], [7, 0, "defeat", 0], [3, 0, "defeat", 0], [8, 0, "defeat", 0], [9, 0, "defeat", 0], [11, 0, "defeat", 0], [2, 0, "defeat", 0], [6, 0, "defeat", 0], [8, 11, "defeat", 0], [8, 6, "defeat", 0], [9, 11, "defeat", 0], [2, 11, "defeat", 0], [10, 11, "defeat", 0], [7, 11, "defeat", 0], [11, 11, "defeat", 0], [3, 11, "defeat", 0], [7, 10, "defeat", 0], [3, 10, "defeat", 0], [10, 10, "defeat", 0], [2, 10, "defeat", 0], [11, 10, "defeat", 0], [9, 10, "defeat", 0], [3, 2, "defeat", 0], [3, 4, "defeat", 0], [3, 5, "defeat", 0], [3, 6, "defeat", 0], [7, 6, "defeat", 0], [2, 6, "defeat", 0], [10, 6, "defeat", 0], [9, 6, "defeat", 0], [11, 6, "defeat", 0], [2, 2, "victory", 0], [7, 2, "victory", 0], [7, 4, "victory", 0], [7, 5, "victory", 0], [2, 4, "victory", 0], [2, 5, "victory", 0], [9, 2, "victory", 0], [10, 2, "victory", 0], [10, 4, "victory", 0], [10, 5, "victory", 0], [9, 4, "victory", 0], [9, 5, "victory", 0], [11, 2, "victory", 0], [11, 4, "victory", 0], [11, 5, "victory", 0]]}
{"teams": {"2": [1, 2, 3, 4, 5, 6], "3": [7, 8, 9, 10, 11, 12]}, "winning_team": 2, "results": [[1, 1, "defeat", 0], [4, 1, "defeat", 0], [10, 1, "defeat", 0], [5, 1, "defeat", 0], [8, 1, "defeat", 0], [2, 1, "defeat", 0], [11, 1, "defeat", 0], [3, 1, "defeat", 0], [6, 1, "defeat", 0], [9, 1, "defeat", 0], [7, 1, "defeat", 0], [5, 8, "defeat", 0], [7, 8, "defeat", 0], [10, 8, "defeat", 0], [3, 8, "defeat", 0], [4, 8, "defeat", 0], [1, 8, "defeat", 0], [9, 8, "defeat", 0], [8, 8, "defeat", 0], [6, 8, "defeat", 0], [11, 8, "defeat", 0], [2, 8, "defeat", 0], [5, 11, "defeat", 0], [5, 0, "defeat", 0], [5, 2, "defeat", 0], [5, 3, "defeat", 0], [5, 6, "defeat", 0], [5, 4, "defeat", 0], [5, 5, "defeat", 0], [5, 7, "defeat", 0], [10, 7, "defeat", 0], [7, 7, "defeat", 0], [1, 7, "defeat", 0], [3, 7, "defeat", 0], [11, 7, "defeat", 0], [9, 7, "defeat", 0], [6, 7, "defeat", 0], [8, 7, "defeat", 0], [2, 7, "defeat", 0], [10, 3, "defeat", 0], [1, 3, "defeat", 0], [3, 3, "defeat", 0], [2, 3, "defeat", 0], [8, 3, "defeat", 0], [7, 3, "defeat", 0], [9, 3, "defeat", 0], [11, 3, "defeat", 0], [6, 3, "defeat", 0], [1, 3, "defeat", 0], [10, 3, "defeat", 0], [7, 3, "defeat", 0], [8, 3, "defeat", 0], [9, 3, "defeat", 0], [3, 3, "defeat", 0], [11, 3, "defeat", 0], [2, 3, "defeat", 0], [6, 3, "defeat", 0], [7, 9, "defeat", 0], [8, 9, "defeat", 0], [9, 9, "defeat", 0], [10, 9, "defeat", 0], [3, 9, "defeat", 0], [2, 9, "defeat", 0], [11, 9, "defeat", 0], [1, 9, "defeat", 0], [6, 9, "defeat", 0], [10, 0, "defeat", 0], [7, 0, "defeat", 0], [3, 0, "defeat", 0], [8, 0, "defeat", 0], [9, 0, "defeat", 0], [11, 0, "defeat", 0], [2, 0, "defeat", 0], [6, 0, "defeat", 0], [8, 11, "defeat", 0], [8, 6, "defeat", 0], [9, 11, "defeat", 0], [2, 11, "defeat", 0], [10, 11, "defeat", 0], [7, 11, "defeat", 0], [11, 11, "defeat", 0], [3, 11, "defeat", 0], [7, 10, "defeat", 0], [3, 10, "defeat", 0], [10, 10, "defeat", 0], [2, 10, "defeat", 0], [11, 10, "defeat", 0], [9, 10, "defeat", 0], [3, 2, "defeat", 0], [3, 4, "defeat", 0], [3, 5, "defeat", 0], [3, 6, "defeat", 0], [7, 6, "defeat", 0], [2, 6, "defeat", 0], [10, 6, "defeat", 0], [9, 6, "defeat", 0], [11, 6, "defeat", 0], [2, 2, "victory", 0], [7, 2, "victory", 0], [7, 4, "victory", 0], [7, 5, "victory", 0], [2, 4, "victory", 0], [2, 5, "victory", 0], [9, 2, "victory", 0], [10, 2, "victory", 0], [10, 4, "victory", 0], [10, 5, "victory", 0], [9, 4, "victory", 0], [9, 5, "victory", 0], [11, 2, "victory", 0], [11, 4, "victory", 0], [11, 5, "victory", 0]]}
14 changes: 7 additions & 7 deletions tests/unit_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,13 @@ async def test_name_sanitization(game, players):
async def test_to_dict(game, player_factory):
game.state = GameState.LOBBY
players = [
(player_factory(f"{i}", player_id=i, global_rating=rating), result, team)
for i, (rating, result, team) in enumerate([
(Rating(1500, 250), 0, 1),
(Rating(1700, 120), 0, 1),
(Rating(1200, 72), 0, 2),
(Rating(1200, 72), 0, 2),
], 1)]
(player_factory(f"{i}", player_id=i, global_rating=rating), result, team)
for i, (rating, result, team) in enumerate([
(Rating(1500, 250), 0, 1),
(Rating(1700, 120), 0, 1),
(Rating(1200, 72), 0, 2),
(Rating(1200, 72), 0, 2),
], 1)]
add_connected_players(game, [player for player, _, _ in players])
for player, _, team in players:
game.set_player_option(player.id, "Team", team)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_ice.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_coturn_tokens(coturn_hmac, coturn_hosts, coturn_credentials):
f"turn:{host}?transport=tcp",
f"turn:{host}?transport=udp",
f"stun:{host}"
]
]

assert server["credential"] == credential
assert server["username"] == "124456:faf-test"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ async def test_abort(mocker, lobbyconnection):
async def test_send_game_list(mocker, database, lobbyconnection, game_stats_service):
games = mocker.patch.object(lobbyconnection, "game_service") # type: GameService
game1, game2 = mock.create_autospec(Game(42, database, mock.Mock(), game_stats_service)), \
mock.create_autospec(Game(22, database, mock.Mock(), game_stats_service))
mock.create_autospec(Game(22, database, mock.Mock(), game_stats_service))

games.open_games = [game1, game2]
lobbyconnection.send = mock.AsyncMock()
Expand Down
26 changes: 13 additions & 13 deletions tests/unit_tests/test_matchmaker_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ def player_factory(player_factory):
@pytest.fixture
def matchmaker_players(player_factory):
return player_factory("Dostya", player_id=1, ladder_rating=(2300, 64)), \
player_factory("Brackman", player_id=2, ladder_rating=(1200, 72)), \
player_factory("Zoidberg", player_id=3, ladder_rating=(1300, 175)), \
player_factory("QAI", player_id=4, ladder_rating=(2350, 125)), \
player_factory("Rhiza", player_id=5, ladder_rating=(1200, 175)), \
player_factory("Newbie", player_id=6, ladder_rating=(1200, 175), ladder_games=config.NEWBIE_MIN_GAMES - 1)
player_factory("Brackman", player_id=2, ladder_rating=(1200, 72)), \
player_factory("Zoidberg", player_id=3, ladder_rating=(1300, 175)), \
player_factory("QAI", player_id=4, ladder_rating=(2350, 125)), \
player_factory("Rhiza", player_id=5, ladder_rating=(1200, 175)), \
player_factory("Newbie", player_id=6, ladder_rating=(1200, 175), ladder_games=config.NEWBIE_MIN_GAMES - 1)


@pytest.fixture
def matchmaker_players_all_match(player_factory):
return player_factory("Dostya", player_id=1, ladder_rating=(1500, 50)), \
player_factory("Brackman", player_id=2, ladder_rating=(1500, 50)), \
player_factory("Zoidberg", player_id=3, ladder_rating=(1500, 50)), \
player_factory("QAI", player_id=4, ladder_rating=(1500, 50)), \
player_factory("Rhiza", player_id=5, ladder_rating=(1500, 50))
player_factory("Brackman", player_id=2, ladder_rating=(1500, 50)), \
player_factory("Zoidberg", player_id=3, ladder_rating=(1500, 50)), \
player_factory("QAI", player_id=4, ladder_rating=(1500, 50)), \
player_factory("Rhiza", player_id=5, ladder_rating=(1500, 50))


def test_get_game_options_empty(queue_factory):
Expand Down Expand Up @@ -361,8 +361,8 @@ def test_queue_multiple_map_pools(
@pytest.mark.asyncio
async def test_queue_many(matchmaker_queue, player_factory):
p1, p2, p3 = player_factory("Dostya", ladder_rating=(2200, 150)), \
player_factory("Brackman", ladder_rating=(1500, 150)), \
player_factory("Zoidberg", ladder_rating=(1500, 125))
player_factory("Brackman", ladder_rating=(1500, 150)), \
player_factory("Zoidberg", ladder_rating=(1500, 125))

s1 = Search([p1])
s2 = Search([p2])
Expand All @@ -384,8 +384,8 @@ async def test_queue_many(matchmaker_queue, player_factory):
@pytest.mark.asyncio
async def test_queue_race(matchmaker_queue, player_factory):
p1, p2, p3 = player_factory("Dostya", ladder_rating=(2300, 150)), \
player_factory("Brackman", ladder_rating=(2200, 150)), \
player_factory("Zoidberg", ladder_rating=(2300, 125))
player_factory("Brackman", ladder_rating=(2200, 150)), \
player_factory("Zoidberg", ladder_rating=(2300, 125))

async def find_matches():
await asyncio.sleep(0.01)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def test_serialize():
player_id=42,
login="Something",
ratings={
RatingType.GLOBAL: (1234, 68),
RatingType.LADDER_1V1: (1500, 230),
RatingType.GLOBAL: (1234, 68),
RatingType.LADDER_1V1: (1500, 230),
},
clan="TOAST",
game_count={RatingType.GLOBAL: 542}
Expand Down
1 change: 1 addition & 0 deletions tests/utils/mock_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class MockDatabase(FAFDatabase):
Note that right now the server relies on autocommit behaviour sqlalchemy.
Any future manual commit() calls should be mocked here as well.
"""

def __init__(
self,
host: str = "localhost",
Expand Down