Skip to content

Commit

Permalink
Run pre-commit run -a
Browse files Browse the repository at this point in the history
  • Loading branch information
fsouza committed Aug 15, 2023
1 parent 39b3dd6 commit 7250437
Show file tree
Hide file tree
Showing 77 changed files with 904 additions and 821 deletions.
2 changes: 1 addition & 1 deletion docs/_templates/genindex.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "!genindex.html" %}

{% block bodyclass %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
2 changes: 1 addition & 1 deletion docs/_templates/modindex.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% extends "!modindex.html" %}
{% block bodyclass %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
2 changes: 1 addition & 1 deletion docs/_templates/search.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% extends "!search.html" %}
{% block bodyclass %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
1 change: 0 additions & 1 deletion docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ Welcome to the Splinter API documentation! Check what's inside:
element-list
request-handling
exceptions

1 change: 0 additions & 1 deletion docs/api/request-handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ Request handling

.. autoclass:: splinter.request_handler.status_code.StatusCode
:members:

13 changes: 5 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# splinter documentation build configuration file, created by
# sphinx-quickstart on Sat Jan 8 23:31:41 2011.
Expand All @@ -10,12 +9,10 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))

import os
import sys
from datetime import datetime
Expand Down Expand Up @@ -47,8 +44,8 @@
master_doc = "index"

# General information about the project.
project = u"Splinter"
copyright = u"{}, cobrateam".format(datetime.now().year)
project = "Splinter"
copyright = f"{datetime.now().year}, cobrateam"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -109,7 +106,7 @@
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
'collapse_navigation': False,
"collapse_navigation": False,
}

# Add any paths that contain custom themes here, relative to this directory.
Expand Down Expand Up @@ -192,7 +189,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
("index", "splinter.tex", u"splinter Documentation", u"andrews medina", "manual")
("index", "splinter.tex", "splinter Documentation", "andrews medina", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -223,4 +220,4 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [("index", "splinter", u"splinter Documentation", [u"andrews medina"], 1)]
man_pages = [("index", "splinter", "splinter Documentation", ["andrews medina"], 1)]
2 changes: 1 addition & 1 deletion docs/selenium-keys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ With Splinter's type() method, you can use Selenium's Keys implementation.
browser.type(Keys.RETURN)

The full list of all supported keys can be found at the official Selenium documentation:
`selenium.webdriver.common.keys <https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html>`_
`selenium.webdriver.common.keys <https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html>`_
19 changes: 10 additions & 9 deletions samples/test_facebook_events.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# -*- coding: utf-8 -*-

# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

"""
This snippet show how to "test" a Facebook feature: the creation of an event.
It creates an event by going to http://www.facebook.com, login and navigate to "Create an event" page.
"""

import os
import unittest
import time
import unittest

from splinter import Browser


Expand All @@ -30,7 +27,7 @@ def do_login_if_need(self, username, password):
self.browser.fill("email", username)
self.browser.fill("pass", password)
self.browser.find_by_css(
'div.menu_login_container input[type="submit"]'
'div.menu_login_container input[type="submit"]',
).first.click()
assert self.browser.is_element_present_by_css("li#navAccount")

Expand All @@ -49,12 +46,15 @@ def test_create_event(self):

# Uploading the picture
picture_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "img", "turtles.jpg"
os.path.abspath(os.path.dirname(__file__)),
"img",
"turtles.jpg",
)
self.browser.find_by_css("div.eventEditUpload a.uiButton").first.click()

if not self.browser.is_element_present_by_css(
"iframe#upload_pic_frame", wait_time=10
"iframe#upload_pic_frame",
wait_time=10,
):
self.fail("The upload pic iframe didn't appear :(")

Expand All @@ -68,7 +68,8 @@ def test_create_event(self):
self.browser.fill("name", "Splinter sprint")
self.browser.fill("location", "Rio de Janeiro, Brazil")
self.browser.fill(
"desc", "For more info, check out the #cobratem channel on freenode!"
"desc",
"For more info, check out the #cobratem channel on freenode!",
)

self.browser.find_by_css('label.uiButton input[type="submit"]').first.click()
Expand Down
3 changes: 1 addition & 2 deletions samples/test_google_search.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python

# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import unittest

from splinter import Browser


Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
Expand All @@ -10,7 +9,7 @@

def read(filename: str) -> str:
path = os.path.join(os.path.dirname(__file__), filename)
with open(path, "r") as f:
with open(path) as f:
return f.read()


