Skip to content

Commit

Permalink
Introduce new project code standards
Browse files Browse the repository at this point in the history
This change adds Ruff as the new linter and loosens Black's formatting
as well.
Due to this change, we can drop flake8 and old pre-commit hooks.
  • Loading branch information
JacobCallahan committed Aug 23, 2023
1 parent 17a7ea5 commit a3602a9
Show file tree
Hide file tree
Showing 154 changed files with 1,362 additions and 1,505 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ settings.ini

# common venv name
.airgun/
venv*

20 changes: 5 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
# configuration for pre-commit git hooks

repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.0.1
hooks:
- id: reorder-python-imports
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.0
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
1 change: 0 additions & 1 deletion airgun/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from airgun.settings import Settings


settings = Settings()
24 changes: 10 additions & 14 deletions airgun/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
tests.
"""
import base64
from contextlib import contextmanager
from datetime import datetime
import logging
import os
import time
import urllib
from contextlib import contextmanager
from datetime import datetime
from urllib.parse import unquote

import yaml
from box import Box
from selenium import webdriver
from wait_for import TimedOutError
from wait_for import wait_for
from wait_for import TimedOutError, wait_for
from webdriver_kaifuku import BrowserManager
from widgetastic.browser import Browser
from widgetastic.browser import DefaultPlugin
from widgetastic.exceptions import NoAlertPresentException
from widgetastic.exceptions import NoSuchElementException
from widgetastic.browser import Browser, DefaultPlugin
from widgetastic.exceptions import NoAlertPresentException, NoSuchElementException
import yaml

from airgun import settings
from airgun.widgets import ConfirmationDialog
from airgun.widgets import Pf4ConfirmationDialog
from airgun.widgets import ConfirmationDialog, Pf4ConfirmationDialog

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -116,7 +112,7 @@ def finalize(self, passed=True):
or not. Is only used for ``saucelabs`` provider.
:return: None
"""
if self.provider == 'selenium' or self.provider == 'remote':
if self.provider in ('selenium', 'remote'):
self._webdriver.quit()
return

