From 9849c74a970f89a061a34ce9080f6f4c68d397b6 Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Sun, 29 Dec 2024 13:10:35 -0800 Subject: [PATCH] style: update format --- pyproject.toml | 2 +- umu/__main__.py | 8 +- umu/umu_log.py | 4 +- umu/umu_plugins.py | 11 +- umu/umu_proton.py | 57 ++------ umu/umu_run.py | 56 ++------ umu/umu_runtime.py | 51 ++----- umu/umu_test.py | 308 ++++++++++------------------------------ umu/umu_test_plugins.py | 76 +++------- umu/umu_util.py | 8 +- 10 files changed, 148 insertions(+), 433 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2fc0ca28c..0b1060a26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -151,7 +151,7 @@ exclude = [ "subprojects", ] # Same as Black. -line-length = 79 +line-length = 88 indent-width = 4 target-version = "py310" diff --git a/umu/__main__.py b/umu/__main__.py index 21ea6d791..49b87f0cd 100644 --- a/umu/__main__.py +++ b/umu/__main__.py @@ -34,9 +34,7 @@ def parse_args() -> Namespace | tuple[str, list[str]]: # noqa: D103 version=f"umu-launcher version {__version__} ({sys.version})", help="show this version and exit", ) - parser.add_argument( - "--config", help=("path to TOML file (requires Python 3.11+)") - ) + parser.add_argument("--config", help=("path to TOML file (requires Python 3.11+)")) parser.add_argument( "winetricks", help=("run winetricks verbs (requires UMU-Proton or GE-Proton)"), @@ -56,9 +54,7 @@ def parse_args() -> Namespace | tuple[str, list[str]]: # noqa: D103 sys.exit(1) # Exit if argument is not a verb - if sys.argv[1].endswith("winetricks") and not is_winetricks_verb( - sys.argv[2:] - ): + if sys.argv[1].endswith("winetricks") and not is_winetricks_verb(sys.argv[2:]): sys.exit(1) if sys.argv[1:][0] in opt_args: diff --git a/umu/umu_log.py b/umu/umu_log.py index a97b92646..7e29db1b6 100644 --- a/umu/umu_log.py +++ b/umu/umu_log.py @@ -60,9 +60,7 @@ def format(self, record: LogRecord) -> str: # noqa: D102 color = Color.WARNING case _: color = Color.BOLD - record.levelname = ( - f"{color}{Color.BOLD}{record.levelname}{Color.RESET}" - ) + record.levelname = f"{color}{Color.BOLD}{record.levelname}{Color.RESET}" return super().format(record) diff --git a/umu/umu_plugins.py b/umu/umu_plugins.py index 0b61575f8..044695477 100644 --- a/umu/umu_plugins.py +++ b/umu/umu_plugins.py @@ -84,9 +84,7 @@ def _check_env_toml(toml: dict[str, Any]) -> dict[str, Any]: path: Path if key not in toml[table]: - err: str = ( - f"The following key in table '[{table}]' is required: '{key}'" - ) + err: str = f"The following key in table '[{table}]' is required: '{key}'" raise ValueError(err) path = Path(toml[table][key]).expanduser() @@ -95,17 +93,14 @@ def _check_env_toml(toml: dict[str, Any]) -> dict[str, Any]: # can happen is when game options are appended at the end of the exe. # Users should use `launch_args` for game options if key == "exe" and not path.is_file(): - err: str = ( - f"Value for key '{key}' is not a file: '{toml[table][key]}'" - ) + err: str = f"Value for key '{key}' is not a file: '{toml[table][key]}'" raise FileNotFoundError(err) if (key == "proton" and not path.is_dir()) or ( key == "prefix" and not path.is_dir() ): err: str = ( - f"Value for key '{key}' " - f"is not a directory: '{toml[table][key]}'" + f"Value for key '{key}' " f"is not a directory: '{toml[table][key]}'" ) raise NotADirectoryError(err) diff --git a/umu/umu_proton.py b/umu/umu_proton.py index dd1309341..a4107549f 100644 --- a/umu/umu_proton.py +++ b/umu/umu_proton.py @@ -34,9 +34,7 @@ SessionCaches = tuple[CacheTmpfs, CacheSubdir] -def get_umu_proton( - env: dict[str, str], session_pools: SessionPools -) -> dict[str, str]: +def get_umu_proton(env: dict[str, str], session_pools: SessionPools) -> dict[str, str]: """Attempt to use the latest Proton when configured. When $PROTONPATH is not set or $PROTONPATH is 'GE-Proton', the launcher @@ -66,10 +64,7 @@ def get_umu_proton( TemporaryDirectory(dir=UMU_CACHE) as tmpcache, ): tmpdirs: SessionCaches = (Path(tmp), Path(tmpcache)) - if ( - _get_latest(env, STEAM_COMPAT, tmpdirs, assets, session_pools) - is env - ): + if _get_latest(env, STEAM_COMPAT, tmpdirs, assets, session_pools) is env: return env if _get_from_steamcompat(env, STEAM_COMPAT) is env: return env @@ -100,9 +95,7 @@ def _fetch_releases( if os.environ.get("PROTONPATH") == "GE-Proton": repo = "/repos/GloriousEggroll/proton-ge-custom/releases/latest" - resp = http_pool.request( - HTTPMethod.GET.value, f"{url}{repo}", headers=headers - ) + resp = http_pool.request(HTTPMethod.GET.value, f"{url}{repo}", headers=headers) if resp.status != HTTPStatus.OK: return () @@ -153,12 +146,8 @@ def _fetch_proton( hashsum = sha512() # Verify the scheme from Github for resources - if not tar_url.startswith("https:") or not proton_hash_url.startswith( - "https:" - ): - err: str = ( - f"Scheme in URLs is not 'https:': {(tar_url, proton_hash_url)}" - ) + if not tar_url.startswith("https:") or not proton_hash_url.startswith("https:"): + err: str = f"Scheme in URLs is not 'https:': {(tar_url, proton_hash_url)}" raise ValueError(err) # Digest file @@ -233,9 +222,7 @@ def _fetch_proton( HTTPStatus.PARTIAL_CONTENT, HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE, }: - err: str = ( - f"{resp.getheader('Host')} returned the status: {resp.status}" - ) + err: str = f"{resp.getheader('Host')} returned the status: {resp.status}" raise HTTPError(err) # Only write our file if we're resuming or downloading first time @@ -245,9 +232,7 @@ def _fetch_proton( hashsum = write_file_chunks(parts, resp, hashsum) except TimeoutErrorUrllib3: log.error("Aborting Proton install due to network error") - log.info( - "Moving '%s' to cache for future resumption", parts.name - ) + log.info("Moving '%s' to cache for future resumption", parts.name) log.debug("Moving: %s -> %s", parts, cache.parent) move(parts, cache.parent) raise @@ -280,9 +265,7 @@ def _get_from_steamcompat( existing Proton build of that same version will be used """ version: str = ( - "GE-Proton" - if os.environ.get("PROTONPATH") == "GE-Proton" - else "UMU-Proton" + "GE-Proton" if os.environ.get("PROTONPATH") == "GE-Proton" else "UMU-Proton" ) try: @@ -338,9 +321,7 @@ def _get_latest( tarball = assets[1][0] proton = tarball.removesuffix(".tar.gz") version = ( - "GE-Proton" - if os.environ.get("PROTONPATH") == "GE-Proton" - else "UMU-Proton" + "GE-Proton" if os.environ.get("PROTONPATH") == "GE-Proton" else "UMU-Proton" ) # Return if the latest Proton is already installed @@ -434,9 +415,7 @@ def _install_proton( parts: str = f"{tarball}.parts" cached_parts: Path = cache.parent.joinpath(f"{tarball}.parts") version: str = ( - "GE-Proton" - if os.environ.get("PROTONPATH") == "GE-Proton" - else "UMU-Proton" + "GE-Proton" if os.environ.get("PROTONPATH") == "GE-Proton" else "UMU-Proton" ) # TODO: Refactor when differential updates are implemented. @@ -452,26 +431,20 @@ def _install_proton( # Move our file and extract within our cache if cached_parts.is_file(): # In this case, arc is already in cache and checksum'd - log.debug( - "Moving: %s -> %s", cached_parts, cached_parts.with_suffix("") - ) + log.debug("Moving: %s -> %s", cached_parts, cached_parts.with_suffix("")) move(cached_parts, cached_parts.with_suffix("")) # Move the archive to our unique subdir log.debug("Moving: %s -> %s", cached_parts.with_suffix(""), cache) move(cached_parts.with_suffix(""), cache) log.info("Extracting %s...", tarball) # Extract within the subdir - extract_tarfile( - cache.joinpath(tarball), cache.joinpath(tarball).parent - ) + extract_tarfile(cache.joinpath(tarball), cache.joinpath(tarball).parent) else: # The archive is in tmpfs. Remove the parts extension move(tmpfs.joinpath(parts), tmpfs.joinpath(tarball)) move(tmpfs.joinpath(tarball), cache) log.info("Extracting %s...", tarball) - extract_tarfile( - cache.joinpath(tarball), cache.joinpath(tarball).parent - ) + extract_tarfile(cache.joinpath(tarball), cache.joinpath(tarball).parent) # Move decompressed archive to compatibilitytools.d log.info( @@ -482,9 +455,7 @@ def _install_proton( move(cache.joinpath(tarball.removesuffix(".tar.gz")), steam_compat) steam_compat.joinpath("UMU-Latest").unlink(missing_ok=True) - steam_compat.joinpath("UMU-Latest").symlink_to( - tarball.removesuffix(".tar.gz") - ) + steam_compat.joinpath("UMU-Latest").symlink_to(tarball.removesuffix(".tar.gz")) log.debug("Linking: UMU-Latest -> %s", tarball.removesuffix(".tar.gz")) if future: diff --git a/umu/umu_run.py b/umu/umu_run.py index 1bd76648e..700a6d9b4 100755 --- a/umu/umu_run.py +++ b/umu/umu_run.py @@ -65,9 +65,7 @@ def setup_pfx(path: str) -> None: """Prepare a Proton compatible WINE prefix.""" pfx: Path = Path(path).joinpath("pfx").expanduser() - steam: Path = ( - Path(path).expanduser().joinpath("drive_c", "users", "steamuser") - ) + steam: Path = Path(path).expanduser().joinpath("drive_c", "users", "steamuser") # Login name of the user as determined by the password database (pwd) user: str = getpwuid(os.getuid()).pw_name wineuser: Path = Path(path).expanduser().joinpath("drive_c", "users", user) @@ -115,10 +113,7 @@ def check_env( err: str = "Environment variable is empty: WINEPREFIX" raise ValueError(err) - if ( - os.environ.get("UMU_NO_PROTON") != "1" - and "WINEPREFIX" not in os.environ - ): + if os.environ.get("UMU_NO_PROTON") != "1" and "WINEPREFIX" not in os.environ: pfx: Path = Path.home().joinpath("Games", "umu", env["GAMEID"]) pfx.mkdir(parents=True, exist_ok=True) os.environ["WINEPREFIX"] = str(pfx) @@ -142,9 +137,7 @@ def check_env( os.environ.get("PROTONPATH") and Path(STEAM_COMPAT, os.environ["PROTONPATH"]).is_dir() ): - os.environ["PROTONPATH"] = str( - STEAM_COMPAT.joinpath(os.environ["PROTONPATH"]) - ) + os.environ["PROTONPATH"] = str(STEAM_COMPAT.joinpath(os.environ["PROTONPATH"])) # GE-Proton if os.environ.get("PROTONPATH") == "GE-Proton": @@ -173,9 +166,7 @@ def set_env( ) -> dict[str, str]: """Set various environment variables for the Steam Runtime.""" pfx: Path = Path(env["WINEPREFIX"]).expanduser().resolve(strict=True) - protonpath: Path = ( - Path(env["PROTONPATH"]).expanduser().resolve(strict=True) - ) + protonpath: Path = Path(env["PROTONPATH"]).expanduser().resolve(strict=True) # Command execution usage is_cmd: bool = isinstance(args, tuple) # Command execution usage, but client wants to create a prefix. When an @@ -202,9 +193,7 @@ def set_env( # Make an absolute path to winetricks within GE-Proton or UMU-Proton. # The launcher will change to the winetricks parent directory before # creating the subprocess - exe: Path = Path(protonpath, "protonfixes", "winetricks").resolve( - strict=True - ) + exe: Path = Path(protonpath, "protonfixes", "winetricks").resolve(strict=True) env["EXE"] = str(exe) args = (env["EXE"], args[1]) # type: ignore env["STEAM_COMPAT_INSTALL_PATH"] = str(exe.parent) @@ -235,9 +224,7 @@ def set_env( env["STEAM_COMPAT_APP_ID"] = "0" if match(r"^umu-[\d\w]+$", env["UMU_ID"]): - env["STEAM_COMPAT_APP_ID"] = env["UMU_ID"][ - env["UMU_ID"].find("-") + 1 : - ] + env["STEAM_COMPAT_APP_ID"] = env["UMU_ID"][env["UMU_ID"].find("-") + 1 :] env["SteamAppId"] = env["STEAM_COMPAT_APP_ID"] env["SteamGameId"] = env["SteamAppId"] @@ -245,9 +232,7 @@ def set_env( env["WINEPREFIX"] = str(pfx) env["PROTONPATH"] = str(protonpath) env["STEAM_COMPAT_DATA_PATH"] = env["WINEPREFIX"] - env["STEAM_COMPAT_SHADER_PATH"] = ( - f"{env['STEAM_COMPAT_DATA_PATH']}/shadercache" - ) + env["STEAM_COMPAT_SHADER_PATH"] = f"{env['STEAM_COMPAT_DATA_PATH']}/shadercache" env["STEAM_COMPAT_TOOL_PATHS"] = f"{env['PROTONPATH']}:{UMU_LOCAL}" env["STEAM_COMPAT_MOUNTS"] = env["STEAM_COMPAT_TOOL_PATHS"] @@ -385,9 +370,7 @@ def get_window_ids(d: display.Display) -> set[str] | None: try: event: Event = d.next_event() if event.type == X.CreateNotify: - return { - child.id for child in d.screen().root.query_tree().children - } + return {child.id for child in d.screen().root.query_tree().children} except Exception as e: log.exception(e) @@ -436,9 +419,7 @@ def get_gamescope_baselayer_appid( # Intern the atom for GAMESCOPECTRL_BASELAYER_APPID atom = d.get_atom(GamescopeAtom.BaselayerAppId.value) # Get the property value - prop: GetProperty | None = root_primary.get_full_property( - atom, Xatom.CARDINAL - ) + prop: GetProperty | None = root_primary.get_full_property(atom, Xatom.CARDINAL) # For GAMESCOPECTRL_BASELAYER_APPID, the value is a u32 array if prop and prop.value and isinstance(prop.value, array): # Convert data to a Python list for safety @@ -446,9 +427,7 @@ def get_gamescope_baselayer_appid( return baselayer_appid log.debug("%s property not found", GamescopeAtom.BaselayerAppId.value) except Exception as e: - log.error( - "Error getting %s property", GamescopeAtom.BaselayerAppId.value - ) + log.error("Error getting %s property", GamescopeAtom.BaselayerAppId.value) log.exception(e) return None @@ -499,9 +478,7 @@ def set_gamescope_baselayer_appid( ) return d except Exception as e: - log.error( - "Error setting %s property", GamescopeAtom.BaselayerAppId.value - ) + log.error("Error setting %s property", GamescopeAtom.BaselayerAppId.value) log.exception(e) return None @@ -577,8 +554,8 @@ def monitor_baselayer_appid( atom, prop.value, ) - rearranged_gamescope_baselayer = ( - rearrange_gamescope_baselayer_appid(prop.value) + rearranged_gamescope_baselayer = rearrange_gamescope_baselayer_appid( + prop.value ) if rearranged_gamescope_baselayer: @@ -649,9 +626,7 @@ def run_in_steammode(proc: Popen) -> int: xdisplay(":0") as d_primary, xdisplay(":1") as d_secondary, ): - gamescope_baselayer_sequence = get_gamescope_baselayer_appid( - d_primary - ) + gamescope_baselayer_sequence = get_gamescope_baselayer_appid(d_primary) # Dont do window fuckery if we're not inside gamescope if ( gamescope_baselayer_sequence @@ -700,8 +675,7 @@ def run_command(command: tuple[Path | str, ...]) -> int: # Note: STEAM_MULTIPLE_XWAYLANDS is steam mode specific and is # documented to be a legacy env var. is_steammode: bool = ( - is_gamescope_session - and os.environ.get("STEAM_MULTIPLE_XWAYLANDS") == "1" + is_gamescope_session and os.environ.get("STEAM_MULTIPLE_XWAYLANDS") == "1" ) if not command: diff --git a/umu/umu_runtime.py b/umu/umu_runtime.py index 25bf46526..1e3bbd38e 100644 --- a/umu/umu_runtime.py +++ b/umu/umu_runtime.py @@ -145,9 +145,7 @@ def _install_umu( preload_content=False, ) if resp.status != HTTPStatus.OK: - err: str = ( - f"{resp.getheader('Host')} returned the status: {resp.status}" - ) + err: str = f"{resp.getheader('Host')} returned the status: {resp.status}" raise HTTPError(err) # Parse data for the archive digest @@ -165,18 +163,14 @@ def _install_umu( HTTPMethod.GET.value, f"{host}{endpoint}/BUILD_ID.txt{token}" ) if resp.status != HTTPStatus.OK: - err: str = ( - f"{resp.getheader('Host')} returned the status: {resp.status}" - ) + err: str = f"{resp.getheader('Host')} returned the status: {resp.status}" raise HTTPError(err) buildid = resp.data.decode(encoding="utf-8").strip() log.debug("BUILD_ID: %s", buildid) # Extend our variables with the BUILD_ID - log.debug( - "Renaming: %s -> %s", parts, parts.with_suffix(f".{buildid}.parts") - ) + log.debug("Renaming: %s -> %s", parts, parts.with_suffix(f".{buildid}.parts")) parts = parts.with_suffix(f".{buildid}.parts") cached_parts = UMU_CACHE.joinpath(f"{archive}.{buildid}.parts") @@ -204,9 +198,7 @@ def _install_umu( HTTPStatus.PARTIAL_CONTENT, HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE, }: - err: str = ( - f"{resp.getheader('Host')} returned the status: {resp.status}" - ) + err: str = f"{resp.getheader('Host')} returned the status: {resp.status}" raise HTTPError(err) # Download the runtime @@ -216,9 +208,7 @@ def _install_umu( hashsum = write_file_chunks(parts, resp, hashsum) except TimeoutErrorUrllib3: log.error("Aborting steamrt install due to network error") - log.info( - "Moving '%s' to cache for future resumption", parts.name - ) + log.info("Moving '%s' to cache for future resumption", parts.name) move(parts, UMU_CACHE) raise @@ -341,8 +331,7 @@ def _update_umu( _, http_pool = session_pools codename, variant = runtime_ver endpoint: str = ( - f"/steamrt-images-{codename}" - "/snapshots/latest-container-runtime-public-beta" + f"/steamrt-images-{codename}" "/snapshots/latest-container-runtime-public-beta" ) # Create a token and append it to the URL to avoid the Cloudflare cache # Avoids infinite updates to the runtime each launch @@ -356,9 +345,7 @@ def _update_umu( # Find the runtime directory (e.g., sniper_platform_0.20240530.90143) # Assume the directory begins with the variant try: - runtime = max( - file for file in local.glob(f"{codename}*") if file.is_dir() - ) + runtime = max(file for file in local.glob(f"{codename}*") if file.is_dir()) except ValueError: log.critical("*_platform_* directory missing in '%s'", local) log.info("Restoring Runtime Platform...") @@ -366,9 +353,7 @@ def _update_umu( local, runtime_ver, session_pools, - lambda: len( - [file for file in local.glob(f"{codename}*") if file.is_dir()] - ) + lambda: len([file for file in local.glob(f"{codename}*") if file.is_dir()]) > 0, ) return @@ -404,15 +389,11 @@ def _update_umu( local.joinpath("VERSIONS.txt").write_text(platformid) # Fetch the version file - url: str = ( - f"{host}{endpoint}/SteamLinuxRuntime_{codename}.VERSIONS.txt{token}" - ) + url: str = f"{host}{endpoint}/SteamLinuxRuntime_{codename}.VERSIONS.txt{token}" log.debug("Sending request to '%s' for 'VERSIONS.txt'...", url) resp = http_pool.request(HTTPMethod.GET.value, url) if resp.status != HTTPStatus.OK: - log.error( - "%s returned the status: %s", resp.getheader("Host"), resp.status - ) + log.error("%s returned the status: %s", resp.getheader("Host"), resp.status) return # Update our runtime @@ -458,9 +439,7 @@ def check_runtime(src: Path, runtime_ver: RuntimeVersion) -> int: # Find the runtime directory try: - runtime = max( - file for file in src.glob(f"{codename}*") if file.is_dir() - ) + runtime = max(file for file in src.glob(f"{codename}*") if file.is_dir()) except ValueError: log.critical("%s validation failed", variant) log.critical("Could not find *_platform_* in '%s'", src) @@ -532,9 +511,7 @@ def _restore_umu_platformid( for line in file: if line.startswith("BUILD_ID"): # Get the value after 'BUILD_ID=' and strip the quotes - build_id: str = ( - line.removeprefix("BUILD_ID=").rstrip().strip('"') - ) + build_id: str = line.removeprefix("BUILD_ID=").rstrip().strip('"') url = f"/steamrt-images-{codename}" f"/snapshots/{build_id}" break @@ -568,9 +545,7 @@ def _update_umu_platform( ) -> None: _, variant = runtime_ver latest: bytes = sha256(resp.data).digest() - current: bytes = sha256( - local.joinpath("VERSIONS.txt").read_bytes() - ).digest() + current: bytes = sha256(local.joinpath("VERSIONS.txt").read_bytes()).digest() versions: Path = local.joinpath("VERSIONS.txt") lock: FileLock = FileLock(f"{local}/umu.lock") diff --git a/umu/umu_test.py b/umu/umu_test.py index 15efbfdb9..f87d53552 100644 --- a/umu/umu_test.py +++ b/umu/umu_test.py @@ -125,21 +125,15 @@ def setUp(self): # Mock the runtime files Path(self.test_user_share, "sniper_platform_0.20240125.75305").mkdir() - Path( - self.test_user_share, "sniper_platform_0.20240125.75305", "foo" - ).touch() + Path(self.test_user_share, "sniper_platform_0.20240125.75305", "foo").touch() Path(self.test_user_share, "run").touch() Path(self.test_user_share, "run-in-sniper").touch() Path(self.test_user_share, "umu").touch() # Mock pressure vessel - Path(self.test_user_share, "pressure-vessel", "bin").mkdir( - parents=True - ) + Path(self.test_user_share, "pressure-vessel", "bin").mkdir(parents=True) Path(self.test_user_share, "pressure-vessel", "foo").touch() - Path( - self.test_user_share, "pressure-vessel", "bin", "pv-verify" - ).touch() + Path(self.test_user_share, "pressure-vessel", "bin", "pv-verify").touch() # Mock the proton file in the dir self.test_proton_dir.joinpath("proton").touch(exist_ok=True) @@ -233,9 +227,7 @@ def test_restore_umu_cb_false(self): result = umu_runtime._restore_umu( mock_local, mock_runtime_ver, mock_session_pools, mock_cb ) - self.assertTrue( - result is None, f"Expected None, received {result}" - ) + self.assertTrue(result is None, f"Expected None, received {result}") self.assertTrue( mock_cb.mock_calls, "Expected callback to be called", @@ -253,9 +245,7 @@ def test_restore_umu(self): result = umu_runtime._restore_umu( mock_local, mock_runtime_ver, mock_session_pools, mock_cb ) - self.assertTrue( - result is None, f"Expected None, received {result}" - ) + self.assertTrue(result is None, f"Expected None, received {result}") self.assertTrue( mock_cb.mock_calls, "Expected callback to be called", @@ -280,9 +270,7 @@ def test_setup_umu_update(self): mock_runtime_ver, mock_session_pools, ) - self.assertTrue( - result is None, f"Expected None, received {result}" - ) + self.assertTrue(result is None, f"Expected None, received {result}") def test_setup_umu_noupdate(self): """Test setup_umu when setting runtime updates are disabled.""" @@ -304,9 +292,7 @@ def test_setup_umu_noupdate(self): mock_runtime_ver, mock_session_pools, ) - self.assertTrue( - result is None, f"Expected None, received {result}" - ) + self.assertTrue(result is None, f"Expected None, received {result}") def test_setup_umu(self): """Test setup_umu on new install.""" @@ -325,9 +311,7 @@ def test_setup_umu(self): mock_runtime_ver, mock_session_pools, ) - self.assertTrue( - result is None, f"Expected None, received {result}" - ) + self.assertTrue(result is None, f"Expected None, received {result}") def test_restore_umu_platformid_status_err(self): """Test _restore_umu_platformid when the server returns a non-200 status code.""" @@ -366,18 +350,14 @@ def test_restore_umu_platformid_status_err(self): with TemporaryDirectory() as file: mock_runtime_base = Path(file) - mock_osrel_file = mock_runtime_base.joinpath( - "files", "lib", "os-release" - ) + mock_osrel_file = mock_runtime_base.joinpath("files", "lib", "os-release") mock_runtime_base.joinpath("files", "lib").mkdir(parents=True) mock_osrel_file.touch(exist_ok=True) mock_osrel_file.write_text(mock_osrel) result = umu_runtime._restore_umu_platformid( mock_runtime_base, mock_runtime_ver, (mock_tp, mock_hp) ) - self.assertTrue( - result is None, f"Expected None, received {result}" - ) + self.assertTrue(result is None, f"Expected None, received {result}") def test_restore_umu_platformid_osrel_none(self): """Test _restore_umu_platformid when the os-release file is missing.""" @@ -403,9 +383,7 @@ def test_restore_umu_platformid_osrel_none(self): result = umu_runtime._restore_umu_platformid( mock_runtime_base, mock_runtime_ver, (mock_tp, mock_hp) ) - self.assertTrue( - result is None, f"Expected None, received {result}" - ) + self.assertTrue(result is None, f"Expected None, received {result}") def test_restore_umu_platformid_osrel_err(self): """Test _restore_umu_platformid on error parsing os-release.""" @@ -443,17 +421,13 @@ def test_restore_umu_platformid_osrel_err(self): with TemporaryDirectory() as file: mock_runtime_base = Path(file) mock_runtime_base.joinpath("files", "lib").mkdir(parents=True) - mock_osrel_file = mock_runtime_base.joinpath( - "files", "lib", "os-release" - ) + mock_osrel_file = mock_runtime_base.joinpath("files", "lib", "os-release") mock_osrel_file.touch(exist_ok=True) mock_osrel_file.write_text(mock_osrel) result = umu_runtime._restore_umu_platformid( mock_runtime_base, mock_runtime_ver, (mock_tp, mock_hp) ) - self.assertTrue( - result is None, f"Expected None, received {result}" - ) + self.assertTrue(result is None, f"Expected None, received {result}") def test_restore_umu_platformid(self): """Test _restore_umu_platformid.""" @@ -491,9 +465,7 @@ def test_restore_umu_platformid(self): with TemporaryDirectory() as file: mock_runtime_base = Path(file) - mock_osrel_file = mock_runtime_base.joinpath( - "files", "lib", "os-release" - ) + mock_osrel_file = mock_runtime_base.joinpath("files", "lib", "os-release") mock_runtime_base.joinpath("files", "lib").mkdir(parents=True) mock_osrel_file.touch(exist_ok=True) mock_osrel_file.write_text(mock_osrel) @@ -511,9 +483,7 @@ def test_write_file_chunks_none(self): file2.write(os.getrandom(chunk_size)) # Pass a buffered reader as our fake http response umu_util.write_file_chunks(mock_file, file2, hasher) - self.assertTrue( - hasher.digest(), "Expected hashed data > 0, received 0" - ) + self.assertTrue(hasher.digest(), "Expected hashed data > 0, received 0") def test_write_file_chunks(self): """Test write_file_chunks.""" @@ -524,9 +494,7 @@ def test_write_file_chunks(self): file2.write(os.getrandom(chunk_size)) # Pass a buffered reader as our fake http response umu_util.write_file_chunks(mock_file, file2, hasher, chunk_size) - self.assertTrue( - hasher.digest(), "Expected hashed data > 0, received 0" - ) + self.assertTrue(hasher.digest(), "Expected hashed data > 0, received 0") def test_get_gamescope_baselayer_appid_err(self): """Test get_gamescope_baselayer_appid on error. @@ -535,14 +503,10 @@ def test_get_gamescope_baselayer_appid_err(self): GAMESCOPECTRL_BASELAYER_APPID """ mock_display = MagicMock(spec=Display) - mock_display.screen.side_effect = DisplayConnectionError( - mock_display, "foo" - ) + mock_display.screen.side_effect = DisplayConnectionError(mock_display, "foo") result = umu_run.get_gamescope_baselayer_appid(mock_display) - self.assertTrue( - result is None, f"Expected a value, received: {result}" - ) + self.assertTrue(result is None, f"Expected a value, received: {result}") def test_get_gamescope_baselayer_appid(self): """Test get_gamescope_baselayer_appid.""" @@ -559,9 +523,7 @@ def test_get_gamescope_baselayer_appid(self): mock_prop.value = array("I", [1, 2, 3]) result = umu_run.get_gamescope_baselayer_appid(mock_display) - self.assertTrue( - result == [1, 2, 3], f"Expected a value, received: {result}" - ) + self.assertTrue(result == [1, 2, 3], f"Expected a value, received: {result}") def test_set_steam_game_property_err(self): """Test set_steam_game_property on error. @@ -573,17 +535,15 @@ def test_set_steam_game_property_err(self): mock_window_ids = {"1", "2", "3"} mock_appid = 123 - mock_display.create_resource_object.side_effect = ( - DisplayConnectionError(mock_display, "foo") + mock_display.create_resource_object.side_effect = DisplayConnectionError( + mock_display, "foo" ) result = umu_run.set_steam_game_property( mock_display, mock_window_ids, mock_appid ) - self.assertTrue( - result is mock_display, f"Expected Display, received: {result}" - ) + self.assertTrue(result is mock_display, f"Expected Display, received: {result}") mock_display.create_resource_object.assert_called() def test_set_steam_game_property(self): @@ -599,9 +559,7 @@ def test_set_steam_game_property(self): result = umu_run.set_steam_game_property( mock_display, mock_window_ids, mock_appid ) - self.assertTrue( - result is mock_display, f"Expected Display, received: {result}" - ) + self.assertTrue(result is mock_display, f"Expected Display, received: {result}") mock_display.create_resource_object.assert_called() mock_display.get_atom.assert_called() @@ -622,9 +580,7 @@ def test_get_window_ids_err(self): mock_display.screen.return_value = mock_screen mock_screen.root = mock_root - mock_root.query_tree.side_effect = DisplayConnectionError( - mock_display, "foo" - ) + mock_root.query_tree.side_effect = DisplayConnectionError(mock_display, "foo") mock_query_tree.children = set() result = umu_run.get_window_ids(mock_display) @@ -653,9 +609,7 @@ def test_get_window_ids(self): result = umu_run.get_window_ids(mock_display) - self.assertTrue( - isinstance(result, set), f"Expected a set, received: {result}" - ) + self.assertTrue(isinstance(result, set), f"Expected a set, received: {result}") mock_display.next_event.assert_called_once() mock_display.screen.assert_called_once() mock_screen.root.query_tree.assert_called_once() @@ -718,9 +672,7 @@ def test_create_shim(self): umu_runtime.create_shim(shim) self.assertTrue(shim.is_file(), f"Expected '{shim}' to be a file") # Ensure there's data - self.assertTrue( - shim.stat().st_size > 0, f"Expected '{shim}' to have data" - ) + self.assertTrue(shim.stat().st_size > 0, f"Expected '{shim}' to have data") def test_rearrange_gamescope_baselayer_order_none(self): """Test rearrange_gamescope_baselayer_order for layer ID mismatches.""" @@ -829,9 +781,7 @@ def test_run_command_none(self): def test_get_libc(self): """Test get_libc.""" - self.assertIsInstance( - umu_util.get_libc(), str, "Value is not a string" - ) + self.assertIsInstance(umu_util.get_libc(), str, "Value is not a string") def test_is_installed_verb_noverb(self): """Test is_installed_verb when passed an empty verb.""" @@ -908,9 +858,7 @@ def test_is_winetricks_verb(self): verbs = [line.strip() for line in file] result = umu_util.is_winetricks_verb(verbs) - self.assertTrue( - result, f"Expected {verbs} to only contain winetricks verbs" - ) + self.assertTrue(result, f"Expected {verbs} to only contain winetricks verbs") def test_check_runtime(self): """Test check_runtime when pv-verify does not exist. @@ -922,9 +870,7 @@ def test_check_runtime(self): If the pv-verify binary does not exist, a warning should be logged and the function should return """ - self.test_user_share.joinpath( - "pressure-vessel", "bin", "pv-verify" - ).unlink() + self.test_user_share.joinpath("pressure-vessel", "bin", "pv-verify").unlink() result = umu_runtime.check_runtime( self.test_user_share, self.test_runtime_version ) @@ -941,9 +887,7 @@ def test_check_runtime_success(self): def test_check_runtime_dir(self): """Test check_runtime when passed a BUILD_ID that does not exist.""" - runtime = Path( - self.test_user_share, "sniper_platform_0.20240125.75305" - ) + runtime = Path(self.test_user_share, "sniper_platform_0.20240125.75305") # Mock the removal of the runtime directory # In the real usage when updating the runtime, this should not happen @@ -974,9 +918,7 @@ def test_move(self): self.test_user_share.joinpath("qux").symlink_to(test_file) # Directory - umu_runtime._move( - test_dir, self.test_user_share, self.test_local_share - ) + umu_runtime._move(test_dir, self.test_user_share, self.test_local_share) self.assertFalse( self.test_user_share.joinpath("foo").exists(), "foo did not move from src", @@ -987,9 +929,7 @@ def test_move(self): ) # File - umu_runtime._move( - test_file, self.test_user_share, self.test_local_share - ) + umu_runtime._move(test_file, self.test_user_share, self.test_local_share) self.assertFalse( self.test_user_share.joinpath("bar").exists(), "bar did not move from src", @@ -1055,9 +995,7 @@ def test_fetch_releases_no_assets(self): result = umu_proton._fetch_releases((mock_tp, mock_hp)) self.assertTrue(result is not None, "Expected a value, received None") - self.assertTrue( - isinstance(result, tuple), f"Expected tuple, received {result}" - ) + self.assertTrue(isinstance(result, tuple), f"Expected tuple, received {result}") result_len = len(result) self.assertFalse( result_len, @@ -1098,9 +1036,7 @@ def test_fetch_releases(self): result = umu_proton._fetch_releases((mock_tp, mock_hp)) self.assertTrue(result is not None, "Expected a value, received None") - self.assertTrue( - isinstance(result, tuple), f"Expected tuple, received {result}" - ) + self.assertTrue(isinstance(result, tuple), f"Expected tuple, received {result}") result_len = len(result) self.assertTrue( result_len, @@ -1114,9 +1050,7 @@ def test_update_proton(self): result = [] for mock in mock_protons: - self.assertTrue( - mock.is_dir(), f"Directory '{mock}' does not exist" - ) + self.assertTrue(mock.is_dir(), f"Directory '{mock}' does not exist") result = umu_proton._update_proton(mock_protons, thread_pool) @@ -1132,9 +1066,7 @@ def test_update_proton_empty(self): # UMU/ULWGL-Proton found in compatibilitytools.d result = umu_proton._update_proton([], None) - self.assertTrue( - result is None, "Expected None when passed an empty list" - ) + self.assertTrue(result is None, "Expected None when passed an empty list") def test_ge_proton(self): """Test check_env when the code name GE-Proton is set for PROTONPATH. @@ -1149,9 +1081,7 @@ def test_ge_proton(self): self.assertRaises(FileNotFoundError), patch.object(umu_proton, "_fetch_releases", return_value=None), patch.object(umu_proton, "_get_latest", return_value=None), - patch.object( - umu_proton, "_get_from_steamcompat", return_value=None - ), + patch.object(umu_proton, "_get_from_steamcompat", return_value=None), ): os.environ["WINEPREFIX"] = self.test_file os.environ["GAMEID"] = self.test_file @@ -1160,9 +1090,7 @@ def test_ge_proton(self): self.assertEqual( self.env["PROTONPATH"], self.test_compat.joinpath( - self.test_archive.name[ - : self.test_archive.name.find(".tar.gz") - ] + self.test_archive.name[: self.test_archive.name.find(".tar.gz")] ).as_posix(), "Expected PROTONPATH to be proton dir in compat", ) @@ -1179,18 +1107,14 @@ def test_ge_proton_none(self): self.assertRaises(FileNotFoundError), patch.object(umu_proton, "_fetch_releases", return_value=None), patch.object(umu_proton, "_get_latest", return_value=None), - patch.object( - umu_proton, "_get_from_steamcompat", return_value=None - ), + patch.object(umu_proton, "_get_from_steamcompat", return_value=None), ThreadPoolExecutor() as thread_pool, ): os.environ["WINEPREFIX"] = self.test_file os.environ["GAMEID"] = self.test_file os.environ["PROTONPATH"] = "GE-Proton" umu_run.check_env(self.env, thread_pool) - self.assertFalse( - os.environ.get("PROTONPATH"), "Expected empty string" - ) + self.assertFalse(os.environ.get("PROTONPATH"), "Expected empty string") def test_latest_interrupt(self): """Test _get_latest when the user interrupts the download/extraction. @@ -1221,9 +1145,7 @@ def test_latest_interrupt(self): files, self.test_session_pools, ) - self.assertFalse( - self.env["PROTONPATH"], "Expected PROTONPATH to be empty" - ) + self.assertFalse(self.env["PROTONPATH"], "Expected PROTONPATH to be empty") self.assertFalse(result, "Expected None on KeyboardInterrupt") def test_latest_val_err(self): @@ -1260,9 +1182,7 @@ def test_latest_val_err(self): files, self.test_session_pools, ) - self.assertFalse( - self.env["PROTONPATH"], "Expected PROTONPATH to be empty" - ) + self.assertFalse(self.env["PROTONPATH"], "Expected PROTONPATH to be empty") self.assertFalse(result, "Expected None when a ValueError occurs") def test_latest_offline(self): @@ -1288,12 +1208,8 @@ def test_latest_offline(self): files, self.test_session_pools, ) - self.assertFalse( - self.env["PROTONPATH"], "Expected PROTONPATH to be empty" - ) - self.assertFalse( - result, "Expected None to be returned from _get_latest" - ) + self.assertFalse(self.env["PROTONPATH"], "Expected PROTONPATH to be empty") + self.assertFalse(result, "Expected None to be returned from _get_latest") def test_link_umu(self): """Test _get_latest for recreating the UMU-Latest link. @@ -1455,12 +1371,8 @@ def test_steamcompat_nodir(self): result = umu_proton._get_from_steamcompat(self.env, self.test_compat) - self.assertFalse( - result, "Expected None after calling _get_from_steamcompat" - ) - self.assertFalse( - self.env["PROTONPATH"], "Expected PROTONPATH to not be set" - ) + self.assertFalse(result, "Expected None after calling _get_from_steamcompat") + self.assertFalse(self.env["PROTONPATH"], "Expected PROTONPATH to not be set") def test_steamcompat(self): """Test _get_from_steamcompat. @@ -1479,9 +1391,7 @@ def test_steamcompat(self): self.assertEqual( self.env["PROTONPATH"], self.test_compat.joinpath( - self.test_archive.name[ - : self.test_archive.name.find(".tar.gz") - ] + self.test_archive.name[: self.test_archive.name.find(".tar.gz")] ).as_posix(), "Expected PROTONPATH to be proton dir in compat", ) @@ -1491,9 +1401,7 @@ def test_extract_tarfile_err(self): A ReadError should be raised as we only expect .tar.gz releases """ - test_archive = self.test_cache.joinpath( - f"{self.test_proton_dir}.tar.zst" - ) + test_archive = self.test_cache.joinpath(f"{self.test_proton_dir}.tar.zst") # Do not apply compression with tarfile.open(test_archive.as_posix(), "w") as tar: @@ -1516,9 +1424,7 @@ def test_extract_tarfile(self): """ result = None - result = umu_util.extract_tarfile( - self.test_archive, self.test_archive.parent - ) + result = umu_util.extract_tarfile(self.test_archive, self.test_archive.parent) move(str(self.test_archive).removesuffix(".tar.gz"), self.test_compat) self.assertEqual( result, @@ -1530,9 +1436,7 @@ def test_extract_tarfile(self): "Expected proton dir to exists in compat", ) self.assertTrue( - self.test_compat.joinpath(self.test_proton_dir) - .joinpath("proton") - .exists(), + self.test_compat.joinpath(self.test_proton_dir).joinpath("proton").exists(), "Expected 'proton' file to exists in the proton dir", ) @@ -1579,9 +1483,7 @@ def test_game_drive_libpath_empty(self): os.environ[key] = val # Game drive - self.assertTrue( - result_gamedrive is self.env, "Expected the same reference" - ) + self.assertTrue(result_gamedrive is self.env, "Expected the same reference") self.assertTrue( self.env["STEAM_RUNTIME_LIBRARY_PATH"], "Expected two elements in STEAM_RUNTIME_LIBRARY_PATHS", @@ -1602,9 +1504,7 @@ def test_game_drive_libpath_empty(self): self.env["STEAM_COMPAT_INSTALL_PATH"], "Expected STEAM_COMPAT_INSTALL_PATH to be empty", ) - self.assertFalse( - self.env["EXE"], "Expected EXE to be empty on empty string" - ) + self.assertFalse(self.env["EXE"], "Expected EXE to be empty on empty string") def test_game_drive_libpath(self): """Test enable_steam_game_drive for duplicate paths. @@ -1661,9 +1561,7 @@ def test_game_drive_libpath(self): os.environ[key] = val # Game drive - self.assertTrue( - result_gamedrive is self.env, "Expected the same reference" - ) + self.assertTrue(result_gamedrive is self.env, "Expected the same reference") self.assertTrue( self.env["STEAM_RUNTIME_LIBRARY_PATH"], "Expected two elements in STEAM_RUNTIME_LIBRARY_PATHS", @@ -1691,9 +1589,7 @@ def test_game_drive_libpath(self): self.env["STEAM_COMPAT_INSTALL_PATH"], "Expected STEAM_COMPAT_INSTALL_PATH to be empty", ) - self.assertFalse( - self.env["EXE"], "Expected EXE to be empty on empty string" - ) + self.assertFalse(self.env["EXE"], "Expected EXE to be empty on empty string") def test_game_drive_empty(self): """Test enable_steam_game_drive. @@ -1750,9 +1646,7 @@ def test_game_drive_empty(self): os.environ[key] = val # Game drive - self.assertTrue( - result_gamedrive is self.env, "Expected the same reference" - ) + self.assertTrue(result_gamedrive is self.env, "Expected the same reference") self.assertTrue( self.env["STEAM_RUNTIME_LIBRARY_PATH"], "Expected two elements in STEAM_RUNTIME_LIBRARY_PATHS", @@ -1777,9 +1671,7 @@ def test_game_drive_empty(self): self.env["STEAM_COMPAT_INSTALL_PATH"], "Expected STEAM_COMPAT_INSTALL_PATH to be empty", ) - self.assertFalse( - self.env["EXE"], "Expected EXE to be empty on empty string" - ) + self.assertFalse(self.env["EXE"], "Expected EXE to be empty on empty string") def test_build_command_linux_exe(self): """Test build_command when running a Linux executable. @@ -1827,9 +1719,7 @@ def test_build_command_linux_exe(self): ) copytree( Path(self.test_user_share, "sniper_platform_0.20240125.75305"), - Path( - self.test_local_share, "sniper_platform_0.20240125.75305" - ), + Path(self.test_local_share, "sniper_platform_0.20240125.75305"), dirs_exist_ok=True, symlinks=True, ) @@ -1914,9 +1804,7 @@ def test_build_command_nopv(self): ) copytree( Path(self.test_user_share, "sniper_platform_0.20240125.75305"), - Path( - self.test_local_share, "sniper_platform_0.20240125.75305" - ), + Path(self.test_local_share, "sniper_platform_0.20240125.75305"), dirs_exist_ok=True, symlinks=True, ) @@ -1946,9 +1834,7 @@ def test_build_command_nopv(self): f"Expected 3 elements, received {len(test_command)}", ) proton, verb, exe, *_ = [*test_command] - self.assertIsInstance( - proton, os.PathLike, "Expected proton to be PathLike" - ) + self.assertIsInstance(proton, os.PathLike, "Expected proton to be PathLike") self.assertEqual( proton, Path(self.env["PROTONPATH"], "proton"), @@ -2046,9 +1932,7 @@ def test_build_command(self): ) copytree( Path(self.test_user_share, "sniper_platform_0.20240125.75305"), - Path( - self.test_local_share, "sniper_platform_0.20240125.75305" - ), + Path(self.test_local_share, "sniper_platform_0.20240125.75305"), dirs_exist_ok=True, symlinks=True, ) @@ -2075,9 +1959,7 @@ def test_build_command(self): 8, f"Expected 8 elements, received {len(test_command)}", ) - entry_point, opt1, verb, opt2, shim, proton, verb2, exe = [ - *test_command - ] + entry_point, opt1, verb, opt2, shim, proton, verb2, exe = [*test_command] # The entry point dest could change. Just check if there's a value self.assertTrue(entry_point, "Expected an entry point") self.assertIsInstance( @@ -2086,13 +1968,9 @@ def test_build_command(self): self.assertEqual(opt1, "--verb", "Expected --verb") self.assertEqual(verb, self.test_verb, "Expected a verb") self.assertEqual(opt2, "--", "Expected --") - self.assertIsInstance( - shim, os.PathLike, "Expected shim to be PathLike" - ) + self.assertIsInstance(shim, os.PathLike, "Expected shim to be PathLike") self.assertEqual(shim, shim_path, "Expected the shim file") - self.assertIsInstance( - proton, os.PathLike, "Expected proton to be PathLike" - ) + self.assertIsInstance(proton, os.PathLike, "Expected proton to be PathLike") self.assertEqual( proton, Path(self.env["PROTONPATH"], "proton"), @@ -2158,9 +2036,7 @@ def test_set_env_opts(self): path_exe, "Expected EXE to be normalized and expanded", ) - self.assertEqual( - self.env["STORE"], test_str, "Expected STORE to be set" - ) + self.assertEqual(self.env["STORE"], test_str, "Expected STORE to be set") self.assertEqual( self.env["PROTONPATH"], path_file, @@ -2171,9 +2047,7 @@ def test_set_env_opts(self): path_file, "Expected WINEPREFIX to be normalized and expanded", ) - self.assertEqual( - self.env["GAMEID"], test_str, "Expected GAMEID to be set" - ) + self.assertEqual(self.env["GAMEID"], test_str, "Expected GAMEID to be set") self.assertEqual( self.env["PROTON_VERB"], self.test_verb, @@ -2228,9 +2102,7 @@ def test_set_env_id(self): Path(path_exe).parent.as_posix(), "Expected STEAM_COMPAT_INSTALL_PATH to be set", ) - self.assertEqual( - self.env["STORE"], test_str, "Expected STORE to be set" - ) + self.assertEqual(self.env["STORE"], test_str, "Expected STORE to be set") self.assertEqual( self.env["PROTONPATH"], path_file, @@ -2241,9 +2113,7 @@ def test_set_env_id(self): path_file, "Expected WINEPREFIX to be normalized and expanded", ) - self.assertEqual( - self.env["GAMEID"], umu_id, "Expected GAMEID to be set" - ) + self.assertEqual(self.env["GAMEID"], umu_id, "Expected GAMEID to be set") self.assertEqual( self.env["PROTON_VERB"], self.test_verb, @@ -2347,9 +2217,7 @@ def test_set_env_exe(self): self.env["STEAM_COMPAT_INSTALL_PATH"], "Expected STEAM_COMPAT_INSTALL_PATH to be empty", ) - self.assertEqual( - self.env["STORE"], test_str, "Expected STORE to be set" - ) + self.assertEqual(self.env["STORE"], test_str, "Expected STORE to be set") self.assertEqual( self.env["PROTONPATH"], path_file, @@ -2360,9 +2228,7 @@ def test_set_env_exe(self): path_file, "Expected WINEPREFIX to be normalized and expanded", ) - self.assertEqual( - self.env["GAMEID"], test_str, "Expected GAMEID to be set" - ) + self.assertEqual(self.env["GAMEID"], test_str, "Expected GAMEID to be set") self.assertEqual( self.env["PROTON_VERB"], self.test_verb, @@ -2469,9 +2335,7 @@ def test_set_env(self): Path(path_exe).parent.as_posix(), "Expected STEAM_COMPAT_INSTALL_PATH to be set", ) - self.assertEqual( - self.env["STORE"], test_str, "Expected STORE to be set" - ) + self.assertEqual(self.env["STORE"], test_str, "Expected STORE to be set") self.assertEqual( self.env["PROTONPATH"], path_file, @@ -2482,9 +2346,7 @@ def test_set_env(self): path_file, "Expected WINEPREFIX to be normalized and expanded", ) - self.assertEqual( - self.env["GAMEID"], test_str, "Expected GAMEID to be set" - ) + self.assertEqual(self.env["GAMEID"], test_str, "Expected GAMEID to be set") self.assertEqual( self.env["PROTON_VERB"], self.test_verb, @@ -2615,9 +2477,7 @@ def test_set_env_winetricks(self): path_file, "Expected WINEPREFIX to be normalized and expanded", ) - self.assertEqual( - self.env["GAMEID"], test_str, "Expected GAMEID to be set" - ) + self.assertEqual(self.env["GAMEID"], test_str, "Expected GAMEID to be set") self.assertEqual( self.env["PROTON_VERB"], proton_verb, @@ -2776,15 +2636,11 @@ def test_setup_pfx_symlinks_unixuser(self): # Verify steamuser -> unix user self.assertTrue( - Path(self.test_file) - .joinpath("drive_c/users/steamuser") - .is_symlink(), + Path(self.test_file).joinpath("drive_c/users/steamuser").is_symlink(), "Expected steamuser to be a symbolic link", ) self.assertEqual( - Path(self.test_file) - .joinpath("drive_c/users/steamuser") - .readlink(), + Path(self.test_file).joinpath("drive_c/users/steamuser").readlink(), Path(self.user), "Expected steamuser -> user", ) @@ -2830,9 +2686,7 @@ def test_setup_pfx_symlinks_steamuser(self): "Expected symbolic link for unixuser", ) self.assertEqual( - Path(self.test_file) - .joinpath(f"drive_c/users/{self.user}") - .readlink(), + Path(self.test_file).joinpath(f"drive_c/users/{self.user}").readlink(), Path("steamuser"), "Expected unixuser -> steamuser", ) @@ -3011,9 +2865,7 @@ def test_parse_args(self): result = __main__.parse_args() self.assertIsInstance(result, tuple, "Expected a tuple") self.assertIsInstance(result[0], str, "Expected a string") - self.assertIsInstance( - result[1], list, "Expected a list as options" - ) + self.assertIsInstance(result[1], list, "Expected a list as options") self.assertEqual( *result[1], test_opt, @@ -3086,9 +2938,7 @@ def test_env_nowine_noproton(self): path.parent.parent.exists(), f"Expected {path.parent.parent} to not exist", ) - self.assertTrue( - mock_home.exists(), f"Expected {mock_home} to exist" - ) + self.assertTrue(mock_home.exists(), f"Expected {mock_home} to exist") def test_env_wine_noproton(self): """Test check_env when configured to not use Proton. @@ -3271,9 +3121,7 @@ def test_env_vars_proton(self): os.environ["WINEPREFIX"] = self.test_file os.environ["GAMEID"] = self.test_file result = umu_run.check_env(self.env, thread_pool) - self.assertTrue( - result is self.env, "Expected the same reference" - ) + self.assertTrue(result is self.env, "Expected the same reference") self.assertFalse(os.environ["PROTONPATH"]) def test_env_vars_wine(self): diff --git a/umu/umu_test_plugins.py b/umu/umu_test_plugins.py index 7b620cec6..6ffc211c0 100644 --- a/umu/umu_test_plugins.py +++ b/umu/umu_test_plugins.py @@ -85,9 +85,7 @@ def setUp(self): # Mock the runtime files Path(self.test_user_share, "sniper_platform_0.20240125.75305").mkdir() - Path( - self.test_user_share, "sniper_platform_0.20240125.75305", "foo" - ).touch() + Path(self.test_user_share, "sniper_platform_0.20240125.75305", "foo").touch() Path(self.test_user_share, "run").touch() Path(self.test_user_share, "run-in-sniper").touch() Path(self.test_user_share, "umu").touch() @@ -98,9 +96,7 @@ def setUp(self): # Mock umu-launcher Path(self.test_user_share, "umu-launcher").mkdir() - Path( - self.test_user_share, "umu-launcher", "compatibilitytool.vdf" - ).touch() + Path(self.test_user_share, "umu-launcher", "compatibilitytool.vdf").touch() Path(self.test_user_share, "umu-launcher", "toolmanifest.vdf").touch() # Mock the proton file in the dir @@ -209,9 +205,7 @@ def test_build_command_entry(self): ) copytree( Path(self.test_user_share, "sniper_platform_0.20240125.75305"), - Path( - self.test_local_share, "sniper_platform_0.20240125.75305" - ), + Path(self.test_local_share, "sniper_platform_0.20240125.75305"), dirs_exist_ok=True, symlinks=True, ) @@ -229,9 +223,7 @@ def test_build_command_entry(self): # Build with self.assertRaisesRegex(FileNotFoundError, "_v2-entry-point"): - umu_run.build_command( - self.env, self.test_local_share, test_command - ) + umu_run.build_command(self.env, self.test_local_share, test_command) def test_build_command_proton(self): """Test build_command. @@ -287,9 +279,7 @@ def test_build_command_proton(self): ) copytree( Path(self.test_user_share, "sniper_platform_0.20240125.75305"), - Path( - self.test_local_share, "sniper_platform_0.20240125.75305" - ), + Path(self.test_local_share, "sniper_platform_0.20240125.75305"), dirs_exist_ok=True, symlinks=True, ) @@ -311,9 +301,7 @@ def test_build_command_proton(self): # Build with self.assertRaisesRegex(FileNotFoundError, "proton"): - umu_run.build_command( - self.env, self.test_local_share, test_command - ) + umu_run.build_command(self.env, self.test_local_share, test_command) def test_build_command_toml(self): """Test build_command. @@ -372,9 +360,7 @@ def test_build_command_toml(self): ) copytree( Path(self.test_user_share, "sniper_platform_0.20240125.75305"), - Path( - self.test_local_share, "sniper_platform_0.20240125.75305" - ), + Path(self.test_local_share, "sniper_platform_0.20240125.75305"), dirs_exist_ok=True, symlinks=True, ) @@ -398,9 +384,7 @@ def test_build_command_toml(self): test_command = umu_run.build_command(self.env, self.test_local_share) # Verify contents of the command - entry_point, opt1, verb, opt2, shim, proton, verb2, exe = [ - *test_command - ] + entry_point, opt1, verb, opt2, shim, proton, verb2, exe = [*test_command] # The entry point dest could change. Just check if there's a value self.assertTrue(entry_point, "Expected an entry point") self.assertIsInstance( @@ -409,13 +393,9 @@ def test_build_command_toml(self): self.assertEqual(opt1, "--verb", "Expected --verb") self.assertEqual(verb, self.test_verb, "Expected a verb") self.assertEqual(opt2, "--", "Expected --") - self.assertIsInstance( - shim, os.PathLike, "Expected shim to be PathLike" - ) + self.assertIsInstance(shim, os.PathLike, "Expected shim to be PathLike") self.assertEqual(shim, shim_path, "Expected the shim file") - self.assertIsInstance( - proton, os.PathLike, "Expected proton to be PathLike" - ) + self.assertIsInstance(proton, os.PathLike, "Expected proton to be PathLike") self.assertEqual( proton, Path(self.env["PROTONPATH"], "proton"), @@ -456,9 +436,7 @@ def test_set_env_toml_nofile(self): self.assertIsInstance( result, Namespace, "Expected a Namespace from parse_arg" ) - self.assertTrue( - vars(result).get("config"), "Expected a value for --config" - ) + self.assertTrue(vars(result).get("config"), "Expected a value for --config") # Env with self.assertRaisesRegex(FileNotFoundError, "exe"): umu_plugins.set_env_toml(self.env, result) @@ -530,9 +508,7 @@ def test_set_env_toml_nodir(self): self.assertIsInstance( result, Namespace, "Expected a Namespace from parse_arg" ) - self.assertTrue( - vars(result).get("config"), "Expected a value for --config" - ) + self.assertTrue(vars(result).get("config"), "Expected a value for --config") # Env with self.assertRaisesRegex(NotADirectoryError, "proton"): umu_plugins.set_env_toml(self.env, result) @@ -568,9 +544,7 @@ def test_set_env_toml_tables(self): self.assertIsInstance( result, Namespace, "Expected a Namespace from parse_arg" ) - self.assertTrue( - vars(result).get("config"), "Expected a value for --config" - ) + self.assertTrue(vars(result).get("config"), "Expected a value for --config") # Env with self.assertRaisesRegex(ValueError, "umu"): umu_plugins.set_env_toml(self.env, result) @@ -634,14 +608,10 @@ def test_set_env_toml_paths(self): self.assertIsInstance( result, Namespace, "Expected a Namespace from parse_arg" ) - self.assertTrue( - vars(result).get("config"), "Expected a value for --config" - ) + self.assertTrue(vars(result).get("config"), "Expected a value for --config") # Env result_set_env = umu_plugins.set_env_toml(self.env, result) - self.assertTrue( - isinstance(result_set_env, tuple), "Expected a tuple" - ) + self.assertTrue(isinstance(result_set_env, tuple), "Expected a tuple") # Check that the paths are still in the unexpanded form after # setting the env @@ -700,16 +670,12 @@ def test_set_env_toml_opts(self): self.assertIsInstance( result, Namespace, "Expected a Namespace from parse_arg" ) - self.assertTrue( - vars(result).get("config"), "Expected a value for --config" - ) + self.assertTrue(vars(result).get("config"), "Expected a value for --config") # Env # The first argument is the env result_set_env = umu_plugins.set_env_toml(self.env, result) - self.assertTrue( - isinstance(result_set_env, tuple), "Expected a tuple" - ) + self.assertTrue(isinstance(result_set_env, tuple), "Expected a tuple") self.assertTrue( result_set_env[0] is self.env, "Expected the same reference" ) @@ -780,14 +746,10 @@ def test_set_env_toml(self): self.assertIsInstance( result, Namespace, "Expected a Namespace from parse_arg" ) - self.assertTrue( - vars(result).get("config"), "Expected a value for --config" - ) + self.assertTrue(vars(result).get("config"), "Expected a value for --config") # Env result_set_env = umu_plugins.set_env_toml(self.env, result) - self.assertTrue( - isinstance(result_set_env, tuple), "Expected a tuple" - ) + self.assertTrue(isinstance(result_set_env, tuple), "Expected a tuple") self.assertTrue(self.env["EXE"], "Expected EXE to be set") self.assertEqual( self.env["PROTONPATH"], diff --git a/umu/umu_util.py b/umu/umu_util.py index dceeb7304..0f94c1575 100644 --- a/umu/umu_util.py +++ b/umu/umu_util.py @@ -145,9 +145,7 @@ def is_installed_verb(verb: list[str], pfx: Path) -> bool: _: str = line.strip() if _ in verbs: is_installed = True - err: str = ( - f"winetricks verb '{_}' is already installed in '{pfx}'" - ) + err: str = f"winetricks verb '{_}' is already installed in '{pfx}'" log.error(err) break @@ -287,9 +285,7 @@ def file_digest(fileobj, digest, /, *, _bufsize=2**18): # noqa: ANN001 and hasattr(fileobj, "readable") and fileobj.readable() ): - err = ( - f"'{fileobj!r}' is not a file-like object in binary reading mode." - ) + err = f"'{fileobj!r}' is not a file-like object in binary reading mode." raise ValueError(err) # binary file, socket.SocketIO object