Adding patch for webbrowser on macOS
This commit is contained in:
@@ -5,13 +5,15 @@ import time
|
||||
import curses
|
||||
from collections import OrderedDict
|
||||
|
||||
import os
|
||||
import six
|
||||
import pytest
|
||||
import requests
|
||||
from six.moves import reload_module
|
||||
|
||||
from rtv import exceptions
|
||||
from rtv.objects import Color, Controller, Navigator, Command, KeyMap, \
|
||||
curses_session
|
||||
curses_session, patch_webbrowser
|
||||
|
||||
try:
|
||||
from unittest import mock
|
||||
@@ -19,6 +21,28 @@ except ImportError:
|
||||
import mock
|
||||
|
||||
|
||||
@mock.patch.dict(os.environ, {'BROWSER': 'safari'})
|
||||
@mock.patch('sys.platform', 'darwin')
|
||||
@mock.patch('shutil.which', return_value=None) # py3 method
|
||||
@mock.patch('os.path.isfile', return_value=None) # py2 method
|
||||
def test_patch_webbrowser(which, isfile):
|
||||
|
||||
# Make sure that webbrowser re-generates the browser list using the
|
||||
# mocked environment
|
||||
import webbrowser
|
||||
webbrowser = reload_module(webbrowser)
|
||||
|
||||
# By default, we expect that BROWSER will be loaded as a generic browser
|
||||
# This is because "safari" is not a valid script in the system PATH
|
||||
assert isinstance(webbrowser.get(), webbrowser.GenericBrowser)
|
||||
|
||||
# After patching, the default webbrowser should now be interpreted as an
|
||||
# OSAScript browser
|
||||
patch_webbrowser()
|
||||
assert isinstance(webbrowser.get(), webbrowser.MacOSXOSAScript)
|
||||
assert webbrowser._tryorder[0] == 'safari'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('use_ascii', [True, False])
|
||||
def test_objects_load_screen(terminal, stdscr, use_ascii):
|
||||
terminal.config['ascii'] = use_ascii
|
||||
|
||||
Reference in New Issue
Block a user