Skip to content

Commit

Permalink
Fix Python 3.4 compatibility
Browse files Browse the repository at this point in the history
Both setup.py and README state this application is Python 3.4
compatible. Python 3.4 is EOL, but the issues are easy enough to fix.
  • Loading branch information
Matoking committed Jan 1, 2020
1 parent db7f1ab commit b3b09b2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ matrix:
sudo: true
- python: "3.6"
- python: "3.5"
- python: "3.4"
install:
- pip install .
- pip install -r requirements_dev.txt
Expand Down
5 changes: 2 additions & 3 deletions src/protontricks/gui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import sys
from subprocess import run, PIPE, CalledProcessError
from subprocess import check_output, PIPE, CalledProcessError

__all__ = ("select_steam_app_with_gui",)

Expand All @@ -20,12 +20,11 @@ def select_steam_app_with_gui(steam_apps):
])

try:
result = run([
choice = check_output([
'zenity', '--forms', '--text=Steam Game Library',
'--title=Choose Game', '--add-combo', 'Pick a library game',
'--combo-values', combo_values
], check=True, stdout=PIPE, stderr=PIPE)
choice = result.stdout
except CalledProcessError as exc:
# TODO: Remove this hack once the bug has been fixed upstream
# Newer versions of zenity have a bug that causes long dropdown choice
Expand Down
4 changes: 2 additions & 2 deletions src/protontricks/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
from subprocess import run, check_output
from subprocess import call, check_output

__all__ = ("run_command",)

Expand Down Expand Up @@ -81,7 +81,7 @@ def get_runtime_library_path(steam_runtime_path, proton_app):
logger.info("Attempting to run command %s", command)

try:
run(command, **kwargs)
call(command, **kwargs)
finally:
# Restore original env vars
os.environ.clear()
Expand Down
21 changes: 8 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,6 @@ def __init__(self, args=None, kwargs=None, mock_stdout=None, env=None):
self.env = env


class MockResult:
def __init__(self, stdout):
self.stdout = stdout


@pytest.fixture(scope="function", autouse=True)
def zenity(monkeypatch):
"""
Expand All @@ -490,15 +485,15 @@ def zenity(monkeypatch):
"""
mock_zenity = MockSubprocess()

def mock_subprocess_run(args, **kwargs):
def mock_subprocess_check_output(args, **kwargs):
mock_zenity.args = args
mock_zenity.kwargs = kwargs

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

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

yield mock_zenity
Expand All @@ -512,16 +507,16 @@ def command(monkeypatch):
"""
mock_command = MockSubprocess()

def mock_subprocess_run(args, **kwargs):
def mock_subprocess_call(args, **kwargs):
mock_command.args = args
mock_command.kwargs = kwargs
mock_command.env = os.environ.copy()

return MockResult(stdout=b"")
return 0

monkeypatch.setattr(
"protontricks.util.run",
mock_subprocess_run
"protontricks.util.call",
mock_subprocess_call
)

yield mock_command
Expand Down
6 changes: 3 additions & 3 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def broken_zenity(zenity, monkeypatch):
the following GitHub issue:
https://github.com/Matoking/protontricks/issues/20
"""
def mock_subprocess_run(args, **kwargs):
def mock_subprocess_check_output(args, **kwargs):
zenity.args = args

raise CalledProcessError(
Expand All @@ -22,8 +22,8 @@ def mock_subprocess_run(args, **kwargs):
)

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

yield zenity
Expand Down

0 comments on commit b3b09b2

Please sign in to comment.