From 1abfc039657d5f40a013cb1c517f4b9c95823e57 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 8 Oct 2018 17:41:12 +0200 Subject: [PATCH] Use pytest.mark.fake_os --- tests/unit/browser/webkit/test_downloads.py | 24 +++++++----------- tests/unit/utils/test_utils.py | 28 +++++++++------------ 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/tests/unit/browser/webkit/test_downloads.py b/tests/unit/browser/webkit/test_downloads.py index 94a11d552..91e778f8c 100644 --- a/tests/unit/browser/webkit/test_downloads.py +++ b/tests/unit/browser/webkit/test_downloads.py @@ -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() diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index 3117b6a27..b901d2d74 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -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'), - (' - "*?:|', 'windows', '_Test_File_ - _____'), - (' - "*?:|', 'mac', ' - "*?_|'), - (' - "*?:|', 'posix', ' - "*?:|'), +@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_ - _____', + marks=pytest.mark.fake_os('windows')), + pytest.param(' - "*?:|', ' - "*?_|', + marks=pytest.mark.fake_os('mac')), + pytest.param(' - "*?:|', ' - "*?:|', + 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