diff --git a/tests/conftest.py b/tests/conftest.py index 324c1c9..3553a94 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_gui.py b/tests/test_gui.py index 7694961..bab4503 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -1,3 +1,5 @@ +import contextlib +import shutil from subprocess import CalledProcessError import pytest @@ -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: diff --git a/tests/test_steam.py b/tests/test_steam.py index 259b181..9c87c73 100644 --- a/tests/test_steam.py +++ b/tests/test_steam.py @@ -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):