From 680ae89ffd82795c52c7b2322f19bdd5819de613 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 26 Jun 2018 17:47:10 +1200 Subject: [PATCH] Also mock platform to windows for utils tests. This is the same fixture I added in tests/unit/browser/webkit/test_downloads.py --- tests/unit/utils/test_utils.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index ef2b6c8d4..b8f9b932e 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -113,6 +113,14 @@ 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): @@ -629,12 +637,15 @@ def test_force_encoding(inp, enc, expected): assert utils.force_encoding(inp, enc) == expected -@pytest.mark.parametrize('inp, expected', [ - ('normal.txt', 'normal.txt'), - ('user/repo issues.mht', 'user_repo issues.mht'), - (' - "*?:|', '_Test_File_ - _____'), +@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', ' - "*?:|'), ]) -def test_sanitize_filename(inp, expected): +def test_sanitize_filename(inp, platform, expected, monkeypatch): + is_platform(monkeypatch, platform) assert utils.sanitize_filename(inp) == expected