Skip to content

Commit 8ddcbed

Browse files
committed
Add and refactor Flatpak/Snap tests
Refactor and improve tests to test Flatpak/Snap detection
1 parent 47bc006 commit 8ddcbed

File tree

3 files changed

+54
-16
lines changed

3 files changed

+54
-16
lines changed

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,13 +782,15 @@ def xdg_user_dir_bin(home_dir):
782782
class MockSubprocess:
783783
def __init__(
784784
self, args=None, kwargs=None, mock_stdout=None,
785-
launcher_alive=True, check=False, cwd=None, shell=False, env=None,
785+
launcher_alive=True, check=False, cwd=None, input=None,
786+
shell=False, env=None,
786787
**_):
787788
self.args = args
788789
self.kwargs = kwargs
789790
self.check = check
790791
self.shell = shell
791792
self.cwd = cwd
793+
self.input = input
792794
self.pid = 5
793795
self.returncode = 0
794796

tests/test_gui.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import contextlib
2+
import shutil
13
from subprocess import CalledProcessError
24

35
import pytest
@@ -291,6 +293,38 @@ def test_select_steam_gui_provider_env(
291293
assert gui_provider.args[0] == "zenity"
292294
assert gui_provider.args[2] == "--hide-header"
293295

296+
@pytest.mark.parametrize(
297+
"path,label",
298+
[
299+
(".steam", "Native"),
300+
(".local/share/Steam", "Native"),
301+
(".var/app/com.valvesoftware.Steam/.local/share/Steam", "Flatpak"),
302+
("snap/steam/common/.local/share/Steam", "Snap")
303+
]
304+
)
305+
def test_correct_labels_detected(
306+
self, gui_provider, steam_dir, home_dir, path, label):
307+
"""
308+
Test that the Steam installation selection dialog uses the correct
309+
label for each Steam installation depending on its type
310+
"""
311+
steam_new_dir = home_dir / path
312+
with contextlib.suppress(FileExistsError):
313+
# First test cases try copying against existing dirs, this can be
314+
# ignored
315+
shutil.copytree(steam_dir, steam_new_dir)
316+
317+
select_steam_installation([
318+
(steam_new_dir, steam_new_dir),
319+
# Use an additional nonsense path; there need to be at least
320+
# two paths or user won't be prompted as there is no need
321+
("/mock-steam", "/mock-steam")
322+
])
323+
324+
prompt_input = gui_provider.kwargs["input"].decode("utf-8")
325+
326+
assert f"{label} - {steam_new_dir}" in prompt_input
327+
294328

295329
@pytest.mark.usefixtures("flatpak_sandbox")
296330
class TestPromptFilesystemAccess:

tests/test_steam.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -628,35 +628,37 @@ def test_find_steam_path_env(
628628
assert str(steam_paths[0]) == str(custom_path)
629629
assert str(steam_paths[1]) == str(custom_path)
630630

631-
@pytest.mark.usefixtures("flatpak_sandbox")
632-
def test_find_steam_path_flatpak(self, steam_dir, steam_root, home_dir):
631+
@pytest.mark.parametrize(
632+
"new_path",
633+
[
634+
".var/app/com.valvesoftware.Steam/data/Steam",
635+
"snap/steam/common/.local/share/Steam"
636+
]
637+
)
638+
def test_find_steam_path_non_native(
639+
self, steam_dir, steam_root, home_dir, new_path):
633640
"""
634-
Ensure that `steam_path` and `steam_root` both point to the Flatpak
635-
installation of Steam if Flatpak installation is found.
641+
Ensure that `steam_path` and `steam_root` both point to the Flatpak/Snap
642+
installation of Steam if either installation is found.
636643
637644
Regression test for flathub/com.github.Matoking.protontricks#10
638645
"""
639-
# Create a symlink to act as the Flatpak installation to keep the test
640-
# simple.
641646
# Copy the existing Steam directory
642-
steam_flatpak_dir = (
643-
home_dir / ".var" / "app" / "com.valvesoftware.Steam" / "data"
644-
/ "Steam"
645-
)
646-
steam_flatpak_dir.parent.mkdir(parents=True)
647-
shutil.copytree(steam_dir, steam_flatpak_dir)
647+
steam_non_native_dir = home_dir / new_path
648+
steam_non_native_dir.parent.mkdir(parents=True)
649+
shutil.copytree(steam_dir, steam_non_native_dir)
648650

649651
steam_installations = find_steam_installations()
650652
steam_path, steam_root = next(
651653
(steam_path, steam_root) for (steam_path, steam_root) in
652654
steam_installations
653-
if str(steam_path) == str(steam_flatpak_dir)
655+
if str(steam_path) == str(steam_non_native_dir)
654656
)
655657

656658
# Since Steam Flatpak installation was found, both of its paths
657659
# should point to the same installation directory
658-
assert str(steam_path) == str(steam_flatpak_dir)
659-
assert str(steam_root) == str(steam_flatpak_dir)
660+
assert str(steam_path) == str(steam_non_native_dir)
661+
assert str(steam_root) == str(steam_non_native_dir)
660662

661663
def test_find_steam_path_multiple_install_warning(
662664
self, steam_dir, steam_root, home_dir, caplog):

0 commit comments

Comments
 (0)