Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests #64

Merged
merged 15 commits into from
Apr 20, 2024
5 changes: 4 additions & 1 deletion .github/workflows/umu-protonfixes.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: umu-protonfixes workflow
name: umu-protonfixes

on:
push:
Expand Down Expand Up @@ -33,3 +33,6 @@ jobs:
- name: Lint with Pylint
run: |
bash tools/lint.sh
- name: Test with unittest
run: |
python protonfixes_test.py
5 changes: 4 additions & 1 deletion checks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
""" Run some tests and generate warnings for proton configuration issues
"""

from .logger import log
try:
from .logger import log
except ImportError:
from logger import log


def esync_file_limits() -> bool:
Expand Down
6 changes: 5 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"""
import os
from configparser import ConfigParser
from .logger import log
try:
from .logger import log
except ImportError:
from logger import log


CONF_FILE = '~/.config/protonfixes/config.ini'
DEFAULT_CONF = '''
Expand Down
54 changes: 31 additions & 23 deletions fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
import sys
import urllib
import json

from functools import lru_cache
from importlib import import_module
from .util import check_internet
from .checks import run_checks
from .logger import log
from . import config

try:
from . import config
from .util import check_internet
from .checks import run_checks
from .logger import log
except ImportError:
import config
from util import check_internet
from checks import run_checks
from logger import log



@lru_cache
Expand All @@ -37,7 +44,7 @@ def get_game_id() -> str:
def get_game_name() -> str:
""" Trys to return the game name from environment variables
"""
if 'UMU_ID' in os.environ:
if os.environ.get('UMU_ID'):
if os.path.isfile(os.environ['WINEPREFIX'] + '/game_title'):
with open(os.environ['WINEPREFIX'] + '/game_title', 'r', encoding='utf-8') as file:
return file.readline()
Expand Down Expand Up @@ -68,22 +75,19 @@ def get_game_name() -> str:
log.debug(f'IndexError occurred: {ex}')
except UnicodeDecodeError as ex:
log.debug(f'UnicodeDecodeError occurred: {ex}')
else:
try:
game_library = re.findall(r'.*/steamapps', os.environ['PWD'], re.IGNORECASE)[-1]
game_manifest = os.path.join(game_library, f'appmanifest_{get_game_id()}.acf')

with io.open(game_manifest, 'r', encoding='utf-8') as appmanifest:
for xline in appmanifest.readlines():
if 'name' in xline.strip():
name = re.findall(r'"[^"]+"', xline, re.UNICODE)[-1]
return name
except OSError:
pass
except IndexError:
pass
except UnicodeDecodeError:
pass
return 'UNKNOWN'
try:
log.debug('UMU_ID is not in environment')
game_library = re.findall(r'.*/steamapps', os.environ['PWD'], re.IGNORECASE)[-1]
game_manifest = os.path.join(game_library, f'appmanifest_{get_game_id()}.acf')

with io.open(game_manifest, 'r', encoding='utf-8') as appmanifest:
for xline in appmanifest.readlines():
if 'name' in xline.strip():
name = re.findall(r'"[^"]+"', xline, re.UNICODE)[-1]
return name
except (OSError, IndexError, UnicodeDecodeError):
pass

return 'UNKNOWN'

Expand All @@ -108,7 +112,11 @@ def get_store_name(store: str) -> str:
def get_module_name(game_id: str, default: bool = False, local: bool = False) -> str:
""" Creates the name of a gamefix module, which can be imported
"""
store = os.environ.get('STORE').lower() if os.environ.get('STORE') else 'steam'
store = 'umu'
if game_id.isnumeric():
store = 'steam'
elif os.environ.get('STORE'):
store = os.environ.get('STORE').lower()

if store != 'steam':
log.info(f'Non-steam game {get_game_name()} ({game_id})')
Expand Down
Loading