Use pytest.mark.fake_os
This commit is contained in:
parent
91ae86db62
commit
1abfc03965
@ -22,14 +22,6 @@ import pytest
|
|||||||
from qutebrowser.browser import downloads, qtnetworkdownloads
|
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,
|
def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache,
|
||||||
fake_args):
|
fake_args):
|
||||||
"""Simple check for download model internals."""
|
"""Simple check for download model internals."""
|
||||||
@ -102,14 +94,16 @@ class TestDownloadTarget:
|
|||||||
assert isinstance(obj, downloads._DownloadTarget)
|
assert isinstance(obj, downloads._DownloadTarget)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('raw, platform, expected', [
|
@pytest.mark.parametrize('raw, expected', [
|
||||||
('http://foo/bar', 'windows', 'bar'),
|
pytest.param('http://foo/bar', 'bar',
|
||||||
('A *|<>\\: bear!', 'windows', 'A ______ bear!'),
|
marks=pytest.mark.fake_os('windows')),
|
||||||
('A *|<>\\: bear!', 'posix', 'A *|<>\\: bear!')
|
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,
|
def test_sanitized_filenames(raw, expected,
|
||||||
download_tmpdir, monkeypatch):
|
config_stub, download_tmpdir, monkeypatch):
|
||||||
is_platform(monkeypatch, platform)
|
|
||||||
manager = downloads.AbstractDownloadManager()
|
manager = downloads.AbstractDownloadManager()
|
||||||
target = downloads.FileDownloadTarget(str(download_tmpdir))
|
target = downloads.FileDownloadTarget(str(download_tmpdir))
|
||||||
item = downloads.AbstractDownloadItem()
|
item = downloads.AbstractDownloadItem()
|
||||||
|
@ -113,14 +113,6 @@ class TestElidingFilenames:
|
|||||||
assert utils.elide_filename(filename, length) == expected
|
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])
|
@pytest.fixture(params=[True, False])
|
||||||
def freezer(request, monkeypatch):
|
def freezer(request, monkeypatch):
|
||||||
if request.param and not getattr(sys, 'frozen', False):
|
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
|
assert utils.force_encoding(inp, enc) == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('inp, platform, expected', [
|
@pytest.mark.parametrize('inp, expected', [
|
||||||
('normal.txt', 'windows', 'normal.txt'),
|
pytest.param('normal.txt', 'normal.txt',
|
||||||
('user/repo issues.mht', 'windows', 'user_repo issues.mht'),
|
marks=pytest.mark.fake_os('windows')),
|
||||||
('<Test\\File> - "*?:|', 'windows', '_Test_File_ - _____'),
|
pytest.param('user/repo issues.mht', 'user_repo issues.mht',
|
||||||
('<Test\\File> - "*?:|', 'mac', '<Test\\File> - "*?_|'),
|
marks=pytest.mark.fake_os('windows')),
|
||||||
('<Test\\File> - "*?:|', 'posix', '<Test\\File> - "*?:|'),
|
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):
|
def test_sanitize_filename(inp, expected, monkeypatch):
|
||||||
is_platform(monkeypatch, platform)
|
|
||||||
assert utils.sanitize_filename(inp) == expected
|
assert utils.sanitize_filename(inp) == expected
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user