def is_supported(cls): """Checks whether the browser is supported on current platform :return: True if browser is supported on current platform else False :rtype: boolean """ support_check = { utils.Platform.LINUX: cls.linux_path, utils.Platform.WINDOWS: cls.windows_path, utils.Platform.MAC: cls.mac_path, } return support_check.get(utils.get_platform()) is not None
def __init__(self, plat: utils.Platform = None): if plat is None: plat = utils.get_platform() homedir = Path.home() error_string = self.name + " browser is not supported on {}" if plat == utils.Platform.WINDOWS: assert self.windows_path is not None, error_string.format("windows") self.history_dir = homedir / self.windows_path elif plat == utils.Platform.MAC: assert self.mac_path is not None, error_string.format("Mac OS") self.history_dir = homedir / self.mac_path elif plat == utils.Platform.LINUX: assert self.linux_path is not None, error_string.format("Linux") self.history_dir = homedir / self.linux_path else: self.history_dir = None if self.profile_support and not self.profile_dir_prefixes: self.profile_dir_prefixes.append("*")
def __init__(self, plat: typing.Optional[utils.Platform] = None): self.profile_dir_prefixes = [] if plat is None: plat = utils.get_platform() homedir = Path.home() error_string = ( f"{self.name} browser is not supported on {utils.get_platform_name(plat)}" ) if plat == utils.Platform.WINDOWS: assert self.windows_path is not None, error_string self.history_dir = homedir / self.windows_path elif plat == utils.Platform.MAC: assert self.mac_path is not None, error_string self.history_dir = homedir / self.mac_path elif plat == utils.Platform.LINUX: assert self.linux_path is not None, error_string self.history_dir = homedir / self.linux_path else: raise NotImplementedError() if self.profile_support and not self.profile_dir_prefixes: self.profile_dir_prefixes.append("*")
def test_plat_win(become_windows): # noqa: F811 assert get_platform() == Platform.WINDOWS
def test_plat_mac(become_mac): # noqa: F811 assert get_platform() == Platform.MAC
def test_plat_linux(become_linux): # noqa: F811 assert get_platform() == Platform.LINUX
# noqa: F401, F811 # pylint: disable=redefined-outer-name,unused-argument,unused-import import webbrowser import pytest from browser_history import browsers, utils from .utils import become_mac, become_linux, become_windows # noqa: F401 platform = utils.get_platform() class MockBrowser: """Mock version of return value of webbrowser.get()""" def __init__(self, name=None): self.name = name @pytest.fixture def change_linux_default(monkeypatch, request): """Changes utils._default_browser_linux to return a specific named browser. use @pytest.mark.browser_name(name) to set browser name """ marker = request.node.get_closest_marker("browser_name") if marker is None: browser_name = None