Expand Down
8 changes: 4 additions & 4 deletions splinter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright 2016 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from splinter.browser import Browser
from splinter.config import Config
from splinter.version import __version_info__, __version__ # NOQA
from splinter.version import __version__ # noqa: F401
from splinter.version import __version_info__ # noqa: F401


__all__ = [
'Browser',
'Config',
"Browser",
"Config",
]
53 changes: 29 additions & 24 deletions splinter/browser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-

# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.


import logging

from http.client import HTTPException
from typing import Dict, Tuple, Type, Union
from typing import Dict
from typing import Tuple
from typing import Type
from typing import Union

from urllib3.exceptions import MaxRetryError

Expand All @@ -21,62 +19,63 @@

try:
from selenium.common.exceptions import WebDriverException

driver_exceptions += (WebDriverException,)
except ImportError as e:
logger.debug(f"Import Warning: {e}")


_DRIVERS: Dict[str, Union[None, Type[DriverAPI]]] = {
'chrome': None,
'edge': None,
'firefox': None,
'remote': None,
'django': None,
'flask': None,
'zope.testbrowser': None,
"chrome": None,
"edge": None,
"firefox": None,
"remote": None,
"django": None,
"flask": None,
"zope.testbrowser": None,
}

try:
from splinter.driver.webdriver.chrome import WebDriver as ChromeWebDriver
from splinter.driver.webdriver.firefox import WebDriver as FirefoxWebDriver
from splinter.driver.webdriver.remote import WebDriver as RemoteWebDriver

_DRIVERS['chrome'] = ChromeWebDriver
_DRIVERS['firefox'] = FirefoxWebDriver
_DRIVERS['remote'] = RemoteWebDriver
_DRIVERS["chrome"] = ChromeWebDriver
_DRIVERS["firefox"] = FirefoxWebDriver
_DRIVERS["remote"] = RemoteWebDriver
except ImportError as e:
logger.debug(f'Import Warning: {e}')
logger.debug(f"Import Warning: {e}")

try:
from splinter.driver.webdriver.edge import WebDriver as EdgeWebDriver

_DRIVERS["edge"] = EdgeWebDriver
except ImportError as e:
logger.debug(f'Import Warning: {e}')
logger.debug(f"Import Warning: {e}")


try:
from splinter.driver.zopetestbrowser import ZopeTestBrowser

_DRIVERS["zope.testbrowser"] = ZopeTestBrowser
except ImportError as e:
logger.debug(f'Import Warning: {e}')
logger.debug(f"Import Warning: {e}")

try:
import django # noqa
from splinter.driver.djangoclient import DjangoClient

_DRIVERS["django"] = DjangoClient
except ImportError as e:
logger.debug(f'Import Warning: {e}')
logger.debug(f"Import Warning: {e}")

try:
import flask # noqa
from splinter.driver.flaskclient import FlaskClient

_DRIVERS["flask"] = FlaskClient
except ImportError as e:
logger.debug(f'Import Warning: {e}')
logger.debug(f"Import Warning: {e}")


def get_driver(driver, retry_count=3, config=None, *args, **kwargs):
Expand All @@ -97,7 +96,13 @@ def get_driver(driver, retry_count=3, config=None, *args, **kwargs):
raise err


def Browser(driver_name: str = "firefox", retry_count: int = 3, config=None, *args, **kwargs): # NOQA: N802
def Browser(
driver_name: str = "firefox",
retry_count: int = 3,
config=None,
*args,
**kwargs,
): # NOQA: N802
"""Get a new driver instance.
Extra arguments will be sent to the driver instance.
Expand All @@ -117,9 +122,9 @@ def Browser(driver_name: str = "firefox", retry_count: int = 3, config=None, *ar
try:
driver = _DRIVERS[driver_name]
except KeyError:
raise DriverNotFoundError(f'{driver_name} is not a recognized driver.')
raise DriverNotFoundError(f"{driver_name} is not a recognized driver.")

if driver is None:
raise DriverNotFoundError(f'Driver for {driver_name} was not found.')
raise DriverNotFoundError(f"Driver for {driver_name} was not found.")

return get_driver(driver, retry_count=retry_count, config=config, *args, **kwargs)
4 changes: 3 additions & 1 deletion splinter/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from typing import List, Optional
from typing import List
from typing import Optional


@dataclass
Expand Down Expand Up @@ -43,6 +44,7 @@ class Config:
user_agent: Set a custom user_agent.
"""

extensions: Optional[List[str]] = None
fullscreen: Optional[bool] = False
headless: Optional[bool] = False
Expand Down
3 changes: 0 additions & 3 deletions splinter/cookie_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from splinter.meta import InheritedDocs


Expand Down
Loading

0 comments on commit 7250437

Please sign in to comment.