Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Add pre-commit hook for black (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
davehunt authored and jrbenny35 committed Sep 12, 2018
1 parent 1d3b2c9 commit d869b56
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 143 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ FoxPuppet is a library for automating user interactions in `Firefox <https://www
:target: https://coveralls.io/github/mozilla/FoxPuppet
:alt: Coverage

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black

.. image:: https://img.shields.io/github/issues/mozilla/FoxPuppet.svg
:target: https://github.com/mozilla/FoxPuppet/issues
:alt: Issues
Expand Down
65 changes: 33 additions & 32 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))


# -- General configuration ------------------------------------------------
Expand All @@ -32,42 +33,43 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
'sphinx.ext.todo',
]
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinx.ext.todo",
]

# intersphinx mappings
intersphinx_mapping = {
'selenium': ('http://seleniumhq.github.io/selenium/docs/api/py/', None)}
"selenium": ("http://seleniumhq.github.io/selenium/docs/api/py/", None)
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'FoxPuppet'
copyright = '2017, Mozilla'
author = 'Mozilla'
project = "FoxPuppet"
copyright = "2017, Mozilla"
author = "Mozilla"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = 'latest'
version = "latest"
# The full version, including alpha/beta/rc tags.
release = 'latest'
release = "latest"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -79,10 +81,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
Expand All @@ -93,7 +95,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'default'
html_theme = "default"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -110,7 +112,7 @@
# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'FoxPuppetdoc'
htmlhelp_basename = "FoxPuppetdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -119,15 +121,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -137,19 +136,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'FoxPuppet.tex', 'FoxPuppet Documentation',
'Mozilla', 'manual'),
(master_doc, "FoxPuppet.tex", "FoxPuppet Documentation", "Mozilla", "manual")
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'foxpuppet', 'FoxPuppet Documentation',
[author], 1)
]
man_pages = [(master_doc, "foxpuppet", "FoxPuppet Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -158,7 +153,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'FoxPuppet', 'FoxPuppet Documentation',
author, 'FoxPuppet', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"FoxPuppet",
"FoxPuppet Documentation",
author,
"FoxPuppet",
"One line description of project.",
"Miscellaneous",
)
]
2 changes: 1 addition & 1 deletion foxpuppet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

from foxpuppet.foxpuppet import FoxPuppet

__all__ = ['FoxPuppet']
__all__ = ["FoxPuppet"]
1 change: 1 addition & 0 deletions foxpuppet/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ def __call__(self, *args, **kwargs):
handles = list(set(self.selenium.window_handles) - set(self.handles))
if len(handles) == 1:
from foxpuppet.windows import BrowserWindow

return BrowserWindow(self.selenium, handles[0])
6 changes: 3 additions & 3 deletions foxpuppet/windows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class BaseWindow(object):
"""A base window model."""

_document_element = (By.CSS_SELECTOR, ':root')
_document_element = (By.CSS_SELECTOR, ":root")

def __init__(self, selenium, handle):
"""Create a BaseWindow object.
Expand Down Expand Up @@ -44,8 +44,8 @@ def firefox_version(self):
int: Major component of the Firefox version.
"""
version = self.selenium.capabilities['browserVersion']
return int(version.partition('.')[0])
version = self.selenium.capabilities["browserVersion"]
return int(version.partition(".")[0])

def close(self):
"""Close the window."""
Expand Down
12 changes: 5 additions & 7 deletions foxpuppet/windows/browser/navbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class NavBar(Region):
"""

_tracking_protection_shield_locator = (
By.ID, 'tracking-protection-icon-box')
_tracking_protection_shield_locator = (By.ID, "tracking-protection-icon-box")

@property
def is_tracking_shield_displayed(self):
Expand All @@ -33,8 +32,7 @@ def is_tracking_shield_displayed(self):
"""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
if self.window.firefox_version >= 63: # Bug 1471713, 1476218
el = self.root.find_element(
*self._tracking_protection_shield_locator)
return el.get_attribute('active') is not None
el = self.root.find_element(By.ID, 'tracking-protection-icon')
return bool(el.get_attribute('state'))
el = self.root.find_element(*self._tracking_protection_shield_locator)
return el.get_attribute("active") is not None
el = self.root.find_element(By.ID, "tracking-protection-icon")
return bool(el.get_attribute("state"))
3 changes: 1 addition & 2 deletions foxpuppet/windows/browser/notifications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
"""Contains the notification interaction API and supporting files."""

from foxpuppet.windows.browser.notifications.base import ( # noqa: F401
BaseNotification)
from foxpuppet.windows.browser.notifications.base import BaseNotification # noqa: F401
30 changes: 15 additions & 15 deletions foxpuppet/windows/browser/notifications/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class AddOnInstallBlocked(BaseNotification):
def allow(self):
"""Allow the add-on to be installed."""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
self.root.find_anonymous_element_by_attribute(
'anonid', 'button').click()
self.root.find_anonymous_element_by_attribute("anonid", "button").click()


class AddOnInstallConfirmation(BaseNotification):
Expand All @@ -31,20 +30,21 @@ def addon_name(self):
"""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
el = self.root.find_anonymous_element_by_attribute(
'class', 'popup-notification-description')
return el.find_element(By.CSS_SELECTOR, 'b').text
"class", "popup-notification-description"
)
return el.find_element(By.CSS_SELECTOR, "b").text

def cancel(self):
"""Cancel add-on install."""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
self.root.find_anonymous_element_by_attribute(
'anonid', 'secondarybutton').click()
"anonid", "secondarybutton"
).click()

def install(self):
"""Confirm add-on install."""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
self.root.find_anonymous_element_by_attribute(
'anonid', 'button').click()
self.root.find_anonymous_element_by_attribute("anonid", "button").click()


class AddOnInstallComplete(BaseNotification):
Expand All @@ -64,12 +64,12 @@ class AddOnProgress(BaseNotification):


NOTIFICATIONS = {
'addon-install-blocked-notification': AddOnInstallBlocked,
'addon-install-confirmation-notification': AddOnInstallConfirmation,
'addon-install-complete-notification': AddOnInstallComplete,
'addon-install-restart-notification': AddOnInstallRestart,
'addon-install-failed-notification': AddOnInstallFailed,
'addon-installed-notification': AddOnInstallComplete,
'addon-progress-notification': AddOnProgress,
'addon-webext-permissions-notification': AddOnInstallConfirmation,
"addon-install-blocked-notification": AddOnInstallBlocked,
"addon-install-confirmation-notification": AddOnInstallConfirmation,
"addon-install-complete-notification": AddOnInstallComplete,
"addon-install-restart-notification": AddOnInstallRestart,
"addon-install-failed-notification": AddOnInstallFailed,
"addon-installed-notification": AddOnInstallComplete,
"addon-progress-notification": AddOnProgress,
"addon-webext-permissions-notification": AddOnInstallConfirmation,
}
10 changes: 6 additions & 4 deletions foxpuppet/windows/browser/notifications/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def create(window, root):
"""
notifications = {}
_id = root.get_property('id')
_id = root.get_property("id")
from foxpuppet.windows.browser.notifications import addons

notifications.update(addons.NOTIFICATIONS)
return notifications.get(_id, BaseNotification)(window, root)

Expand All @@ -44,7 +45,7 @@ def label(self):
"""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
return self.root.get_attribute('label')
return self.root.get_attribute("label")

@property
def origin(self):
Expand All @@ -55,11 +56,12 @@ def origin(self):
"""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
return self.root.get_attribute('origin')
return self.root.get_attribute("origin")

def close(self):
"""Close the notification."""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
self.root.find_anonymous_element_by_attribute(
'anonid', 'closebutton').click()
"anonid", "closebutton"
).click()
self.window.wait_for_notification(None)

0 comments on commit d869b56

Please sign in to comment.