Skip to content

Commit

Permalink
Add test case for Zenity locale fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Matoking committed Jan 1, 2020
1 parent f310289 commit 0c79be0
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import pytest
from subprocess import CalledProcessError

from protontricks.gui import select_steam_app_with_gui
from protontricks.steam import SteamApp

import pytest
from conftest import MockResult


@pytest.fixture(scope="function")
def broken_zenity(zenity, monkeypatch):
Expand All @@ -29,6 +32,35 @@ def mock_subprocess_run(args, **kwargs):
yield zenity


@pytest.fixture(scope="function")
def locale_error_zenity(zenity, monkeypatch):
"""
Mock a Zenity executable returning a 255 error due to a locale issue
on first run and working normally on second run
"""
def mock_subprocess_run(args, **kwargs):
if not zenity.args:
zenity.args = args
raise CalledProcessError(
returncode=255,
cmd=args,
output="",
stderr=(
b"This option is not available. "
b"Please see --help for all possible usages."
)
)

return MockResult(stdout=zenity.mock_stdout.encode("utf-8"))

monkeypatch.setattr(
"protontricks.gui.run",
mock_subprocess_run
)

yield zenity


class TestSelectApp:
def test_select_game(self, zenity, steam_app_factory):
"""
Expand Down Expand Up @@ -75,3 +107,24 @@ def test_select_game_broken_zenity(self, broken_zenity, steam_app_factory):

assert steam_app == steam_apps[1]

def test_select_game_locale_error(
self, locale_error_zenity, steam_app_factory, caplog):
"""
Try choosing a game with an environment that can't handle non-ASCII
characters
"""
steam_apps = [
steam_app_factory(name="Fäke game 1", appid=10),
steam_app_factory(name="Fäke game 2", appid=20)
]

# Fake user selecting 'Fäke game 2'. The non-ASCII character 'ä'
# is stripped since Zenity wouldn't be able to display the character.
locale_error_zenity.mock_stdout = "Fke game 2: 20"
steam_app = select_steam_app_with_gui(steam_apps=steam_apps)

assert steam_app == steam_apps[1]
assert (
"Your system locale is incapable of displaying all characters"
in caplog.records[0].message
)

0 comments on commit 0c79be0

Please sign in to comment.