Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
GloriousEggroll committed Oct 15, 2024
1 parent d77c5b2 commit b457a0e
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions protonfixes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,27 @@ 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"""
os.environ['UMU_ID'] = 'umu-35140'
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"""
Expand All @@ -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"""
Expand Down

0 comments on commit b457a0e

Please sign in to comment.