Use pytest.mark.fake_os

This commit is contained in:
Florian Bruhin 2018-10-08 17:41:12 +02:00
parent 91ae86db62
commit 1abfc03965
2 changed files with 21 additions and 31 deletions

View File

@ -22,14 +22,6 @@ import pytest
from qutebrowser.browser import downloads, qtnetworkdownloads
@pytest.fixture(autouse=True)
def is_platform(monkeypatch, platform="windows"):
for p in ["mac", "linux", "posix", "windows"]:
monkeypatch.setattr(
'qutebrowser.utils.utils.is_{}'.format(p),
p == platform)
def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache,
fake_args):
"""Simple check for download model internals."""
@ -102,14 +94,16 @@ class TestDownloadTarget:
assert isinstance(obj, downloads._DownloadTarget)
@pytest.mark.parametrize('raw, platform, expected', [
('http://foo/bar', 'windows', 'bar'),
('A *|<>\\: bear!', 'windows', 'A ______ bear!'),
('A *|<>\\: bear!', 'posix', 'A *|<>\\: bear!')
@pytest.mark.parametrize('raw, expected', [
pytest.param('http://foo/bar', 'bar',
marks=pytest.mark.fake_os('windows')),
pytest.param('A *|<>\\: bear!', 'A ______ bear!',
marks=pytest.mark.fake_os('windows')),
pytest.param('A *|<>\\: bear!', 'A *|<>\\: bear!',
marks=pytest.mark.fake_os('posix')),
])
def test_sanitized_filenames(raw, platform, expected, config_stub,
download_tmpdir, monkeypatch):
is_platform(monkeypatch, platform)
def test_sanitized_filenames(raw, expected,
config_stub, download_tmpdir, monkeypatch):
manager = downloads.AbstractDownloadManager()
target = downloads.FileDownloadTarget(str(download_tmpdir))
item = downloads.AbstractDownloadItem()

View File

@ -113,14 +113,6 @@ class TestElidingFilenames:
assert utils.elide_filename(filename, length) == expected
@pytest.fixture(autouse=True)
def is_platform(monkeypatch, platform="windows"):
for p in ["mac", "linux", "posix", "windows"]:
monkeypatch.setattr(
'qutebrowser.utils.utils.is_{}'.format(p),
p == platform)
@pytest.fixture(params=[True, False])
def freezer(request, monkeypatch):
if request.param and not getattr(sys, 'frozen', False):
@ -641,15 +633,19 @@ def test_force_encoding(inp, enc, expected):
assert utils.force_encoding(inp, enc) == expected
@pytest.mark.parametrize('inp, platform, expected', [
('normal.txt', 'windows', 'normal.txt'),
('user/repo issues.mht', 'windows', 'user_repo issues.mht'),
('<Test\\File> - "*?:|', 'windows', '_Test_File_ - _____'),
('<Test\\File> - "*?:|', 'mac', '<Test\\File> - "*?_|'),
('<Test\\File> - "*?:|', 'posix', '<Test\\File> - "*?:|'),
@pytest.mark.parametrize('inp, expected', [
pytest.param('normal.txt', 'normal.txt',
marks=pytest.mark.fake_os('windows')),
pytest.param('user/repo issues.mht', 'user_repo issues.mht',
marks=pytest.mark.fake_os('windows')),
pytest.param('<Test\\File> - "*?:|', '_Test_File_ - _____',
marks=pytest.mark.fake_os('windows')),
pytest.param('<Test\\File> - "*?:|', '<Test\\File> - "*?_|',
marks=pytest.mark.fake_os('mac')),
pytest.param('<Test\\File> - "*?:|', '<Test\\File> - "*?:|',
marks=pytest.mark.fake_os('posix')),
])
def test_sanitize_filename(inp, platform, expected, monkeypatch):
is_platform(monkeypatch, platform)
def test_sanitize_filename(inp, expected, monkeypatch):
assert utils.sanitize_filename(inp) == expected