Make helpers.get_pyinstaller_resource_path work when package is not frozen, and make tests report real platform to get accurate paths

This commit is contained in:
Micah Lee 2016-04-12 10:43:28 -07:00
parent ef5665b050
commit e8ce6b1c54
2 changed files with 11 additions and 6 deletions

View file

@ -36,13 +36,16 @@ def get_pyinstaller_resource_path(filename):
"""
Returns the path a resource file in a frozen PyInstall app
"""
# Resource path from frozen PyInstaller app
# Check if app is "frozen" with pyinstaller
# https://pythonhosted.org/PyInstaller/#run-time-information
p = get_platform()
if p == 'Darwin':
return os.path.join(os.path.join(os.path.dirname(sys._MEIPASS), 'Resources'), filename)
elif p == 'Windows':
return os.path.join(sys._MEIPASS, filename)
if getattr(sys, 'frozen', False):
p = get_platform()
if p == 'Darwin':
return os.path.join(os.path.join(os.path.dirname(sys._MEIPASS), 'Resources'), filename)
elif p == 'Windows':
return os.path.join(sys._MEIPASS, filename)
else:
return os.path.join(os.path.dirname(os.path.dirname(__file__)), filename)
def get_html_path(filename):
"""

View file

@ -23,5 +23,7 @@ import test_helpers
def test_get_platform_returns_platform_system():
"""get_platform() returns platform.system() when ONIONSHARE_PLATFORM is not defined"""
p = helpers.platform.system
helpers.platform.system = lambda: 'Sega Saturn'
assert helpers.get_platform() == 'Sega Saturn'
helpers.platform.system = p