From 29ec82d9ec4c81608b4951318fea6e17fadbc720 Mon Sep 17 00:00:00 2001 From: cclecle Date: Sun, 24 Sep 2023 23:18:23 +0100 Subject: [PATCH] fix format implement most used cod4 config keys complete unittest --- src/pygamecfg/__init__.py | 5 +- src/pygamecfg/common_ut.py | 2 +- src/pygamecfg/core_gamecfg.py | 43 ++- src/pygamecfg/game_cod4.py | 515 ++++++++++++++++++++++++++++++++- test/data/COD4/main/server.cfg | 143 +++++++++ test/test_cod4.py | 68 +++++ test/test_ut99.py | 103 ++++--- 7 files changed, 805 insertions(+), 74 deletions(-) create mode 100644 test/data/COD4/main/server.cfg create mode 100644 test/test_cod4.py diff --git a/src/pygamecfg/__init__.py b/src/pygamecfg/__init__.py index 2e38913..bbe4909 100644 --- a/src/pygamecfg/__init__.py +++ b/src/pygamecfg/__init__.py @@ -8,7 +8,7 @@ # # You should have received a copy of the license along with this # work. If not, see . - +# pylint: disable=wrong-import-position """ Main module __init__ file. """ @@ -37,8 +37,7 @@ except PackageNotFoundError: # pragma: no cover warnings.warn('can not read dist.metadata["Name"], assuming local test context, setting it to ') __Name__ = "pygamecfg" -from pygamecfg.core_gamecfg import GameOptions_Factory - +from .core_gamecfg import GameOptions_Factory from . import game_cod4 from . import game_ut99 from . import game_ut2k4 diff --git a/src/pygamecfg/common_ut.py b/src/pygamecfg/common_ut.py index cf79dbb..b307e75 100644 --- a/src/pygamecfg/common_ut.py +++ b/src/pygamecfg/common_ut.py @@ -55,7 +55,7 @@ class GameOption_UT(GameOption): if not self.szOptionName: raise RuntimeError("szOptionName is not set") self.format(value) - self.inifile.setaddkeyvalue(self.szSectionName, self.szKeyName, self.szFormatedValue, self.bForceAdd) + self.inifile.setaddkeyvalue(self.szSectionName, self.szKeyName, value, self.bForceAdd) self.inifile.writefile() def rem(self, value: Union[None, str]) -> None: diff --git a/src/pygamecfg/core_gamecfg.py b/src/pygamecfg/core_gamecfg.py index d5abe22..fbd7d51 100644 --- a/src/pygamecfg/core_gamecfg.py +++ b/src/pygamecfg/core_gamecfg.py @@ -37,7 +37,6 @@ class GameOption(metaclass=ABCMeta): TValueType: OptionType = OptionType.OT_INVALID szDefaultValue: str = "" szHelp: str = "" - szFormatedValue: str = "" def __init__(self, GameRootDir: str, ConfigFileRelPath: Union[None, str] = None): """GameOption constructor. @@ -64,25 +63,43 @@ class GameOption(metaclass=ABCMeta): def close(self) -> None: """user-define close() function (for subclassing)""" - def format(self, value: Union[int, str, float]) -> None: - """standard function to format options before writing it to file (overloadable)""" + def format_OT_STRING(self, value: Union[int, str, float]) -> str: + """ "STRING specific format method (TO file)""" + return str(value) + def format_OT_INTEGER(self, value: Union[int, str, float]) -> str: + """ "INTEGER specific format method (TO file)""" + return str(int(value)) + + def format_OT_BOOLEAN(self, value: Union[int, str, float]) -> str: + """ "BOOLEAN specific format method (TO file)""" + try: + intval = int(value) + return str(bool(intval)) + except ValueError: + return str(True) if str(value).lower() == "true" else str(False) + + def format_OT_FLOAT(self, value: Union[int, str, float]) -> str: + """ "FLOAT specific format method (TO file)""" + return str(float(value)) + + def format(self, value: Union[int, str, float]) -> str: + """standard method to format options before writing it TO file (overloadable)""" + + FormatedValue: str = "" if self.TValueType == OptionType.OT_STRING: - self.szFormatedValue = str(value) + FormatedValue = self.format_OT_STRING(value) elif self.TValueType == OptionType.OT_INTEGER: - self.szFormatedValue = str(int(value)) + FormatedValue = self.format_OT_INTEGER(value) elif self.TValueType == OptionType.OT_BOOLEAN: - try: - intval = int(value) - self.szFormatedValue = str(bool(intval)) - except ValueError: - self.szFormatedValue = str(True) if str(value).lower() == "true" else str(False) + FormatedValue = self.format_OT_BOOLEAN(value) elif self.TValueType == OptionType.OT_FLOAT: - self.szFormatedValue = str(float(value)) + FormatedValue = self.format_OT_FLOAT(value) else: raise RuntimeError("Invalid Option TValueType") - print(f"setting option <{self.szOptionName}> to: {self.szFormatedValue}") + print(f"setting option <{self.szOptionName}> to: {FormatedValue}") + return FormatedValue @abstractmethod def set(self, value: str) -> None: @@ -126,7 +143,7 @@ class GameOptions_Factory: for _option in GameOptions_Factory.ar_Options_cls_filtered: if _option.szOptionName == OptionName: with _option(self.GameRootDir, self.ConfigFileRelPath) as _optionInst: - _optionInst.set(value) + _optionInst.set(_optionInst.format(value)) return raise RuntimeError("Option not found") diff --git a/src/pygamecfg/game_cod4.py b/src/pygamecfg/game_cod4.py index be19ac6..5891bad 100644 --- a/src/pygamecfg/game_cod4.py +++ b/src/pygamecfg/game_cod4.py @@ -15,6 +15,7 @@ from typing import Union import re from os.path import join +from os import linesep from .core_gamecfg import GameOptions_Factory_Register, GameOption, OptionType @@ -33,30 +34,52 @@ class GameOption_COD4(GameOption): self.mainConfigFilePath = join(GameRootDir, ConfigFileRelPath) self.cfgfile = open(self.mainConfigFilePath, "r", encoding="utf8") # pylint: disable=consider-using-with + def format_OT_BOOLEAN(self, value: Union[int, str, float]) -> str: + return "1" if bool(value) is True else "0" + def close(self) -> None: self.cfgfile.close() def set(self, value: str) -> None: if not self.szOptionName: raise RuntimeError("szOptionName is not set") - self.format(value) + + FinalValue: str = value if self.bDblQuoted: - value = '"' + value + '"' + FinalValue = '"' + FinalValue + '"' if self.szPrefix: - value = self.szPrefix + " " + self.szKeyName + " " + value + FinalValue = self.szPrefix + " " + self.szKeyName + " " + FinalValue + linesep + + bfound = False + newFile = "" + + regex = r"^\s*" + self.szPrefix + r"\s+" + self.szKeyName + r"\s*(?P.*)" for line in self.cfgfile.readlines(): - if re.search(r"\s+" + self.szPrefix + r"\s+", line): - print(f"found: {line}") + if re.search(regex, line): + if bfound: + print("[warning] Option defined multiple time") + newFile += FinalValue + bfound = True + else: + newFile += line + + if not bfound: + # write new key at the top of the file to be sure we do not erase the map / map_rotate cmd + newFile = value + newFile + + self.cfgfile.close() + with open(self.mainConfigFilePath, "w", encoding="utf8") as ofile: + ofile.write(newFile) + self.cfgfile = open(self.mainConfigFilePath, "r", encoding="utf8") # pylint: disable=consider-using-with def rem(self, value: Union[str, None] = None) -> None: if not self.szOptionName: raise RuntimeError("szOptionName is not set") - regex = r"^\s*" + self.szPrefix + r"\s+" + self.szOptionName + r"\s*(?P.*)" + regex = r"^\s*" + self.szPrefix + r"\s+" + self.szKeyName + r"\s*(?P.*)" bfound = False - newFile = "" for line in self.cfgfile.readlines(): if re.search(regex, line): @@ -78,9 +101,9 @@ class GameOption_COD4(GameOption): raise RuntimeError("szOptionName not set") if self.bDblQuoted: - regex = r"^\s*" + self.szPrefix + r"\s+" + self.szOptionName + r"\s*\"(?P.*)\"" + regex = r"^\s*" + self.szPrefix + r"\s+" + self.szKeyName + r"\s*\"(?P.*)\"" else: - regex = r"^\s*" + self.szPrefix + r"\s+" + self.szOptionName + r"\s*(?P.*)" + regex = r"^\s*" + self.szPrefix + r"\s+" + self.szKeyName + r"\s*(?P.*)" bfound = False for line in self.cfgfile.readlines(): @@ -95,22 +118,484 @@ class GameOption_COD4(GameOption): @GameOptions_Factory_Register -class GameOption_COD4_sv_maxclients(GameOption_COD4): +class GameOption_COD4_Meta_Admin(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "meta_admin" + szKeyName: str = "_Admin" + bDblQuoted: bool = True + szPrefix = "sets" + szDefaultValue = "ServAdmin" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_Meta_Email(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "meta_email" + szKeyName: str = "_Email" + bDblQuoted: bool = True + szPrefix = "sets" + szDefaultValue = "ServEmail" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_Meta_Website(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "meta_website" + szKeyName: str = "_Website" + bDblQuoted: bool = True + szPrefix = "sets" + szDefaultValue = "ServWebsite" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_Meta_Location(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "meta_location" + szKeyName: str = "_Location" + bDblQuoted: bool = True + szPrefix = "sets" + szDefaultValue = "ServLocation" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_Meta_Maps(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "meta_maps" + szKeyName: str = "_Maps" + bDblQuoted: bool = True + szPrefix = "sets" + szDefaultValue = "" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_Meta_Gametype(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "meta_gametype" + szKeyName: str = "_Gametype" + bDblQuoted: bool = True + szPrefix = "sets" + szDefaultValue = "" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_Cod4x_AuthToken(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "cod4x_authtoken" + szKeyName: str = "sv_authtoken" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "" + szHelp = "Cod4x personnal auth token" + + +@GameOptions_Factory_Register +class GameOption_COD4_Hostname(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "hostname" + szKeyName: str = "sv_hostname" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "" + szHelp = "Server Hostname" + + +@GameOptions_Factory_Register +class GameOption_COD4_MOTD(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "motd" + szKeyName: str = "g_motd" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "Welcome" + szHelp = "Server Message Of The Day" + + +@GameOptions_Factory_Register +class GameOption_COD4_dedicated(GameOption_COD4): TValueType = OptionType.OT_INTEGER - szOptionName: str = "sv_maxclients" + szOptionName: str = "dedicated" + szKeyName: str = "dedicated" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "2" + szHelp = """0 = Listen, 1 = LAN, 2 = Internet ( you probably want 2 )""" + + +@GameOptions_Factory_Register +class GameOption_COD4_RCON_password(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "rcon_password" + szKeyName: str = "rcon_password" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "" + szHelp = "password for remote access, leave empty to deactivate, min 8 characters" + + +@GameOptions_Factory_Register +class GameOption_COD4_game_password(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "game_password" + szKeyName: str = "g_password" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "" + szHelp = "join password, leave empty to deactivate" + + +@GameOptions_Factory_Register +class GameOption_COD4_nb_private_clients(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "nb_privateClients" + szKeyName: str = "sv_privateClients" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "3" + szHelp = """Private Clients, number of slots that can only be changed with a password""" + + +@GameOptions_Factory_Register +class GameOption_COD4_private_password(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "private_password" + szKeyName: str = "sv_privatePassword" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "" + szHelp = "the password to join private slots" + + +@GameOptions_Factory_Register +class GameOption_COD4_maxclients(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "maxclients" szKeyName: str = "sv_maxclients" bDblQuoted: bool = True szPrefix = "set" szDefaultValue = "12" - szHelp = "Maximum client number" + szHelp = """Maximum client number""" @GameOptions_Factory_Register -class GameOption_COD4_sv_mapRotation(GameOption_COD4): +class GameOption_COD4_logsync(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "logsync" + szKeyName: str = "g_logsync" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "2" + szHelp = """0=no log, 1=buffered, 2=continuous, 3=append""" + + +@GameOptions_Factory_Register +class GameOption_COD4_enable_logfile(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "enable_logfile" + szKeyName: str = "logfile" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "1" + szHelp = """0 = NO log, 1 = log file enabled""" + + +@GameOptions_Factory_Register +class GameOption_COD4_logfile(GameOption_COD4): TValueType = OptionType.OT_STRING - szOptionName: str = "sv_mapRotation" + szOptionName: str = "logfile" + szKeyName: str = "g_log" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "games_mp.log" + szHelp = "Name of log file, default is games_mp.log" + + +@GameOptions_Factory_Register +class GameOption_COD4_enable_logdamage(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "enable_logdamage" + szKeyName: str = "sv_log_damage" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "1" + szHelp = """0 = NO logdamage, 1 = logdamage enabled""" + + +@GameOptions_Factory_Register +class GameOption_COD4_statusfile(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "statusfile" + szKeyName: str = "sv_statusfile" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "serverstatus.xml" + szHelp = "writes an xml serverstatus to disc, leave empty to disable" + + +@GameOptions_Factory_Register +class GameOption_COD4_ney_port(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "net_port" + szKeyName: str = "net_port" + bDblQuoted: bool = False + szPrefix = "set" + szDefaultValue = "28960" + szHelp = """network port""" + + +@GameOptions_Factory_Register +class GameOption_COD4_maxRate(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "maxRate" + szKeyName: str = "sv_maxRate" + bDblQuoted: bool = False + szPrefix = "set" + szDefaultValue = "25000" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_minPing(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "minPing" + szKeyName: str = "sv_minPing" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "0" + szHelp = "minimal ping [ms] for a player to join the server" + + +@GameOptions_Factory_Register +class GameOption_COD4_maxPing(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "maxPing" + szKeyName: str = "sv_maxPing" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "350" + szHelp = "maximal ping [ms] for a player to join the server" + + +@GameOptions_Factory_Register +class GameOption_COD4_randomMapRotation(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "randomMapRotation" + szKeyName: str = "sv_randomMapRotation" + bDblQuoted: bool = False + szPrefix = "set" + szDefaultValue = "1" + szHelp = """0 = sv_mapRotation is randomized, 1 = sequential order of sv_mapRotation""" + + +@GameOptions_Factory_Register +class GameOption_COD4_teambalance(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "teambalance" + szKeyName: str = "scr_teambalance" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "1" + szHelp = "auto-teambalance //0 = no, 1 = yes" + + +@GameOptions_Factory_Register +class GameOption_COD4_team_fftype(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "team_fftype" + szKeyName: str = "scr_team_fftype" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "0" + szHelp = "friendly-fire //0 = off, 1 = on, //2 = reflect damage, 3 = shared damage" + + +@GameOptions_Factory_Register +class GameOption_COD4_enable_hardcore(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "hardcore" + szKeyName: str = "scr_hardcore" + bDblQuoted: bool = False + szPrefix = "set" + szDefaultValue = "0" + szHelp = """Hardcore Mode //0 = off 1 = on""" + + +@GameOptions_Factory_Register +class GameOption_COD4_enable_oldschool(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "oldschool" + szKeyName: str = "scr_oldschool" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "0" + szHelp = """Oldschool Mode //0 = off, 1 = on""" + + +@GameOptions_Factory_Register +class GameOption_COD4_enable_friendlyPlayerCanBlock(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "friendlyPlayerCanBlock" + szKeyName: str = "g_friendlyPlayerCanBlock" + bDblQuoted: bool = False + szPrefix = "set" + szDefaultValue = "1" + szHelp = """1 = player collision between friendly players, 0 = collision between friendly players is disabled""" + + +@GameOptions_Factory_Register +class GameOption_COD4_enable_FFAPlayerCanBlock(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "FFAPlayerCanBlock" + szKeyName: str = "g_FFAPlayerCanBlock" + bDblQuoted: bool = False + szPrefix = "set" + szDefaultValue = "1" + szHelp = """1 = player collision, 0 = collision between players is disabled""" + + +@GameOptions_Factory_Register +class GameOption_COD4_DM_scorelimit(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "dm_scorelimit" + szKeyName: str = "scr_dm_scorelimit" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "1000" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_DM_timelimit(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "dm_timelimit" + szKeyName: str = "scr_dm_timelimit" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "15" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_DM_roundlimit(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "dm_roundlimit" + szKeyName: str = "scr_dm_roundlimit" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "1" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_TDM_scorelimit(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "tdm_scorelimit" + szKeyName: str = "scr_war_scorelimit" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "2000" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_TDM_timelimit(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "tdm_timelimit" + szKeyName: str = "scr_war_timelimit" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "10" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_TDM_roundlimit(GameOption_COD4): + TValueType = OptionType.OT_INTEGER + szOptionName: str = "tdm_roundlimit" + szKeyName: str = "scr_war_roundlimit" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "1" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_gametype(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "gametype" + szKeyName: str = "g_gametype" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "dm" + szHelp = "gamemode, one of [war, dm, sd, sab, koth]" + + +@GameOptions_Factory_Register +class GameOption_COD4_mapRotation(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "mapRotation" szKeyName: str = "sv_mapRotation" bDblQuoted: bool = True szPrefix = "set" szDefaultValue = "gametype dm map mp_block" - szHelp = "Map rotation list" + szHelp = """Map rotation list""" + + +@GameOptions_Factory_Register +class GameOption_COD4_allowdownloadk(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "allowdownload" + szKeyName: str = "sv_allowdownload" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "1" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_wwwDownload(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "wwwDownload" + szKeyName: str = "sv_wwwDownload" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "1" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_wwwBaseURL(GameOption_COD4): + TValueType = OptionType.OT_STRING + szOptionName: str = "wwwBaseURL" + szKeyName: str = "sv_wwwBaseURL" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_wwwDlDisconnected(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "wwwDlDisconnected" + szKeyName: str = "sv_wwwDlDisconnected" + bDblQuoted: bool = True + szPrefix = "set" + szDefaultValue = "0" + szHelp = "" + + +@GameOptions_Factory_Register +class GameOption_COD4_nosteamnames(GameOption_COD4): + TValueType = OptionType.OT_BOOLEAN + szOptionName: str = "nosteamnames" + szKeyName: str = "sv_nosteamnames" + bDblQuoted: bool = False + szPrefix = "set" + szDefaultValue = "1" + szHelp = "1 = Use names from steam if steam is available" diff --git a/test/data/COD4/main/server.cfg b/test/data/COD4/main/server.cfg new file mode 100644 index 0000000..c91ce60 --- /dev/null +++ b/test/data/COD4/main/server.cfg @@ -0,0 +1,143 @@ +sets _Admin "TestAdmin" +sets _Email "TestEmail@domain.com" +sets _Website "www.TestWebSite.com" +sets _Location "TestLocation" +sets _Maps "TestMap" +sets _Gametype "TestGametype" + +set sv_authtoken "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + +set sv_hostname "TestHostName" +set g_motd "TestMOTD" +set dedicated "2" +set rcon_password "TestRconPwd" +set g_password "TestPwd" +set sv_privateClients "3" +set sv_privatePassword "TestPrivatePassword" +set sv_authorizemode "0" +set sv_showasranked 0 +set sv_maxclients "11" + +set g_logsync "2" +set logfile "1" +set g_log "games_mp.log" +set sv_log_damage "1" +set sv_statusfile "serverstatus.xml" + +set net_port 28960 + + +set sv_minPing "0" +set sv_maxPing "350" +set sv_timeout 40 +set sv_connectTimeout 90 +set sv_zombieTime 2 +set sv_reconnectlimit 5 + + + +set sv_allowAnonymous "0" + + +set g_deadChat "1" +set voice_deadChat "0" +set g_gravity "800" +set sv_disableClientConsole "0" +set scr_teambalance "1" +set scr_team_fftype "0" +set scr_game_spectatetype "2" +set scr_hardcore 0 +set scr_oldschool "0" + +set g_friendlyPlayerCanBlock 1 +set g_FFAPlayerCanBlock 1 + +set scr_drawfriend "1" +set scr_enable_scoretext "1" +set scr_game_allowkillcam "1" +set scr_game_deathpointloss "0" +set scr_game_suicidepointloss "0" +set scr_game_matchstarttime "5" +set scr_game_playerwaittime "0" +set scr_player_forcerespawn "-1" +set scr_player_healthregentime "5" +set scr_player_maxhealth "100" +set scr_player_sprinttime "4" +set scr_game_onlyheadshots "0" +set scr_teamKillPunishCount "3" +set scr_team_teamkillspawndelay "20" +set scr_team_teamkillpointloss "1" +set scr_enable_hiticon "1" + +set scr_dm_scorelimit "1000" +set scr_dm_timelimit "15" +set scr_dm_roundlimit "1" +set scr_dm_numlives "0" +set scr_dm_playerrespawndelay "0" +set scr_dm_waverespawndelay "0" + +set scr_war_scorelimit "2000" +set scr_war_timelimit "10" +set scr_war_roundlimit "1" +set scr_war_numlives "0" +set scr_war_playerrespawndelay "0" +set scr_war_waverespawndelay "0" + +set scr_dom_scorelimit "250" +set scr_dom_timelimit "0" +set scr_dom_numlives "0" +set scr_dom_playerrespawndelay "0" +set scr_dom_roundlimit "1" +set scr_dom_waverespawndelay "0" + +set scr_koth_scorelimit "250" +set scr_koth_timelimit "15" +set koth_kothmode "0" +set koth_capturetime "20" +set koth_spawntime "3" +set scr_koth_numlives "0" +set scr_koth_playerrespawndelay "3" +set scr_koth_roundlimit "1" +set scr_koth_roundswitch "1" +set scr_koth_waverespawndelay "0" +set koth_autodestroytime "60" +set koth_delayPlayer "3" +set koth_destroytime "10" +set koth_spawnDelay "3" + +set scr_sab_scorelimit "2" +set scr_sab_timelimit "10" +set scr_sab_roundswitch "1" +set scr_sab_bombtimer "30" +set scr_sab_planttime "2.5" +set scr_sab_defusetime "5" +set scr_sab_hotpotato "0" +set scr_sab_numlives "0" +set scr_sab_playerrespawndelay "0" +set scr_sab_roundlimit "0" +set scr_sab_waverespawndelay "0" + +set scr_sd_scorelimit "9" +set scr_sd_timelimit "2.5" +set scr_sd_roundswitch "4" +set scr_sd_bombtimer "45" +set scr_sd_planttime "5" +set scr_sd_defusetime "7" +set scr_sd_multibomb "0" +set scr_sd_numlives "1" +set scr_sd_playerrespawndelay "0" +set scr_sd_roundlimit "0" +set scr_sd_waverespawndelay "0" + +set g_gametype "dm" +set sv_mapRotation "gametype dm map mp_backlot gametype dm map mp_bloc gametype dm map mp_bog gametype dm map mp_cargoship gametype dm map mp_citystreets gametype dm map mp_convoy gametype dm map mp_countdown gametype dm map mp_crash gametype dm map mp_crossfire gametype dm map mp_farm gametype dm map mp_overgrown gametype dm map mp_pipeline gametype dm map mp_shipment gametype dm map mp_showdown gametype dm map mp_strike gametype dm map mp_vacant" + + +set sv_allowdownload "1" +set sv_wwwDownload "1" +set sv_wwwBaseURL "http://TestRedirect/" +set sv_wwwDlDisconnected "0" + +set sv_nosteamnames 1 + +map_rotate diff --git a/test/test_cod4.py b/test/test_cod4.py new file mode 100644 index 0000000..dd8bc4b --- /dev/null +++ b/test/test_cod4.py @@ -0,0 +1,68 @@ +# pygamecfg (c) by chacha +# +# pygamecfg is licensed under a +# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License. +# +# You should have received a copy of the license along with this +# work. If not, see . + +import unittest +from os import linesep, path, chdir +from io import StringIO +from contextlib import redirect_stdout, redirect_stderr +from pathlib import Path +import glob +import shutil + +from src import pygamecfg +from src.pygamecfg.__main__ import fct_main + +testdir_path = Path(__file__).parent.resolve() +chdir(testdir_path.parent.resolve()) + + +class Testtest_cod4(unittest.TestCase): + def tearDown(self) -> None: + self.CleanTmp() + + def setUp(self) -> None: + self.CleanTmp() + + def CleanTmp(self): + # remove any file in tmp dir, except .keep + if path.exists(testdir_path / "tmp"): + shutil.rmtree(testdir_path / "tmp") + shutil.copytree(testdir_path / "data", testdir_path / "tmp") + print("======================") + + def test_normal_READ_sv_maxclients(self): + with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: + fct_main(["-g", "cod4", "-b", "test/tmp/COD4", "GetOption", "maxclients"]) + # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep + self.assertEqual("11\n", capted_stdout.getvalue()) + self.assertEqual("", capted_stderr.getvalue()) + + def test_normal_READ_sv_mapRotation(self): + with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: + fct_main(["-g", "cod4", "-b", "test/tmp/COD4", "GetOption", "mapRotation"]) + # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep + self.assertEqual( + "gametype dm map mp_backlot gametype dm map mp_bloc gametype dm map mp_bog gametype dm map mp_cargoship gametype dm map mp_citystreets gametype dm map mp_convoy gametype dm map mp_countdown gametype dm map mp_crash gametype dm map mp_crossfire gametype dm map mp_farm gametype dm map mp_overgrown gametype dm map mp_pipeline gametype dm map mp_shipment gametype dm map mp_showdown gametype dm map mp_strike gametype dm map mp_vacant\n", + capted_stdout.getvalue(), + ) + self.assertEqual("", capted_stderr.getvalue()) + + def test_normal_WRITE_sv_maxclients(self): + with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: + fct_main(["-g", "cod4", "-b", "test/tmp/COD4", "SetOption", "maxclients", "17"]) + # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep + self.assertEqual("setting option to: 17\n", capted_stdout.getvalue()) + self.assertEqual("", capted_stderr.getvalue()) + + with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: + fct_main(["-g", "cod4", "-b", "test/tmp/COD4", "GetOption", "maxclients"]) + # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep + self.assertEqual("17\n", capted_stdout.getvalue()) + self.assertEqual("", capted_stderr.getvalue()) + # check if other key still there / untouched + self.test_normal_READ_sv_mapRotation() diff --git a/test/test_ut99.py b/test/test_ut99.py index b650efe..b77443e 100644 --- a/test/test_ut99.py +++ b/test/test_ut99.py @@ -7,18 +7,37 @@ # work. If not, see . import unittest -from os import linesep +from os import linesep, path, chdir from io import StringIO from contextlib import redirect_stdout, redirect_stderr +from pathlib import Path +import glob +import shutil from src import pygamecfg from src.pygamecfg.__main__ import fct_main +testdir_path = Path(__file__).parent.resolve() +chdir(testdir_path.parent.resolve()) + class Testtest_ut99(unittest.TestCase): + def tearDown(self) -> None: + self.CleanTmp() + + def setUp(self) -> None: + self.CleanTmp() + shutil.copytree(testdir_path / "data", testdir_path / "tmp") + print("======================") + + def CleanTmp(self): + # remove any file in tmp dir, except .keep + if path.exists(testdir_path / "tmp"): + shutil.rmtree(testdir_path / "tmp") + def test_normal_ServerPackages(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "ServerPackages"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "ServerPackages"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual( "['SoldierSkins', 'CommandoSkins', 'FCommandoSkins', 'SGirlSkins', 'BossSkins', 'Botpack']\n", capted_stdout.getvalue() @@ -27,7 +46,7 @@ class Testtest_ut99(unittest.TestCase): def test_normal_ServerActors(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "ServerActors"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "ServerActors"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual( "['IpDrv.UdpBeacon', 'IpServer.UdpServerQuery', 'IpServer.UdpServerUplink MasterServerAddress=unreal.epicgames.com MasterServerPort=27900', 'IpServer.UdpServerUplink MasterServerAddress=master0.gamespy.com MasterServerPort=27900', 'IpServer.UdpServerUplink MasterServerAddress=master.mplayer.com MasterServerPort=27900', 'UWeb.WebServer']\n", @@ -37,273 +56,273 @@ class Testtest_ut99(unittest.TestCase): def test_normal_Port(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "Port"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "Port"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("7777\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_Map(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "Map"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "Map"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("Index.unr\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_GameType(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "GameType"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "GameType"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("Botpack.DeathMatchPlus\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_HostName(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "HostName"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "HostName"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("Test Server Name FULL\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MOTD(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MOTD"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MOTD"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("TestMOTDLine1\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MOTD2(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MOTD2"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MOTD2"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("TestMOTDLine2\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MOTD3(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MOTD3"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MOTD3"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("TestMOTDLine3\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MOTD4(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MOTD4"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MOTD4"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("TestMOTDLine4\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_AdminEmail(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "AdminEmail"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "AdminEmail"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("TestAdminName@test.com\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_AdminName(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "AdminName"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "AdminName"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("TestAdminName\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_HTTPDownloadServer(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "HTTPDownloadServer"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "HTTPDownloadServer"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("http://uz.ut-files.com/\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MaxClientRate(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MaxClientRate"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MaxClientRate"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("20000\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_NetServerMaxTickRate(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "NetServerMaxTickRate"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "NetServerMaxTickRate"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("20\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_LanServerMaxTickRate(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "LanServerMaxTickRate"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "LanServerMaxTickRate"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("35\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_AdminPassword(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "AdminPassword"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "AdminPassword"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("TestAdminPwd\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_GamePassword(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "GamePassword"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "GamePassword"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("TestPwd\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MaxPlayers(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MaxPlayers"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MaxPlayers"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("4\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MaxSpectators(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MaxSpectators"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MaxSpectators"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("1\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_AS_TimeLimit(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "AS_TimeLimit"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "AS_TimeLimit"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("123\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_DOM_TimeLimit(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "DOM_TimeLimit"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "DOM_TimeLimit"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("423\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_CTF_TimeLimit(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "CTF_TimeLimit"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "CTF_TimeLimit"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("223\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_DM_TimeLimit(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "DM_TimeLimit"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "DM_TimeLimit"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("323\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_GoalTeamScore(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "GoalTeamScore"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "GoalTeamScore"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("30\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MaxTeamSize(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MaxTeamSize"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MaxTeamSize"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("4\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_DM_FragLimit(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "DM_FragLimit"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "DM_FragLimit"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("321\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_ServerLogName(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "ServerLogName"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "ServerLogName"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("server.log\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_WebServer(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "WebServer"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "WebServer"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("9999\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_TournamentMode(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "TournamentMode"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "TournamentMode"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("False\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_InitialBots(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "InitialBots"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "InitialBots"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("7\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_MinPlayers(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "MinPlayers"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "MinPlayers"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("11\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_AS_UseTranslocator(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "AS_UseTranslocator"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "AS_UseTranslocator"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("True\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_CTF_UseTranslocator(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "CTF_UseTranslocator"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "CTF_UseTranslocator"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("True\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_DM_UseTranslocator(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "DM_UseTranslocator"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "DM_UseTranslocator"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("False\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_DOM_UseTranslocator(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "DOM_UseTranslocator"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "DOM_UseTranslocator"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("True\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_CTF_ForceRespawn(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "CTF_ForceRespawn"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "CTF_ForceRespawn"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("False\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_DM_ForceRespawn(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "DM_ForceRespawn"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "DM_ForceRespawn"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("True\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_DOM_ForceRespawn(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "DOM_ForceRespawn"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "DOM_ForceRespawn"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("False\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_AS_ForceRespawn(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "GetOption", "AS_ForceRespawn"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "GetOption", "AS_ForceRespawn"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("True\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) def test_normal_customcfgfile_HostName(self): with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: - fct_main(["-g", "ut99", "-b", "test/data/UT99", "-c", "System/UT99.ini", "GetOption", "HostName"]) + fct_main(["-g", "ut99", "-b", "test/tmp/UT99", "-c", "System/UT99.ini", "GetOption", "HostName"]) # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep self.assertEqual("Alt Serv Name FULL\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue())