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 27f7aaa commit d77c5b2
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions protonfixes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,78 +289,79 @@ def testGetGameName(self):
os.environ['UMU_ID'] = self.game_id
os.environ['WINEPREFIX'] = self.pfx.as_posix()
self.pfx.joinpath('game_title').touch()
result = fix.get_game_name()
func = fix.get_game_name.__wrapped__ # Do not reference the cache
result = func()
self.assertFalse(result, 'Expected an empty string')

def testGetGameNameDB(self):
"""Set UMU_ID and access umu database"""
os.environ['UMU_ID'] = 'umu-35140'
os.environ['STORE'] = 'gog'
os.environ['WINEPREFIX'] = str(self.pfx) # Convert PosixPath to string
os.environ['WINEPREFIX'] = self.pfx.as_posix()

# Mock CSV content
csv_content = """Batman: Arkham Asylum Game of the Year Edition,gog,1482504285,umu-35140,,"""

with patch('builtins.open', mock_open(read_data=csv_content)):
func = fix.get_game_name
func = fix.get_game_name.__wrapped__ # Do not reference the cache
result = func()
self.assertEqual(result, 'Batman: Arkham Asylum Game of the Year Edition')

def testGetGameNameDBFileNotFound(self):
"""Set UMU_ID and simulate FileNotFoundError for the CSV file"""
os.environ['UMU_ID'] = 'umu-35140'
os.environ['STORE'] = 'gog'
os.environ['WINEPREFIX'] = str(self.pfx)
os.environ['WINEPREFIX'] = self.pfx.as_posix()

with patch('builtins.open', side_effect=FileNotFoundError):
func = fix.get_game_name
func = fix.get_game_name.__wrapped__ # Do not reference the cache
result = func()
self.assertEqual(result, 'UNKNOWN')

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'] = str(self.pfx)
os.environ['WINEPREFIX'] = self.pfx.as_posix()

with patch('builtins.open', side_effect=OSError):
func = fix.get_game_name
func = fix.get_game_name.__wrapped__ # Do not reference the cache
result = func()
self.assertEqual(result, 'UNKNOWN')

def testGetGameNameDbIndex(self):
"""Set UMU_ID and simulate IndexError with malformed CSV data"""
os.environ['UMU_ID'] = 'umu-35140'
os.environ['STORE'] = 'gog'
os.environ['WINEPREFIX'] = str(self.pfx)
os.environ['WINEPREFIX'] = self.pfx.as_posix()

# Mock CSV content with missing columns
csv_content = """Batman: Arkham Asylum Game of the Year Edition,gog"""

with patch('builtins.open', mock_open(read_data=csv_content)):
func = fix.get_game_name
func = fix.get_game_name.__wrapped__ # Do not reference the cache
result = func()
self.assertEqual(result, 'UNKNOWN')

def testGetGameNameDbUnicode(self):
"""Set UMU_ID and simulate UnicodeDecodeError when reading the CSV file"""
os.environ['UMU_ID'] = 'umu-35140'
os.environ['STORE'] = 'gog'
os.environ['WINEPREFIX'] = str(self.pfx)
os.environ['WINEPREFIX'] = self.pfx.as_posix()

with patch('builtins.open', side_effect=UnicodeDecodeError('utf-8', b'', 0, 1, '')):
func = fix.get_game_name
func = fix.get_game_name.__wrapped__ # Do not reference the cache
result = func()
self.assertEqual(result, 'UNKNOWN')

def testGetGameNameNoManifest(self):
"""Do not set UMU_ID and try to get the title from the steam app library"""
os.environ['SteamAppId'] = '1628350'
os.environ['WINEPREFIX'] = str(self.pfx)
os.environ['WINEPREFIX'] = self.pfx.as_posix()
os.environ['PWD'] = os.environ['WINEPREFIX']
steamapps = os.path.join(self.pfx, 'steamapps')
steamapps = self.pfx.joinpath('steamapps')
os.makedirs(steamapps, exist_ok=True)
func = fix.get_game_name
func = fix.get_game_name.__wrapped__ # Do not reference the cache
result = func()
self.assertEqual(result, 'UNKNOWN')

Expand Down

0 comments on commit d77c5b2

Please sign in to comment.