Skip to content

Commit

Permalink
whoops, might wanna fix the rest of the title check tests too..
Browse files Browse the repository at this point in the history
  • Loading branch information
GloriousEggroll committed Oct 15, 2024
1 parent e3b259c commit 7e08906
Showing 1 changed file with 31 additions and 64 deletions.
95 changes: 31 additions & 64 deletions protonfixes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,94 +310,61 @@ def testGetGameNameDB(self):
result = func()
self.assertEqual(result, 'Batman: Arkham Asylum Game of the Year Edition')

def testGetGameNameDBTimeout(self):
"""Set UMU_ID and access umu database
Mock the TimeoutError
"""
def testGetGameNameDBFileNotFound(self):
"""Set UMU_ID and simulate FileNotFoundError for the CSV file"""
os.environ['UMU_ID'] = 'umu-35140'
os.environ['WINEPREFIX'] = self.pfx.as_posix()
# Mock a valid umu db response
with (
patch.object(fix, 'check_internet', return_value=True),
patch.object(urllib.request, 'urlopen') as mock_function,
):
mock_function.side_effect = TimeoutError
func = fix.get_game_name.__wrapped__ # Do not reference the cache
os.environ['STORE'] = 'gog'
os.environ['WINEPREFIX'] = self.pfx

with patch('builtins.open', side_effect=FileNotFoundError):
func = fix.get_game_name
result = func()
self.assertEqual(result, 'UNKNOWN')

def testGetGameNameDbOS(self):
"""Set UMU_ID and access umu database
Mock the OSError, which only shown if debugging is enabled
"""
"""Set UMU_ID and simulate OSError when accessing the CSV file"""
os.environ['UMU_ID'] = 'umu-35140'
os.environ['WINEPREFIX'] = self.pfx.as_posix()
os.environ['DEBUG'] = '1'
# Mock a valid umu db response
with (
patch.object(fix, 'check_internet', return_value=True),
patch.object(urllib.request, 'urlopen') as mock_function,
):
mock_function.side_effect = OSError
func = fix.get_game_name.__wrapped__ # Do not reference the cache
os.environ['STORE'] = 'gog'
os.environ['WINEPREFIX'] = self.pfx

with patch('builtins.open', side_effect=OSError):
func = fix.get_game_name
result = func()
self.assertEqual(result, 'UNKNOWN')

def testGetGameNameDbIndex(self):
"""Set UMU_ID and access umu database
Mock the IndexError
"""
"""Set UMU_ID and simulate IndexError with malformed CSV data"""
os.environ['UMU_ID'] = 'umu-35140'
os.environ['WINEPREFIX'] = self.pfx.as_posix()
os.environ['DEBUG'] = '1'
# Mock a valid umu db response
with (
patch.object(fix, 'check_internet', return_value=True),
patch.object(urllib.request, 'urlopen') as mock_function,
):
mock_function.side_effect = IndexError
func = fix.get_game_name.__wrapped__ # Do not reference the cache
os.environ['STORE'] = 'gog'
os.environ['WINEPREFIX'] = self.pfx

# 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
result = func()
self.assertEqual(result, 'UNKNOWN')

def testGetGameNameDbUnicode(self):
"""Set UMU_ID and access umu database
Mock the UnicodeError
"""
"""Set UMU_ID and simulate UnicodeDecodeError when reading the CSV file"""
os.environ['UMU_ID'] = 'umu-35140'
os.environ['WINEPREFIX'] = self.pfx.as_posix()
os.environ['DEBUG'] = '1'

def mock_urlopen_raise_error(*args, **kwargs):
raise UnicodeDecodeError('utf-8', b'', 0, 1, '')

# Mock a valid umu db response
with (
patch.object(fix, 'check_internet', return_value=True),
patch.object(urllib.request, 'urlopen') as mock_function,
):
mock_function.side_effect = mock_urlopen_raise_error
func = fix.get_game_name.__wrapped__ # Do not reference the cache
os.environ['STORE'] = 'gog'
os.environ['WINEPREFIX'] = self.pfx

with patch('builtins.open', side_effect=UnicodeDecodeError('utf-8', b'', 0, 1, '')):
func = fix.get_game_name
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
UNKNOWN should be returned because no manifest file will exist in the
test directory
"""
"""Do not set UMU_ID and try to get the title from the steam app library"""
os.environ['SteamAppId'] = '1628350'
os.environ['WINEPREFIX'] = self.pfx.as_posix()
os.environ['WINEPREFIX'] = self.pfx
os.environ['PWD'] = os.environ['WINEPREFIX']
steamapps = self.pfx.joinpath('steamapps')
steamapps.mkdir()
func = fix.get_game_name.__wrapped__ # Do not reference the cache
func = fix.get_game_name
result = func()
self.assertEqual(result, 'UNKNOWN')

Expand Down

0 comments on commit 7e08906

Please sign in to comment.