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 Sep 6, 2023
1 parent 4d77c5f commit af24d68
Show file tree
Hide file tree
Showing 148 changed files with 1,259 additions and 1,392 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 @@ -342,7 +338,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 @@ -477,7 +473,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
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 @@ -273,7 +274,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 @@ -293,23 +294,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
11 changes: 6 additions & 5 deletions airgun/entities/configgroup.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.configgroup import ConfigGroupCreateView
from airgun.views.configgroup import ConfigGroupEditView
from airgun.views.configgroup import ConfigGroupsView
from airgun.views.configgroup import (
ConfigGroupCreateView,
ConfigGroupEditView,
ConfigGroupsView,
)


class ConfigGroupEntity(BaseEntity):
Expand Down
9 changes: 5 additions & 4 deletions airgun/entities/containerimagetag.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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.containerimagetag import ContainerImageTagDetailsView
from airgun.views.containerimagetag import ContainerImageTagsView
from airgun.views.containerimagetag import (
ContainerImageTagDetailsView,
ContainerImageTagsView,
)


class ContainerImageTagEntity(BaseEntity):
Expand Down
11 changes: 6 additions & 5 deletions airgun/entities/contentcredential.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.contentcredential import ContentCredentialCreateView
from airgun.views.contentcredential import ContentCredentialEditView
from airgun.views.contentcredential import ContentCredentialsTableView
from airgun.views.contentcredential import (
ContentCredentialCreateView,
ContentCredentialEditView,
ContentCredentialsTableView,
)
from airgun.views.product import ProductEditView


Expand Down
20 changes: 10 additions & 10 deletions airgun/entities/contenthost.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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.contenthost import ContentHostDetailsView
from airgun.views.contenthost import ContentHostsView
from airgun.views.contenthost import ContentHostTaskDetailsView
from airgun.views.contenthost import ErrataDetailsView
from airgun.views.contenthost import SyspurposeBulkActionView
from airgun.views.job_invocation import JobInvocationCreateView
from airgun.views.job_invocation import JobInvocationStatusView
from airgun.views.contenthost import (
ContentHostDetailsView,
ContentHostsView,
ContentHostTaskDetailsView,
ErrataDetailsView,
SyspurposeBulkActionView,
)
from airgun.views.job_invocation import JobInvocationCreateView, JobInvocationStatusView


class ContentHostEntity(BaseEntity):
Expand Down Expand Up @@ -108,7 +108,7 @@ def execute_module_stream_action(
customize_values = {}
view = self.navigate_to(self, 'Edit', entity_name=entity_name)
view.module_streams.search(f'name = {module_name} and stream = {stream_version}')
action_type = dict(is_customize=customize, action=action_type)
action_type = {'is_customize': customize, 'action': action_type}
view.module_streams.table.row(name=module_name, stream=stream_version)['Actions'].fill(
action_type
)
Expand Down
Loading

0 comments on commit af24d68

Please sign in to comment.