Ejemplo n.º 1
0
    def test_find_executable(self):
        with tempfile.NamedTemporaryFile(prefix="test_not_executable_", delete=False) as f:
            filepath = Path(f.name).resolve()
            self.assertTrue(filepath.is_file())
            name = filepath.name
            path = filepath.parent

            # File is not in PATH:
            with self.assertRaises(FileNotFoundError) as context_manager:
                find_executable(name)

            assert_pformat_equal(context_manager.exception.args, ("Can't find '%s' in PATH or None!" % name,))

            old_path = os.environ["PATH"]
            try:
                # File is in PATH, but not executable:
                os.environ["PATH"] += "%s%s" % (os.pathsep, path)
                with self.assertRaises(FileNotFoundError) as context_manager:
                    find_executable(name)

                assert_pformat_equal(
                    context_manager.exception.args, ("%s exists, but it's not executable!" % filepath,)
                )

                # File is in PATH and executable:
                filepath.chmod(0x777)
                result = find_executable(name)
                assert_pformat_equal(result, filepath)
            finally:
                os.environ["PATH"] = old_path

            # Executable file is not in PATH, but can be found via extra_search_paths:
            result = find_executable(name, extra_search_paths=(path,))
            assert_pformat_equal(result, filepath)
Ejemplo n.º 2
0
def chromium_available(filename=None):
    """
    :return: True/False if 'chromium-chromedriver' executable can be found

    >>> chromium_available("doesn't exists")
    False
    """
    if filename is None:
        filename = SeleniumChromiumTestCase.filename

    try:
        executable = find_executable(filename, SeleniumChromiumTestCase.extra_search_paths)
    except FileNotFoundError as err:
        log.error("Chromium is no available: %s")
        return False

    log.debug("Chromium found here: %s" % executable)
    return True
Ejemplo n.º 3
0
def firefox_available(filename=None):
    """
    :return: True/False if 'firefox-chromedriver' executable can be found

    >>> firefox_available("doesn't exists")
    False
    """
    if filename is None:
        filename = SeleniumFirefoxTestCase.filename

    try:
        executable = find_executable(filename, SeleniumFirefoxTestCase.extra_search_paths)
    except FileNotFoundError as err:
        log.error("Firefox is no available: %s", err)
        return False

    log.debug(f"Firefox found here: {executable}")
    return True
Ejemplo n.º 4
0
def chromium_available(filename=None):
    """
    :return: True/False if 'chromium-chromedriver' executable can be found

    >>> chromium_available("doesn't exists")
    False
    """
    if filename is None:
        filename = SeleniumChromiumTestCase.filename

    try:
        executable = find_executable(
            filename, SeleniumChromiumTestCase.extra_search_paths)
    except FileNotFoundError as err:
        log.error("Chromium is no available: %s")
        return False

    log.debug("Chromium found here: %s" % executable)
    return True
Ejemplo n.º 5
0
    def setUpClass(cls):
        options = webdriver.FirefoxOptions()
        for argument in cls.options:
            options.add_argument(argument)

        try:
            executable = find_executable(cls.filename, cls.extra_search_paths)
        except FileNotFoundError:
            cls.driver = None
        else:
            desired = DesiredCapabilities.FIREFOX
            for key, value in cls.desired_capabilities.items():
                desired[key] = value

            cls.driver = webdriver.Firefox(
                firefox_options=options,
                executable_path=str(executable),  # Path() instance -> str()
                desired_capabilities=desired,
            )
            cls.driver.implicitly_wait(10)

        super().setUpClass()
Ejemplo n.º 6
0
    def setUpClass(cls):
        options = webdriver.FirefoxOptions()
        for argument in cls.options:
            options.add_argument(argument)

        try:
            executable = find_executable(cls.filename, cls.extra_search_paths)
        except FileNotFoundError:
            cls.driver = None
        else:
            desired = DesiredCapabilities.FIREFOX
            for key, value in cls.desired_capabilities.items():
                desired[key] = value

            cls.driver = webdriver.Firefox(
                firefox_options=options,
                executable_path=str(executable),  # Path() instance -> str()
                desired_capabilities=desired,
            )
            cls.driver.implicitly_wait(10)

        super().setUpClass()
Ejemplo n.º 7
0
    def test_find_executable(self):
        with tempfile.NamedTemporaryFile(prefix="test_not_executable_",
                                         delete=False) as f:
            filepath = Path(f.name).resolve()
            self.assertTrue(filepath.is_file())
            name = filepath.name
            path = filepath.parent

            # File is not in PATH:
            with self.assertRaises(FileNotFoundError) as context_manager:
                find_executable(name)

            assert_pformat_equal(context_manager.exception.args,
                                 (f"Can't find '{name}' in PATH or None!", ))

            old_path = os.environ["PATH"]
            try:
                # File is in PATH, but not executable:
                os.environ["PATH"] += f"{os.pathsep}{path}"
                with self.assertRaises(FileNotFoundError) as context_manager:
                    find_executable(name)

                assert_pformat_equal(
                    context_manager.exception.args,
                    (f"{filepath} exists, but it's not executable!", ))

                # File is in PATH and executable:
                filepath.chmod(0x777)
                result = find_executable(name)
                assert_pformat_equal(result, filepath)
            finally:
                os.environ["PATH"] = old_path

            # Executable file is not in PATH, but can be found via extra_search_paths:
            result = find_executable(name, extra_search_paths=(path, ))
            assert_pformat_equal(result, filepath)