mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-06 08:25:15 -04:00
Format all code using black
This commit is contained in:
parent
8010b279e7
commit
88e151d414
87 changed files with 4293 additions and 2374 deletions
|
@ -1,4 +1,5 @@
|
|||
import sys
|
||||
|
||||
# Force tests to look for resources in the source code tree
|
||||
sys.onionshare_dev_mode = True
|
||||
|
||||
|
@ -10,6 +11,7 @@ import pytest
|
|||
|
||||
from onionshare import common, web, settings, strings
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--rungui", action="store_true", default=False, help="run GUI tests"
|
||||
|
@ -27,7 +29,7 @@ def pytest_collection_modifyitems(config, items):
|
|||
if "tor" in item.keywords:
|
||||
item.add_marker(skip_tor)
|
||||
|
||||
if not config.getoption('--rungui'):
|
||||
if not config.getoption("--rungui"):
|
||||
# --rungui given in cli: do not skip GUI tests
|
||||
skip_gui = pytest.mark.skip(reason="need --rungui option to run")
|
||||
for item in items:
|
||||
|
@ -43,8 +45,8 @@ def temp_dir_1024():
|
|||
|
||||
tmp_dir = tempfile.mkdtemp()
|
||||
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
|
||||
with open(tmp_file, 'wb') as f:
|
||||
f.write(b'*' * 1024)
|
||||
with open(tmp_file, "wb") as f:
|
||||
f.write(b"*" * 1024)
|
||||
return tmp_dir
|
||||
|
||||
|
||||
|
@ -58,8 +60,8 @@ def temp_dir_1024_delete():
|
|||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
|
||||
with open(tmp_file, 'wb') as f:
|
||||
f.write(b'*' * 1024)
|
||||
with open(tmp_file, "wb") as f:
|
||||
f.write(b"*" * 1024)
|
||||
yield tmp_dir
|
||||
|
||||
|
||||
|
@ -68,7 +70,7 @@ def temp_file_1024():
|
|||
""" Create a temporary file of a particular size (1024 bytes). """
|
||||
|
||||
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
||||
tmp_file.write(b'*' * 1024)
|
||||
tmp_file.write(b"*" * 1024)
|
||||
return tmp_file.name
|
||||
|
||||
|
||||
|
@ -81,18 +83,18 @@ def temp_file_1024_delete():
|
|||
"""
|
||||
|
||||
with tempfile.NamedTemporaryFile() as tmp_file:
|
||||
tmp_file.write(b'*' * 1024)
|
||||
tmp_file.write(b"*" * 1024)
|
||||
tmp_file.flush()
|
||||
yield tmp_file.name
|
||||
|
||||
|
||||
# pytest > 2.9 only needs @pytest.fixture
|
||||
@pytest.yield_fixture(scope='session')
|
||||
@pytest.yield_fixture(scope="session")
|
||||
def custom_zw():
|
||||
zw = web.share_mode.ZipWriter(
|
||||
common.Common(),
|
||||
zip_filename=common.Common.random_string(4, 6),
|
||||
processed_size_callback=lambda _: 'custom_callback'
|
||||
processed_size_callback=lambda _: "custom_callback",
|
||||
)
|
||||
yield zw
|
||||
zw.close()
|
||||
|
@ -100,7 +102,7 @@ def custom_zw():
|
|||
|
||||
|
||||
# pytest > 2.9 only needs @pytest.fixture
|
||||
@pytest.yield_fixture(scope='session')
|
||||
@pytest.yield_fixture(scope="session")
|
||||
def default_zw():
|
||||
zw = web.share_mode.ZipWriter(common.Common())
|
||||
yield zw
|
||||
|
@ -111,76 +113,77 @@ def default_zw():
|
|||
|
||||
@pytest.fixture
|
||||
def locale_en(monkeypatch):
|
||||
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8'))
|
||||
monkeypatch.setattr("locale.getdefaultlocale", lambda: ("en_US", "UTF-8"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def locale_fr(monkeypatch):
|
||||
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8'))
|
||||
monkeypatch.setattr("locale.getdefaultlocale", lambda: ("fr_FR", "UTF-8"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def locale_invalid(monkeypatch):
|
||||
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8'))
|
||||
monkeypatch.setattr("locale.getdefaultlocale", lambda: ("xx_XX", "UTF-8"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def locale_ru(monkeypatch):
|
||||
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8'))
|
||||
monkeypatch.setattr("locale.getdefaultlocale", lambda: ("ru_RU", "UTF-8"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platform_darwin(monkeypatch):
|
||||
monkeypatch.setattr('platform.system', lambda: 'Darwin')
|
||||
monkeypatch.setattr("platform.system", lambda: "Darwin")
|
||||
|
||||
|
||||
@pytest.fixture # (scope="session")
|
||||
def platform_linux(monkeypatch):
|
||||
monkeypatch.setattr('platform.system', lambda: 'Linux')
|
||||
monkeypatch.setattr("platform.system", lambda: "Linux")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platform_windows(monkeypatch):
|
||||
monkeypatch.setattr('platform.system', lambda: 'Windows')
|
||||
monkeypatch.setattr("platform.system", lambda: "Windows")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sys_argv_sys_prefix(monkeypatch):
|
||||
monkeypatch.setattr('sys.argv', [sys.prefix])
|
||||
monkeypatch.setattr("sys.argv", [sys.prefix])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sys_frozen(monkeypatch):
|
||||
monkeypatch.setattr('sys.frozen', True, raising=False)
|
||||
monkeypatch.setattr("sys.frozen", True, raising=False)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sys_meipass(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
'sys._MEIPASS', os.path.expanduser('~'), raising=False)
|
||||
monkeypatch.setattr("sys._MEIPASS", os.path.expanduser("~"), raising=False)
|
||||
|
||||
|
||||
@pytest.fixture # (scope="session")
|
||||
def sys_onionshare_dev_mode(monkeypatch):
|
||||
monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False)
|
||||
monkeypatch.setattr("sys.onionshare_dev_mode", True, raising=False)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def time_time_100(monkeypatch):
|
||||
monkeypatch.setattr('time.time', lambda: 100)
|
||||
monkeypatch.setattr("time.time", lambda: 100)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def time_strftime(monkeypatch):
|
||||
monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00')
|
||||
monkeypatch.setattr("time.strftime", lambda _: "Jun 06 2013 11:05:00")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def common_obj():
|
||||
return common.Common()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def settings_obj(sys_onionshare_dev_mode, platform_linux):
|
||||
_common = common.Common()
|
||||
_common.version = 'DUMMY_VERSION_1.2.3'
|
||||
_common.version = "DUMMY_VERSION_1.2.3"
|
||||
strings.load_strings(_common)
|
||||
return settings.Settings(_common)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue