Skip to content

Commit

Permalink
Add and refactor Flatpak/Snap tests
Browse files Browse the repository at this point in the history
Refactor and improve tests to test Flatpak/Snap detection
  • Loading branch information
Matoking committed Sep 11, 2024
1 parent 47bc006 commit 8ddcbed
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,15 @@ def xdg_user_dir_bin(home_dir):
class MockSubprocess:
def __init__(
self, args=None, kwargs=None, mock_stdout=None,
launcher_alive=True, check=False, cwd=None, shell=False, env=None,
launcher_alive=True, check=False, cwd=None, input=None,
shell=False, env=None,
**_):
self.args = args
self.kwargs = kwargs
self.check = check
self.shell = shell
self.cwd = cwd
self.input = input
self.pid = 5
self.returncode = 0

Expand Down
34 changes: 34 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import contextlib
import shutil
from subprocess import CalledProcessError

import pytest
Expand Down Expand Up @@ -291,6 +293,38 @@ def test_select_steam_gui_provider_env(
assert gui_provider.args[0] == "zenity"
assert gui_provider.args[2] == "--hide-header"

@pytest.mark.parametrize(
"path,label",
[
(".steam", "Native"),
(".local/share/Steam", "Native"),
(".var/app/com.valvesoftware.Steam/.local/share/Steam", "Flatpak"),
("snap/steam/common/.local/share/Steam", "Snap")
]
)
def test_correct_labels_detected(
self, gui_provider, steam_dir, home_dir, path, label):
"""
Test that the Steam installation selection dialog uses the correct
label for each Steam installation depending on its type
"""
steam_new_dir = home_dir / path
with contextlib.suppress(FileExistsError):
# First test cases try copying against existing dirs, this can be
# ignored
shutil.copytree(steam_dir, steam_new_dir)

select_steam_installation([
(steam_new_dir, steam_new_dir),
# Use an additional nonsense path; there need to be at least
# two paths or user won't be prompted as there is no need
("/mock-steam", "/mock-steam")
])

prompt_input = gui_provider.kwargs["input"].decode("utf-8")

assert f"{label} - {steam_new_dir}" in prompt_input


@pytest.mark.usefixtures("flatpak_sandbox")
class TestPromptFilesystemAccess:
Expand Down
32 changes: 17 additions & 15 deletions tests/test_steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,35 +628,37 @@ def test_find_steam_path_env(
assert str(steam_paths[0]) == str(custom_path)
assert str(steam_paths[1]) == str(custom_path)

@pytest.mark.usefixtures("flatpak_sandbox")
def test_find_steam_path_flatpak(self, steam_dir, steam_root, home_dir):
@pytest.mark.parametrize(
"new_path",
[
".var/app/com.valvesoftware.Steam/data/Steam",
"snap/steam/common/.local/share/Steam"
]
)
def test_find_steam_path_non_native(
self, steam_dir, steam_root, home_dir, new_path):
"""
Ensure that `steam_path` and `steam_root` both point to the Flatpak
installation of Steam if Flatpak installation is found.
Ensure that `steam_path` and `steam_root` both point to the Flatpak/Snap
installation of Steam if either installation is found.
Regression test for flathub/com.github.Matoking.protontricks#10
"""
# Create a symlink to act as the Flatpak installation to keep the test
# simple.
# Copy the existing Steam directory
steam_flatpak_dir = (
home_dir / ".var" / "app" / "com.valvesoftware.Steam" / "data"
/ "Steam"
)
steam_flatpak_dir.parent.mkdir(parents=True)
shutil.copytree(steam_dir, steam_flatpak_dir)
steam_non_native_dir = home_dir / new_path
steam_non_native_dir.parent.mkdir(parents=True)
shutil.copytree(steam_dir, steam_non_native_dir)

steam_installations = find_steam_installations()
steam_path, steam_root = next(
(steam_path, steam_root) for (steam_path, steam_root) in
steam_installations
if str(steam_path) == str(steam_flatpak_dir)
if str(steam_path) == str(steam_non_native_dir)
)

# Since Steam Flatpak installation was found, both of its paths
# should point to the same installation directory
assert str(steam_path) == str(steam_flatpak_dir)
assert str(steam_root) == str(steam_flatpak_dir)
assert str(steam_path) == str(steam_non_native_dir)
assert str(steam_root) == str(steam_non_native_dir)

def test_find_steam_path_multiple_install_warning(
self, steam_dir, steam_root, home_dir, caplog):
Expand Down

0 comments on commit 8ddcbed

Please sign in to comment.