From 45d132c5ca457ba871fb4f893496842ba0e0bd56 Mon Sep 17 00:00:00 2001 From: cclecle Date: Sat, 30 Sep 2023 13:16:40 +0100 Subject: [PATCH] fix cod4 boolean handling --- src/pygamecfg/game_cod4.py | 2 +- test/test_cod4.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/pygamecfg/game_cod4.py b/src/pygamecfg/game_cod4.py index 15db995..420c80c 100644 --- a/src/pygamecfg/game_cod4.py +++ b/src/pygamecfg/game_cod4.py @@ -39,7 +39,7 @@ class GameOption_COD4(GameOption): 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" + return "1" if super().format_OT_BOOLEAN(value) is "True" else "0" def close(self) -> None: self.cfgfile.close() diff --git a/test/test_cod4.py b/test/test_cod4.py index ee586ae..76399a1 100644 --- a/test/test_cod4.py +++ b/test/test_cod4.py @@ -61,7 +61,7 @@ class Testtest_cod4(unittest.TestCase): # /!\ 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 + # check if *other* key still there / untouched self.test_normal_READ_sv_mapRotation() def test_defect_READ_net_port_NONEXISTS(self): @@ -74,3 +74,28 @@ class Testtest_cod4(unittest.TestCase): fct_main(["-g", "cod4", "-b", "test/tmp/COD4", "GetOption", "net_port"]) self.assertEqual("132\n", capted_stdout.getvalue()) self.assertEqual("", capted_stderr.getvalue()) + + def test_normal_WRITE_oldschool(self): + with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: + fct_main(["-g", "cod4", "-b", "test/tmp/COD4", "SetOption", "oldschool", "1"]) + # /!\ 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: 1\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", "oldschool"]) + # /!\ 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()) + + with redirect_stdout(StringIO()) as capted_stdout, redirect_stderr(StringIO()) as capted_stderr: + fct_main(["-g", "cod4", "-b", "test/tmp/COD4", "SetOption", "oldschool", "0"]) + # /!\ 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: 0\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", "oldschool"]) + # /!\ add '\n' at the end of the string cause Python terminal newline is always this, regardless Windows / Linux os.linesep + self.assertEqual("0\n", capted_stdout.getvalue()) + self.assertEqual("", capted_stderr.getvalue()) -- 2.47.3