Expand Down Expand Up @@ -350,7 +346,7 @@ def get_downloads_list(self):
'.filter(e => e.state === "COMPLETE")'
'.map(e => e.file_url || e.fileUrl);'
)
if self.browser_type == 'chrome' and self.browser_version >= 79:
if self.browser_type == 'chrome':
script = (
'return document.querySelector("downloads-manager")'
'.shadowRoot.querySelector("#downloadsList")'
Expand Down Expand Up @@ -485,7 +481,7 @@ def handle_alert(
):
"""Extend the behaviour of widgetstatic.browser.handle_alert to handle PF4 alerts"""
popup = self.get_alert(squash=squash)
if isinstance(popup, (Pf4ConfirmationDialog, ConfirmationDialog)):
if isinstance(popup, Pf4ConfirmationDialog | ConfirmationDialog):
if cancel:
self.logger.info(" dismissing")
popup.cancel()
Expand Down
40 changes: 21 additions & 19 deletions airgun/entities/acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
from wait_for import wait_for

from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.acs import AddAlternateContentSourceModal
from airgun.views.acs import AlternateContentSourcesView
from airgun.views.acs import EditCapsulesModal
from airgun.views.acs import EditCredentialsModal
from airgun.views.acs import EditDetailsModal
from airgun.views.acs import EditProductsModal
from airgun.views.acs import EditUrlAndSubpathsModal
from airgun.views.acs import RowDrawer
from airgun.views.acs import (
AddAlternateContentSourceModal,
AlternateContentSourcesView,
EditCapsulesModal,
EditCredentialsModal,
EditDetailsModal,
EditProductsModal,
EditUrlAndSubpathsModal,
RowDrawer,
)


class AcsEntity(BaseEntity):
Expand Down Expand Up @@ -456,14 +457,15 @@ def edit_credentials(
must be specified when using credentials
"""

if check_parameters:
if (acs_name_to_edit is None) and (
sum([manual_auth, content_credentials_auth, none_auth] != 1)
):
raise ValueError(
'At least acs_name_to_edit and one of '
'manual_auth, content_credentials_auth, none_auth must be specified!'
)
if (
check_parameters
and acs_name_to_edit is None
and (sum([manual_auth, content_credentials_auth, none_auth] != 1))
):
raise ValueError(
'At least acs_name_to_edit and one of '
'manual_auth, content_credentials_auth, none_auth must be specified!'
)

view = self.edit_helper(acs_name_to_edit)
view.credentials.edit_credentials.click()
Expand Down Expand Up @@ -571,7 +573,7 @@ def edit_products(
)
self.close_details_side_panel()

def create_new_acs(
def create_new_acs( # noqa: C901 - function is too complex
self,
custom_type=False,
simplified_type=False,
Expand Down
11 changes: 6 additions & 5 deletions airgun/entities/activationkey.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from navmazing import NavigateToSibling

from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.activationkey import ActivationKeyCreateView
from airgun.views.activationkey import ActivationKeyEditView
from airgun.views.activationkey import ActivationKeysView
from airgun.views.activationkey import (
ActivationKeyCreateView,
ActivationKeyEditView,
ActivationKeysView,
)


class ActivationKeyEntity(BaseEntity):
Expand Down
6 changes: 2 additions & 4 deletions airgun/entities/ansible_role.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from navmazing import NavigateToSibling

from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.views.ansible_role import AnsibleRolesImportView
from airgun.views.ansible_role import AnsibleRolesView
from airgun.navigation import NavigateStep, navigator
from airgun.views.ansible_role import AnsibleRolesImportView, AnsibleRolesView


class AnsibleRolesEntity(BaseEntity):
Expand Down
6 changes: 2 additions & 4 deletions airgun/entities/ansible_variable.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from navmazing import NavigateToSibling

from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.views.ansible_variable import AnsibleVariablesView
from airgun.views.ansible_variable import NewAnsibleVariableView
from airgun.navigation import NavigateStep, navigator
from airgun.views.ansible_variable import AnsibleVariablesView, NewAnsibleVariableView


class AnsibleVariablesEntity(BaseEntity):
Expand Down
11 changes: 6 additions & 5 deletions airgun/entities/architecture.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from navmazing import NavigateToSibling

from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.architecture import ArchitectureCreateView
from airgun.views.architecture import ArchitectureDetailsView
from airgun.views.architecture import ArchitecturesView
from airgun.views.architecture import (
ArchitectureCreateView,
ArchitectureDetailsView,
ArchitecturesView,
)


class ArchitectureEntity(BaseEntity):
Expand Down
3 changes: 1 addition & 2 deletions airgun/entities/audit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.audit import AuditsView

Expand Down
1 change: 0 additions & 1 deletion airgun/entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class BaseEntity:

HELPER_CLASS = BaseEntityHelper

def __init__(self, browser):
Expand Down
6 changes: 2 additions & 4 deletions airgun/entities/bookmark.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.bookmark import BookmarkEditView
from airgun.views.bookmark import BookmarksView
from airgun.views.bookmark import BookmarkEditView, BookmarksView


def _gen_queries(entity_name, controller=None):
Expand Down
6 changes: 2 additions & 4 deletions airgun/entities/cloud_insights.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.cloud_insights import CloudInsightsView
from airgun.views.cloud_insights import CloudTokenView
from airgun.views.cloud_insights import CloudInsightsView, CloudTokenView
from airgun.views.job_invocation import JobInvocationCreateView


Expand Down
3 changes: 1 addition & 2 deletions airgun/entities/cloud_inventory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.cloud_inventory import CloudInventoryListView

Expand Down
13 changes: 7 additions & 6 deletions airgun/entities/computeprofile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from navmazing import NavigateToSibling

from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.computeprofile import ComputeProfileCreateView
from airgun.views.computeprofile import ComputeProfileDetailView
from airgun.views.computeprofile import ComputeProfileRenameView
from airgun.views.computeprofile import ComputeProfilesView
from airgun.views.computeprofile import (
ComputeProfileCreateView,
ComputeProfileDetailView,
ComputeProfileRenameView,
ComputeProfilesView,
)


class ComputeProfileEntity(BaseEntity):
Expand Down
45 changes: 22 additions & 23 deletions airgun/entities/computeresource.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from navmazing import NavigateToSibling

from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.computeresource import ComputeResourceRHVImageCreateView
from airgun.views.computeresource import ComputeResourceRHVImageEditView
from airgun.views.computeresource import ComputeResourcesView
from airgun.views.computeresource import ComputeResourceVMwareImageCreateView
from airgun.views.computeresource import ComputeResourceVMwareImageEditView
from airgun.views.computeresource import ResourceProviderCreateView
from airgun.views.computeresource import ResourceProviderDetailView
from airgun.views.computeresource import ResourceProviderEditView
from airgun.views.computeresource import ResourceProviderProfileView
from airgun.views.computeresource import ResourceProviderVMImport
from airgun.views.computeresource import (
ComputeResourceRHVImageCreateView,
ComputeResourceRHVImageEditView,
ComputeResourcesView,
ComputeResourceVMwareImageCreateView,
ComputeResourceVMwareImageEditView,
ResourceProviderCreateView,
ResourceProviderDetailView,
ResourceProviderEditView,
ResourceProviderProfileView,
ResourceProviderVMImport,
)


class ComputeResourceEntity(BaseEntity):
Expand Down Expand Up @@ -277,7 +278,7 @@ class ComputeResourceImageProvider(NavigateStep):
(that depend from compute resource provider) before reaching navigation destination.
"""

PROVIDER_VIEWS = dict()
PROVIDER_VIEWS = {}

def prerequisite(self, *args, **kwargs):
entity_name = kwargs.get('entity_name')
Expand All @@ -297,23 +298,21 @@ def am_i_here(self, *args, **kwargs):

@navigator.register(ComputeResourceEntity, 'Create Image')
class ComputeResourceImageCreate(ComputeResourceImageProvider):

PROVIDER_VIEWS = dict(
RHV=ComputeResourceRHVImageCreateView,
VMware=ComputeResourceVMwareImageCreateView,
)
PROVIDER_VIEWS = {
'RHV': ComputeResourceRHVImageCreateView,
'VMware': ComputeResourceVMwareImageCreateView,
}

def step(self, *args, **kwargs):
self.parent.create_image.click()


@navigator.register(ComputeResourceEntity, 'Edit Image')
class ComputeResourceImageEdit(ComputeResourceImageProvider):

PROVIDER_VIEWS = dict(
RHV=ComputeResourceRHVImageEditView,
VMware=ComputeResourceVMwareImageEditView,
)
PROVIDER_VIEWS = {
'RHV': ComputeResourceRHVImageEditView,
'VMware': ComputeResourceVMwareImageEditView,
}

def step(self, *args, **kwargs):
image_name = kwargs.get('image_name')
Expand Down
6 changes: 2 additions & 4 deletions airgun/entities/config_report.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from airgun.entities.base import BaseEntity
from airgun.navigation import NavigateStep
from airgun.navigation import navigator
from airgun.navigation import NavigateStep, navigator
from airgun.utils import retry_navigation
from airgun.views.config_report import ConfigReportDetailsView
from airgun.views.config_report import ConfigReportsView
from airgun.views.config_report import ConfigReportDetailsView, ConfigReportsView


class ConfigReportEntity(BaseEntity):
Expand Down
Loading

0 comments on commit a3602a9

Please sign in to comment.