From b457a0e48635b41ed70dcd2163445c9d07caaaf1 Mon Sep 17 00:00:00 2001 From: GloriousEggroll Date: Tue, 15 Oct 2024 16:42:55 -0600 Subject: [PATCH] fixup --- protonfixes_test.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/protonfixes_test.py b/protonfixes_test.py index 94fca1b..efe0882 100644 --- a/protonfixes_test.py +++ b/protonfixes_test.py @@ -313,10 +313,13 @@ def testGetGameNameDBFileNotFound(self): os.environ['STORE'] = 'gog' os.environ['WINEPREFIX'] = self.pfx.as_posix() - with patch('builtins.open', side_effect=FileNotFoundError): - func = fix.get_game_name.__wrapped__ # Do not reference the cache - result = func() - self.assertEqual(result, 'UNKNOWN') + with patch('builtins.open', mock_open()) as mocked_open: + mocked_open.side_effect = FileNotFoundError + with patch('fix.log') as mocked_log: # Mock the logger separately + func = fix.get_game_name.__wrapped__ # Do not reference the cache + result = func() + self.assertEqual(result, 'UNKNOWN') + mocked_log.warn.assert_called_with(f"CSV file not found: {os.path.join(self.pfx.as_posix(), 'umu-database.csv')}") def testGetGameNameDbOS(self): """Set UMU_ID and simulate OSError when accessing the CSV file""" @@ -324,10 +327,13 @@ def testGetGameNameDbOS(self): os.environ['STORE'] = 'gog' os.environ['WINEPREFIX'] = self.pfx.as_posix() - with patch('builtins.open', side_effect=OSError): - func = fix.get_game_name.__wrapped__ # Do not reference the cache - result = func() - self.assertEqual(result, 'UNKNOWN') + with patch('builtins.open', mock_open()) as mocked_open: + mocked_open.side_effect = OSError + with patch('fix.log') as mocked_log: # Mock the logger separately + func = fix.get_game_name.__wrapped__ # Do not reference the cache + result = func() + self.assertEqual(result, 'UNKNOWN') + mocked_log.warn.assert_called_with("Game title not found in CSV") def testGetGameNameDbIndex(self): """Set UMU_ID and simulate IndexError with malformed CSV data""" @@ -349,10 +355,13 @@ def testGetGameNameDbUnicode(self): os.environ['STORE'] = 'gog' os.environ['WINEPREFIX'] = self.pfx.as_posix() - with patch('builtins.open', side_effect=UnicodeDecodeError('utf-8', b'', 0, 1, '')): - func = fix.get_game_name.__wrapped__ # Do not reference the cache - result = func() - self.assertEqual(result, 'UNKNOWN') + with patch('builtins.open', mock_open()) as mocked_open: + mocked_open.side_effect = UnicodeDecodeError('utf-8', b'', 0, 1, '') + with patch('fix.log') as mocked_log: # Mock the logger separately + func = fix.get_game_name.__wrapped__ # Do not reference the cache + result = func() + self.assertEqual(result, 'UNKNOWN') + mocked_log.warn.assert_called_with("Game title not found in CSV") def testGetGameNameNoManifest(self): """Do not set UMU_ID and try to get the title from the steam app library"""