mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-07 08:55:12 -04:00
Fix tests
This commit is contained in:
parent
30b14712e9
commit
fc1360a0ba
3 changed files with 16 additions and 12 deletions
|
@ -122,8 +122,13 @@ class Settings(object):
|
||||||
"""
|
"""
|
||||||
p = platform.system()
|
p = platform.system()
|
||||||
if p == 'Windows':
|
if p == 'Windows':
|
||||||
|
try:
|
||||||
appdata = os.environ['APPDATA']
|
appdata = os.environ['APPDATA']
|
||||||
return '{}\\OnionShare\\onionshare.json'.format(appdata)
|
return '{}\\OnionShare\\onionshare.json'.format(appdata)
|
||||||
|
except:
|
||||||
|
# If for some reason we don't have the 'APPDATA' environment variable
|
||||||
|
# (like running tests in Linux while pretending to be in Windows)
|
||||||
|
return os.path.expanduser('~/.config/onionshare/onionshare.json')
|
||||||
elif p == 'Darwin':
|
elif p == 'Darwin':
|
||||||
return os.path.expanduser('~/Library/Application Support/OnionShare/onionshare.json')
|
return os.path.expanduser('~/Library/Application Support/OnionShare/onionshare.json')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -8,7 +8,7 @@ import tempfile
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from onionshare import common, web, settings
|
from onionshare import common, web, settings, strings
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def temp_dir_1024():
|
def temp_dir_1024():
|
||||||
|
@ -151,7 +151,10 @@ def time_strftime(monkeypatch):
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def common_obj():
|
def common_obj():
|
||||||
return common.Common()
|
_common = common.Common()
|
||||||
|
_common.settings = settings.Settings(_common)
|
||||||
|
strings.load_strings(_common)
|
||||||
|
return _common
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def settings_obj(sys_onionshare_dev_mode, platform_linux):
|
def settings_obj(sys_onionshare_dev_mode, platform_linux):
|
||||||
|
|
|
@ -32,12 +32,6 @@ from onionshare import strings
|
||||||
# return path
|
# return path
|
||||||
# common.get_resource_path = get_resource_path
|
# common.get_resource_path = get_resource_path
|
||||||
|
|
||||||
|
|
||||||
def test_starts_with_empty_strings():
|
|
||||||
""" Creates an empty strings dict by default """
|
|
||||||
assert strings.strings == {}
|
|
||||||
|
|
||||||
|
|
||||||
def test_underscore_is_function():
|
def test_underscore_is_function():
|
||||||
assert callable(strings._) and isinstance(strings._, types.FunctionType)
|
assert callable(strings._) and isinstance(strings._, types.FunctionType)
|
||||||
|
|
||||||
|
@ -53,11 +47,13 @@ class TestLoadStrings:
|
||||||
def test_load_strings_loads_other_languages(
|
def test_load_strings_loads_other_languages(
|
||||||
self, common_obj, locale_fr, sys_onionshare_dev_mode):
|
self, common_obj, locale_fr, sys_onionshare_dev_mode):
|
||||||
""" load_strings() loads other languages in different locales """
|
""" load_strings() loads other languages in different locales """
|
||||||
strings.load_strings(common_obj, "fr")
|
common_obj.settings.set('locale', 'fr')
|
||||||
|
strings.load_strings(common_obj)
|
||||||
assert strings._('preparing_files') == "Préparation des fichiers à partager."
|
assert strings._('preparing_files') == "Préparation des fichiers à partager."
|
||||||
|
|
||||||
def test_load_invalid_locale(
|
def test_load_invalid_locale(
|
||||||
self, common_obj, locale_invalid, sys_onionshare_dev_mode):
|
self, common_obj, locale_invalid, sys_onionshare_dev_mode):
|
||||||
""" load_strings() raises a KeyError for an invalid locale """
|
""" load_strings() raises a KeyError for an invalid locale """
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
strings.load_strings(common_obj, 'XX')
|
common_obj.settings.set('locale', 'XX')
|
||||||
|
strings.load_strings(common_obj)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue