diff --git a/license.rtf b/license.rtf index f89c96dfe..665d2e4da 100644 --- a/license.rtf +++ b/license.rtf @@ -676,4 +676,4 @@ Public License instead of this License. But first, please read\par .\par \par } - \ No newline at end of file + diff --git a/server/api/api_accessor.py b/server/api/api_accessor.py index b2420e83f..36e3c1602 100644 --- a/server/api/api_accessor.py +++ b/server/api/api_accessor.py @@ -17,6 +17,7 @@ class SessionManager: """ Garantor for API access """ + def __init__(self): self.session = None # Instance of session diff --git a/server/broadcast_service.py b/server/broadcast_service.py index 4bdda72cd..d107a42f0 100644 --- a/server/broadcast_service.py +++ b/server/broadcast_service.py @@ -1,3 +1,5 @@ +from typing import TYPE_CHECKING + from aio_pika import DeliveryMode from .config import config @@ -9,6 +11,9 @@ from .player_service import PlayerService from .timing import LazyIntervalTimer +if TYPE_CHECKING: + from server import ServerInstance + @with_logger class BroadcastService(Service): diff --git a/server/exceptions.py b/server/exceptions.py index a36f81b43..b2102d9bb 100644 --- a/server/exceptions.py +++ b/server/exceptions.py @@ -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 @@ -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 @@ -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 diff --git a/server/game_service.py b/server/game_service.py index cc5e7396f..f1323a81b 100644 --- a/server/game_service.py +++ b/server/game_service.py @@ -33,6 +33,7 @@ class GameService(Service): """ Utility class for maintaining lifecycle of games """ + def __init__( self, database: FAFDatabase, diff --git a/server/gameconnection.py b/server/gameconnection.py index 7f03214e0..61838adca 100644 --- a/server/gameconnection.py +++ b/server/gameconnection.py @@ -503,7 +503,7 @@ async def handle_game_state(self, state: str): await self.on_connection_lost() self._mark_dirty() - async def handle_game_ended(self, *args: List[Any]): + async def handle_game_ended(self, *args: List[Any]): """ Signals that the simulation has ended. """ @@ -616,25 +616,25 @@ def __str__(self): COMMAND_HANDLERS = { - "Desync": GameConnection.handle_desync, - "GameState": GameConnection.handle_game_state, - "GameOption": GameConnection.handle_game_option, - "GameMods": GameConnection.handle_game_mods, - "PlayerOption": GameConnection.handle_player_option, - "AIOption": GameConnection.handle_ai_option, - "ClearSlot": GameConnection.handle_clear_slot, - "GameResult": GameConnection.handle_game_result, - "OperationComplete": GameConnection.handle_operation_complete, - "JsonStats": GameConnection.handle_json_stats, - "EnforceRating": GameConnection.handle_enforce_rating, - "TeamkillReport": GameConnection.handle_teamkill_report, - "TeamkillHappened": GameConnection.handle_teamkill_happened, - "GameEnded": GameConnection.handle_game_ended, - "Rehost": GameConnection.handle_rehost, - "Bottleneck": GameConnection.handle_bottleneck, - "BottleneckCleared": GameConnection.handle_bottleneck_cleared, - "Disconnected": GameConnection.handle_disconnected, - "IceMsg": GameConnection.handle_ice_message, - "Chat": GameConnection.handle_chat, - "GameFull": GameConnection.handle_game_full + "Desync": GameConnection.handle_desync, + "GameState": GameConnection.handle_game_state, + "GameOption": GameConnection.handle_game_option, + "GameMods": GameConnection.handle_game_mods, + "PlayerOption": GameConnection.handle_player_option, + "AIOption": GameConnection.handle_ai_option, + "ClearSlot": GameConnection.handle_clear_slot, + "GameResult": GameConnection.handle_game_result, + "OperationComplete": GameConnection.handle_operation_complete, + "JsonStats": GameConnection.handle_json_stats, + "EnforceRating": GameConnection.handle_enforce_rating, + "TeamkillReport": GameConnection.handle_teamkill_report, + "TeamkillHappened": GameConnection.handle_teamkill_happened, + "GameEnded": GameConnection.handle_game_ended, + "Rehost": GameConnection.handle_rehost, + "Bottleneck": GameConnection.handle_bottleneck, + "BottleneckCleared": GameConnection.handle_bottleneck_cleared, + "Disconnected": GameConnection.handle_disconnected, + "IceMsg": GameConnection.handle_ice_message, + "Chat": GameConnection.handle_chat, + "GameFull": GameConnection.handle_game_full } diff --git a/server/games/coop.py b/server/games/coop.py index eea01029d..e556de87a 100644 --- a/server/games/coop.py +++ b/server/games/coop.py @@ -1,5 +1,3 @@ -import asyncio - from .game import Game from .typedefs import FA, GameType, InitMode, ValidityState, Victory diff --git a/server/games/custom_game.py b/server/games/custom_game.py index 077a77625..c71523bc4 100644 --- a/server/games/custom_game.py +++ b/server/games/custom_game.py @@ -1,4 +1,3 @@ -import asyncio import time from server.decorators import with_logger diff --git a/server/games/game.py b/server/games/game.py index 70412ffe6..2b94cc3d3 100644 --- a/server/games/game.py +++ b/server/games/game.py @@ -3,7 +3,17 @@ import logging import time from collections import defaultdict -from typing import Any, Dict, FrozenSet, Iterable, List, Optional, Set, Tuple +from typing import ( + TYPE_CHECKING, + Any, + Dict, + FrozenSet, + Iterable, + List, + Optional, + Set, + Tuple +) import pymysql from sqlalchemy import and_, bindparam @@ -43,6 +53,10 @@ VisibilityState ) +if TYPE_CHECKING: + from server import GameConnection, GameService, GameStatsService + from server.db import FAFDatabase + class GameError(Exception): pass diff --git a/server/ice_servers/nts.py b/server/ice_servers/nts.py index 925ec9efe..7abe1f2b5 100644 --- a/server/ice_servers/nts.py +++ b/server/ice_servers/nts.py @@ -17,6 +17,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 diff --git a/server/ladder_service.py b/server/ladder_service.py index 4049cf5f8..242345af1 100644 --- a/server/ladder_service.py +++ b/server/ladder_service.py @@ -7,7 +7,7 @@ import random import re from collections import defaultdict -from typing import Dict, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple import aiocron from sqlalchemy import and_, func, select, text, true @@ -37,6 +37,9 @@ from .players import Player, PlayerState from .types import GameLaunchOptions, Map, NeroxisGeneratedMap +if TYPE_CHECKING: + from .lobbyconnection import LobbyConnection + @with_logger class LadderService(Service): @@ -44,6 +47,7 @@ class LadderService(Service): Service responsible for managing the 1v1 ladder. Does matchmaking, updates statistics, and launches the games. """ + def __init__( self, database: FAFDatabase, diff --git a/server/lobbyconnection.py b/server/lobbyconnection.py index 37d6b55ad..5095b93c8 100644 --- a/server/lobbyconnection.py +++ b/server/lobbyconnection.py @@ -41,6 +41,7 @@ CoopGame, CustomGame, FeaturedModType, + Game, GameConnectionState, GameState, InitMode, @@ -1065,7 +1066,7 @@ async def command_modvault(self, message): downloads=downloads, date=int(date.timestamp()), uid=uid, name=name, version=version, author=author, ui=ui) await self.send(out) - except: + except BaseException: self._logger.error(f"Error handling table_mod row (uid: {uid})", exc_info=True) elif type == "like": @@ -1091,7 +1092,7 @@ async def command_modvault(self, message): canLike = False else: likers.append(self.player.id) - except: + except BaseException: likers = [] # TODO: Avoid sending all the mod info in the world just because we liked it? diff --git a/server/matchmaker/algorithm/bucket_teams.py b/server/matchmaker/algorithm/bucket_teams.py index c1dc55694..3b115bf1e 100644 --- a/server/matchmaker/algorithm/bucket_teams.py +++ b/server/matchmaker/algorithm/bucket_teams.py @@ -35,7 +35,7 @@ def find( teams, searches_without_team = self._find_teams(searches, team_size) matchmaker1v1 = StableMarriageMatchmaker() - matches, unmatched_searches = matchmaker1v1.find(teams, 1) + matches, unmatched_searches = matchmaker1v1.find(teams, 1) unmatched_searches.extend(searches_without_team) return matches, unmatched_searches diff --git a/server/matchmaker/algorithm/stable_marriage.py b/server/matchmaker/algorithm/stable_marriage.py index 242f40b50..d189909a7 100644 --- a/server/matchmaker/algorithm/stable_marriage.py +++ b/server/matchmaker/algorithm/stable_marriage.py @@ -10,6 +10,7 @@ WeightedGraph = Dict[Search, List[Tuple[Search, float]]] + class StableMarriage(MatchmakingPolicy1v1): def find(self, ranks: WeightedGraph) -> Dict[Search, Search]: """Perform the stable matching algorithm until a maximal stable matching @@ -78,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]]: diff --git a/server/matchmaker/algorithm/team_matchmaker.py b/server/matchmaker/algorithm/team_matchmaker.py index 5ffff56bf..af1e66325 100644 --- a/server/matchmaker/algorithm/team_matchmaker.py +++ b/server/matchmaker/algorithm/team_matchmaker.py @@ -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 [], [] @@ -113,7 +114,7 @@ def pick_neighboring_players(searches: List[Search], index: int, team_size: int) # We need to do this in two steps to ensure that index = 0 gives an empty iterator lower = searches[:index] lower = iter(lower[::-1]) - higher = iter(searches[index+1:]) + higher = iter(searches[index + 1:]) pick_lower = True candidate = searches[index] participants = [candidate] diff --git a/server/matchmaker/matchmaker_queue.py b/server/matchmaker/matchmaker_queue.py index 1d68be625..272563f52 100644 --- a/server/matchmaker/matchmaker_queue.py +++ b/server/matchmaker/matchmaker_queue.py @@ -3,7 +3,16 @@ from collections import OrderedDict from concurrent.futures import CancelledError from datetime import datetime, timezone -from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple +from typing import ( + TYPE_CHECKING, + Any, + Callable, + Dict, + Iterable, + List, + Optional, + Tuple +) import server.metrics as metrics @@ -15,6 +24,9 @@ from .pop_timer import PopTimer from .search import Match, Search +if TYPE_CHECKING: + from server import GameService + MatchFoundCallback = Callable[[Search, Search, "MatchmakerQueue"], Any] diff --git a/server/matchmaker/pop_timer.py b/server/matchmaker/pop_timer.py index b4f83007c..72af3fc3a 100644 --- a/server/matchmaker/pop_timer.py +++ b/server/matchmaker/pop_timer.py @@ -1,13 +1,16 @@ import asyncio from collections import deque from time import time -from typing import Deque +from typing import TYPE_CHECKING, Deque import server.metrics as metrics from ..config import config from ..decorators import with_logger +if TYPE_CHECKING: + from .matchmaker_queue import MatchmakerQueue + @with_logger class PopTimer(object): @@ -25,6 +28,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 diff --git a/server/message_queue_service.py b/server/message_queue_service.py index cb78de59b..3404c3c45 100644 --- a/server/message_queue_service.py +++ b/server/message_queue_service.py @@ -26,6 +26,7 @@ class MessageQueueService(Service): Service handling connection to the message queue and providing an interface to publish messages. """ + def __init__(self) -> None: self._logger.debug("Message queue service created.") self._connection = None diff --git a/server/party_service.py b/server/party_service.py index e35ba2050..79b5d861d 100644 --- a/server/party_service.py +++ b/server/party_service.py @@ -2,7 +2,7 @@ Manages interactions between players and parties """ -from typing import Dict, List, Set +from typing import TYPE_CHECKING, Dict, List, Set from .core import Service from .decorators import with_logger @@ -13,6 +13,9 @@ from .team_matchmaker.player_party import PlayerParty from .timing import at_interval +if TYPE_CHECKING: + from .lobbyconnection import LobbyConnection + @with_logger class PartyService(Service): diff --git a/server/player_service.py b/server/player_service.py index f52040481..c7bf34c11 100644 --- a/server/player_service.py +++ b/server/player_service.py @@ -3,7 +3,7 @@ """ import asyncio -from typing import Optional, Set, ValuesView +from typing import TYPE_CHECKING, Optional, Set, ValuesView import aiocron from sqlalchemy import and_, select @@ -32,6 +32,9 @@ user_group_assignment ) +if TYPE_CHECKING: + from .lobbyconnection import LobbyConnection + @with_logger class PlayerService(Service): diff --git a/server/players.py b/server/players.py index 2688549ad..1aaa6135a 100644 --- a/server/players.py +++ b/server/players.py @@ -5,13 +5,16 @@ from collections import defaultdict from contextlib import suppress from enum import Enum, unique -from typing import Dict, Optional, Union +from typing import TYPE_CHECKING, Dict, Optional, Union from .factions import Faction from .protocol import DisconnectedError from .rating import Leaderboard, PlayerRatings, RatingType from .weakattr import WeakAttribute +if TYPE_CHECKING: + from .lobbyconnection import LobbyConnection + @unique class PlayerState(Enum): diff --git a/server/rating.py b/server/rating.py index 2962cabc0..e36516cad 100644 --- a/server/rating.py +++ b/server/rating.py @@ -137,6 +137,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 diff --git a/server/stats/unit.py b/server/stats/unit.py index 3874df124..727b1b336 100644 --- a/server/stats/unit.py +++ b/server/stats/unit.py @@ -22,17 +22,17 @@ class Unit(Enum): GALACTIC_COLOSSUS = "ual0401" TEMPEST = "uas0401" SALVATION = "xab2307" - #UEF + # UEF MAVOR = "ueb2401" FATBOY = "uel0401" NOVAX_CENTER = "xeb2402" ATLANTIS = "ues0401" - #Cybran + # Cybran SOUL_RIPPER = "ura0401" SCATHIS = "url0401" MONKEYLORD = "url0402" MEGALITH = "xrl0403" - #Sera + # Sera YOLONA_OSS = "xsb2401" AHWASSA = "xsa0402" YTHOTHA = "xsl0401" diff --git a/tests/data/game_stats_ai_game.json b/tests/data/game_stats_ai_game.json index 7ab115fcb..c95cd783a 100644 --- a/tests/data/game_stats_ai_game.json +++ b/tests/data/game_stats_ai_game.json @@ -93,4 +93,4 @@ } } ] -} \ No newline at end of file +} diff --git a/tests/data/game_stats_full_example.json b/tests/data/game_stats_full_example.json index 3f528ba04..b3964b4b9 100644 --- a/tests/data/game_stats_full_example.json +++ b/tests/data/game_stats_full_example.json @@ -847,4 +847,4 @@ } } ] -} \ No newline at end of file +} diff --git a/tests/data/game_stats_no_army_for_user.json b/tests/data/game_stats_no_army_for_user.json index f34a69f2f..5f0b6da02 100644 --- a/tests/data/game_stats_no_army_for_user.json +++ b/tests/data/game_stats_no_army_for_user.json @@ -9,4 +9,4 @@ "name": "SomeoneElse" } ] -} \ No newline at end of file +} diff --git a/tests/data/game_stats_simple_win.json b/tests/data/game_stats_simple_win.json index 110d8f2de..679b42712 100644 --- a/tests/data/game_stats_simple_win.json +++ b/tests/data/game_stats_simple_win.json @@ -95,4 +95,4 @@ } } ] -} \ No newline at end of file +} diff --git a/tests/data/game_stats_single_player.json b/tests/data/game_stats_single_player.json index 1e057092f..61a26aa42 100644 --- a/tests/data/game_stats_single_player.json +++ b/tests/data/game_stats_single_player.json @@ -95,4 +95,4 @@ } } ] -} \ No newline at end of file +} diff --git a/tests/data/uid11255492.log.json b/tests/data/uid11255492.log.json index f6ec4c83e..b71191c00 100644 --- a/tests/data/uid11255492.log.json +++ b/tests/data/uid11255492.log.json @@ -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]]} \ No newline at end of file +{"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]]} diff --git a/tests/integration_tests/test_game.py b/tests/integration_tests/test_game.py index 69b75d5c0..ddcfa6751 100644 --- a/tests/integration_tests/test_game.py +++ b/tests/integration_tests/test_game.py @@ -413,9 +413,9 @@ async def test_partial_game_ended_rates_game(lobby_server, tmp_user): # Set player options await send_player_options( host_proto, - [guest_id, "Army", i+2], - [guest_id, "StartSpot", i+2], - [guest_id, "Color", i+2], + [guest_id, "Army", i + 2], + [guest_id, "StartSpot", i + 2], + [guest_id, "Color", i + 2], [guest_id, "Faction", 1], [guest_id, "Team", 3 if i % 2 == 0 else 2] ) diff --git a/tests/integration_tests/test_oauth_session.py b/tests/integration_tests/test_oauth_session.py index 671e70bf5..46bb9d31a 100644 --- a/tests/integration_tests/test_oauth_session.py +++ b/tests/integration_tests/test_oauth_session.py @@ -34,7 +34,7 @@ def oauth2_server(event_loop): @routes.post("/token") async def token(request): data = await request.post() - return await { + return await { # noqa: W606 "client_credentials": client_credentials, "refresh_token": refresh_token }.get(data.get("grant_type"))(data) diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 6c622a387..363b258f1 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -144,9 +144,9 @@ def add(gameobj: Game, n: int, team: int = None): game = gameobj current = len(game.players) players = [] - for i in range(current, current+n): + for i in range(current, current + n): p = player_factory( - player_id=i+1, + player_id=i + 1, login=f"Player {i + 1}", global_rating=(1500, 500), lobby_connection_spec=None diff --git a/tests/unit_tests/strategies.py b/tests/unit_tests/strategies.py index 25fa04bde..171735ee3 100644 --- a/tests/unit_tests/strategies.py +++ b/tests/unit_tests/strategies.py @@ -72,7 +72,7 @@ def st_searches_list(draw, min_players=1, max_players=10, min_size=0, max_size=3 @st.composite -def st_searches_list_with_player_size(draw, min_players=1, max_players=10, min_size=1, max_size=30): +def st_searches_list_with_player_size(draw, min_players=1, max_players=10, min_size=1, max_size=30): """Strategy for generating a list of Search objects and the max player size""" player_size = draw(st.integers(min_value=min_players, max_value=max_players)) searches_list = draw( @@ -90,7 +90,7 @@ def st_searches_list_with_player_size(draw, min_players=1, max_players=10, min_s @st.composite -def st_searches_list_with_index(draw, min_players=1, max_players=10, min_size=1, max_size=30): +def st_searches_list_with_index(draw, min_players=1, max_players=10, min_size=1, max_size=30): """Strategy for generating a list of Search objects and an index that points at a location in the list""" searches_list = draw( st_searches_list( diff --git a/tests/unit_tests/test_configuration_refresh.py b/tests/unit_tests/test_configuration_refresh.py index a1468e75e..34252dabd 100644 --- a/tests/unit_tests/test_configuration_refresh.py +++ b/tests/unit_tests/test_configuration_refresh.py @@ -54,7 +54,7 @@ async def test_config_refresh_empty_file(monkeypatch): @fast_forward(20) -async def test_configuration_refresh(config_service, monkeypatch): +async def test_configuration_refresh(config_service, monkeypatch): # noqa: F811 assert config.DB_PASSWORD == "banana" monkeypatch.setenv("CONFIGURATION_FILE", "tests/data/refresh_conf.yaml") assert config.DB_PASSWORD == "banana" diff --git a/tests/unit_tests/test_coop_game.py b/tests/unit_tests/test_coop_game.py index 1a4d5dfb3..b9c0d6c2e 100644 --- a/tests/unit_tests/test_coop_game.py +++ b/tests/unit_tests/test_coop_game.py @@ -7,7 +7,7 @@ async def test_create_coop_game(database): - game = CoopGame( + game = CoopGame( # noqa: F841 id_=0, database=database, host=mock.Mock(), diff --git a/tests/unit_tests/test_custom_game.py b/tests/unit_tests/test_custom_game.py index efcbc36cc..a4867dc55 100644 --- a/tests/unit_tests/test_custom_game.py +++ b/tests/unit_tests/test_custom_game.py @@ -82,7 +82,7 @@ async def test_global_rating_higher_after_custom_game_win( old_mean = players[0].ratings[RatingType.GLOBAL][0] await game.launch() - game.launched_at = time.time() - 60*20 # seconds + game.launched_at = time.time() - 60 * 20 # seconds await game.add_result(0, 0, "victory", 5) await game.add_result(0, 1, "defeat", -5) await game.on_game_end() diff --git a/tests/unit_tests/test_game.py b/tests/unit_tests/test_game.py index 0d6647785..e4c871848 100644 --- a/tests/unit_tests/test_game.py +++ b/tests/unit_tests/test_game.py @@ -596,13 +596,14 @@ 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) diff --git a/tests/unit_tests/test_ice.py b/tests/unit_tests/test_ice.py index bf786a4ba..134e0ee0e 100644 --- a/tests/unit_tests/test_ice.py +++ b/tests/unit_tests/test_ice.py @@ -47,12 +47,11 @@ def test_coturn_tokens(coturn_hmac, coturn_hosts, coturn_credentials): host = comparison_list[i]["host"] credential = comparison_list[i]["cred"] assert server["credentialType"] == "token" - assert server["urls"] == \ - [ - f"turn:{host}?transport=tcp", - f"turn:{host}?transport=udp", - f"stun:{host}" - ] + assert server["urls"] == [ + f"turn:{host}?transport=tcp", + f"turn:{host}?transport=udp", + f"stun:{host}" + ] assert server["credential"] == credential assert server["username"] == "124456:faf-test" diff --git a/tests/unit_tests/test_laddergame.py b/tests/unit_tests/test_laddergame.py index 7cba10e52..ebad978e2 100644 --- a/tests/unit_tests/test_laddergame.py +++ b/tests/unit_tests/test_laddergame.py @@ -102,7 +102,7 @@ async def test_rate_game(laddergame: LadderGame, database, game_add_players): before_deviation = {1: 125, 2: 75} await laddergame.launch() - laddergame.launched_at = time.time() - 60*20 + laddergame.launched_at = time.time() - 60 * 20 await laddergame.add_result(0, 0, "victory", 5) await laddergame.add_result(0, 1, "defeat", -5) await laddergame.on_game_end() @@ -151,7 +151,7 @@ async def test_persist_rating_victory(laddergame: LadderGame, database, result_before = await result.fetchall() await laddergame.launch() - laddergame.launched_at = time.time() - 60*20 + laddergame.launched_at = time.time() - 60 * 20 await laddergame.add_result(0, 0, "victory", 5) await laddergame.add_result(0, 1, "defeat", -5) await laddergame.on_game_end() diff --git a/tests/unit_tests/test_lobbyconnection.py b/tests/unit_tests/test_lobbyconnection.py index 34c234469..211b6ba6d 100644 --- a/tests/unit_tests/test_lobbyconnection.py +++ b/tests/unit_tests/test_lobbyconnection.py @@ -487,8 +487,8 @@ 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)) + game1 = mock.create_autospec(Game(42, database, mock.Mock(), game_stats_service)) + game2 = mock.create_autospec(Game(22, database, mock.Mock(), game_stats_service)) games.open_games = [game1, game2] lobbyconnection.send = CoroutineMock() @@ -959,13 +959,13 @@ async def test_command_game_matchmaking_not_party_owner( lobbyconnection.ladder_service.cancel_search.assert_called_once() - + async def test_command_match_ready(lobbyconnection): await lobbyconnection.on_message_received({ "command": "match_ready" }) - + async def test_command_matchmaker_info( lobbyconnection, ladder_service, diff --git a/tests/unit_tests/test_matchmaker_algorithm_stable_marriage.py b/tests/unit_tests/test_matchmaker_algorithm_stable_marriage.py index 081d90f6f..19de544a7 100644 --- a/tests/unit_tests/test_matchmaker_algorithm_stable_marriage.py +++ b/tests/unit_tests/test_matchmaker_algorithm_stable_marriage.py @@ -15,7 +15,7 @@ def player_factory(player_factory): def make( mean: int = 1500, deviation: int = 500, - ladder_games: int = config.NEWBIE_MIN_GAMES+1, + ladder_games: int = config.NEWBIE_MIN_GAMES + 1, name=None ): """Make a player with the given ratings""" diff --git a/tests/unit_tests/test_matchmaker_algorithm_team_matchmaker.py b/tests/unit_tests/test_matchmaker_algorithm_team_matchmaker.py index ca366a0c3..353c0f33d 100644 --- a/tests/unit_tests/test_matchmaker_algorithm_team_matchmaker.py +++ b/tests/unit_tests/test_matchmaker_algorithm_team_matchmaker.py @@ -28,7 +28,7 @@ def player_factory(player_factory): def make( mean: int = 1500, deviation: int = 500, - ladder_games: int = config.NEWBIE_MIN_GAMES+1, + ladder_games: int = config.NEWBIE_MIN_GAMES + 1, name=None ): """Make a player with the given ratings""" diff --git a/tests/unit_tests/test_matchmaker_queue.py b/tests/unit_tests/test_matchmaker_queue.py index 3fcc77522..504c0544f 100644 --- a/tests/unit_tests/test_matchmaker_queue.py +++ b/tests/unit_tests/test_matchmaker_queue.py @@ -27,21 +27,25 @@ 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) + 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) + ) @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)) + 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)) + ) def test_newbie_detection(matchmaker_players): @@ -328,9 +332,11 @@ 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)) + p1, p2, p3 = ( + player_factory("Dostya", ladder_rating=(2200, 150)), + player_factory("Brackman", ladder_rating=(1500, 150)), + player_factory("Zoidberg", ladder_rating=(1500, 125)) + ) s1 = Search([p1]) s2 = Search([p2]) @@ -351,9 +357,11 @@ 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)) + p1, p2, p3 = ( + player_factory("Dostya", ladder_rating=(2300, 150)), + player_factory("Brackman", ladder_rating=(2200, 150)), + player_factory("Zoidberg", ladder_rating=(2300, 125)) + ) async def find_matches(): await asyncio.sleep(0.01) @@ -422,7 +430,7 @@ async def find_matches(): async def test_queue_cancel_while_being_matched_registers_failed_attempt( matchmaker_queue, matchmaker_players_all_match ): - p1, p2, p3, p4, _ = matchmaker_players_all_match + p1, p2, p3, p4, _ = matchmaker_players_all_match searches = [Search([p1]), Search([p2]), Search([p3]), Search([p4])] for search in searches: asyncio.create_task(matchmaker_queue.search(search)) diff --git a/tests/unit_tests/test_players.py b/tests/unit_tests/test_players.py index 5d365c06b..3082eb1c9 100644 --- a/tests/unit_tests/test_players.py +++ b/tests/unit_tests/test_players.py @@ -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} diff --git a/tests/unit_tests/test_profiler.py b/tests/unit_tests/test_profiler.py index 4e8a1e9c5..a278f38ce 100644 --- a/tests/unit_tests/test_profiler.py +++ b/tests/unit_tests/test_profiler.py @@ -145,7 +145,7 @@ async def test_profiler_refresh_cancels(): profiler.refresh() await asyncio.sleep(10) - assert profiler._running == False + assert profiler._running is False assert profiler.profile_count == 0 assert profiler.profiler is None assert enable_mock.call_count < 12 diff --git a/tests/unit_tests/test_protocol.py b/tests/unit_tests/test_protocol.py index 005cfdedf..d87cbf130 100644 --- a/tests/unit_tests/test_protocol.py +++ b/tests/unit_tests/test_protocol.py @@ -183,7 +183,7 @@ async def test_QDataStreamProtocol_encode_ping_pong(): async def test_send_message_simultaneous_writes(unix_protocol): msg = { "command": "test", - "data": "*" * (4096*4) + "data": "*" * (4096 * 4) } # If drain calls are not synchronized, then this will raise an @@ -194,7 +194,7 @@ async def test_send_message_simultaneous_writes(unix_protocol): async def test_send_messages_simultaneous_writes(unix_protocol): msg = { "command": "test", - "data": "*" * (4096*4) + "data": "*" * (4096 * 4) } # If drain calls are not synchronized, then this will raise an @@ -205,7 +205,7 @@ async def test_send_messages_simultaneous_writes(unix_protocol): async def test_send_raw_simultaneous_writes(unix_protocol): - msg = b"*" * (4096*4) + msg = b"*" * (4096 * 4) # If drain calls are not synchronized, then this will raise an # AssertionError from within asyncio diff --git a/tests/utils.py b/tests/utils.py index f20ef8da3..ef4e61ae8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -101,6 +101,7 @@ class MockDatabase: Note that right now the server relies on autocommit behaviour of aiomysql. Any future manual commit() calls should be mocked here as well. """ + def __init__(self, loop): self._loop = loop self.engine = None