Add flake8 pre-commit hook
Change-Id: I1893f9031091fb02e62633d2ee387aff2b967237
This commit is contained in:
parent
5252001658
commit
cecb2b1cde
|
@ -18,6 +18,13 @@ repos:
|
||||||
args: [requirements.txt, test-requirements.txt, extra-requirements.txt, linters-requirements.txt, doc/requirements.txt, infrared_plugin/requirements.txt]
|
args: [requirements.txt, test-requirements.txt, extra-requirements.txt, linters-requirements.txt, doc/requirements.txt, infrared_plugin/requirements.txt]
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
|
|
||||||
|
- repo: https://gitlab.com/pycqa/flake8
|
||||||
|
rev: '3.8.3' # pick a git hash / tag to point to
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
additional_dependencies: [flake8-import-order]
|
||||||
|
files: ^tobiko/
|
||||||
|
|
||||||
# - repo: https://github.com/adrienverge/yamllint.git
|
# - repo: https://github.com/adrienverge/yamllint.git
|
||||||
# rev: v1.23.0
|
# rev: v1.23.0
|
||||||
# hooks:
|
# hooks:
|
||||||
|
|
|
@ -16,7 +16,6 @@ from __future__ import absolute_import
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
import testtools
|
import testtools
|
||||||
from testtools import content
|
from testtools import content
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,10 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
import testtools
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
import testtools
|
|
||||||
|
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
|
|
||||||
from tobiko.openstack.neutron import _client
|
from tobiko.openstack.neutron import _client
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ from __future__ import absolute_import
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
|
|
||||||
from tobiko.openstack.neutron import _client
|
from tobiko.openstack.neutron import _client
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,8 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
import podman
|
import podman
|
||||||
|
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.podman import _exception
|
from tobiko.podman import _exception
|
||||||
from tobiko.podman import _shell
|
from tobiko.podman import _shell
|
||||||
|
@ -56,9 +53,6 @@ class PodmanClientFixture(tobiko.SharedFixture):
|
||||||
ssh_client = None
|
ssh_client = None
|
||||||
|
|
||||||
def __init__(self, ssh_client=None):
|
def __init__(self, ssh_client=None):
|
||||||
if six.PY2:
|
|
||||||
raise _exception.PodmanError(
|
|
||||||
"Podman isn't compatible with python 2.7")
|
|
||||||
super(PodmanClientFixture, self).__init__()
|
super(PodmanClientFixture, self).__init__()
|
||||||
if ssh_client:
|
if ssh_client:
|
||||||
self.ssh_client = ssh_client
|
self.ssh_client = ssh_client
|
||||||
|
|
|
@ -19,7 +19,6 @@ import io
|
||||||
import select
|
import select
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
|
@ -21,7 +21,6 @@ import time
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
|
|
||||||
from tobiko.shell.sh import _command
|
from tobiko.shell.sh import _command
|
||||||
from tobiko.shell.sh import _exception
|
from tobiko.shell.sh import _exception
|
||||||
from tobiko.shell.sh import _io
|
from tobiko.shell.sh import _io
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
|
|
@ -16,9 +16,8 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import testtools
|
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
import testtools
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.openstack import neutron
|
from tobiko.openstack import neutron
|
||||||
|
@ -28,6 +27,7 @@ from tobiko.openstack import topology
|
||||||
from tobiko.shell import ping
|
from tobiko.shell import ping
|
||||||
from tobiko.shell import sh
|
from tobiko.shell import sh
|
||||||
|
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from oslo_log import log
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.shell import sh
|
from tobiko.shell import sh
|
||||||
from tobiko.openstack import topology
|
from tobiko.openstack import topology
|
||||||
|
@ -11,7 +13,6 @@ from tobiko.openstack import keystone
|
||||||
from tobiko.tripleo import pacemaker
|
from tobiko.tripleo import pacemaker
|
||||||
from tobiko.tripleo import containers
|
from tobiko.tripleo import containers
|
||||||
from tobiko.tripleo import nova
|
from tobiko.tripleo import nova
|
||||||
from oslo_log import log
|
|
||||||
from tobiko.tests.faults.ha import test_cloud_recovery
|
from tobiko.tests.faults.ha import test_cloud_recovery
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,9 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import testtools
|
|
||||||
|
|
||||||
from docker import client as docker_client
|
from docker import client as docker_client
|
||||||
from docker.models import containers
|
from docker.models import containers
|
||||||
|
import testtools
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko import docker
|
from tobiko import docker
|
||||||
|
|
|
@ -14,8 +14,9 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import tobiko
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
import tobiko
|
||||||
from tobiko.openstack import stacks
|
from tobiko.openstack import stacks
|
||||||
from tobiko.openstack import neutron
|
from tobiko.openstack import neutron
|
||||||
from tobiko.openstack import nova
|
from tobiko.openstack import nova
|
||||||
|
|
|
@ -13,9 +13,8 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
import testtools
|
import testtools
|
||||||
|
import yaml
|
||||||
|
|
||||||
from tobiko.openstack import nova
|
from tobiko.openstack import nova
|
||||||
|
|
||||||
|
|
|
@ -15,74 +15,62 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
import six
|
from tobiko import podman
|
||||||
|
from tobiko.tests import unit
|
||||||
|
|
||||||
# We need to ignore this code under py2
|
|
||||||
# it's not compatible and parser will failed even if we use
|
|
||||||
# the `unittest.skipIf` decorator, because during the test discovery
|
|
||||||
# stestr and unittest will load this test
|
|
||||||
# module before running it and it will load podman
|
|
||||||
# too which isn't compatible in version leather than python 3
|
|
||||||
# Also the varlink mock module isn't compatible with py27, is using
|
|
||||||
# annotations syntaxe to generate varlink interface for the mocked service
|
|
||||||
# and it will raise related exceptions too.
|
|
||||||
# For all these reasons we can't run podman tests under a python 2 environment
|
|
||||||
if six.PY3:
|
|
||||||
from tobiko import podman
|
|
||||||
from tobiko.tests import unit
|
|
||||||
|
|
||||||
class TestShell(unit.TobikoUnitTest):
|
class TestShell(unit.TobikoUnitTest):
|
||||||
|
|
||||||
@mock.patch('tobiko.shell.sh.execute')
|
@mock.patch('tobiko.shell.sh.execute')
|
||||||
def test_discover_podman_socket(self, mock_execute):
|
def test_discover_podman_socket(self, mock_execute):
|
||||||
class FakeProcess:
|
class FakeProcess:
|
||||||
exit_status = 0
|
exit_status = 0
|
||||||
stdout = '/run/podman/io.podman'
|
stdout = '/run/podman/io.podman'
|
||||||
stderr = ''
|
stderr = ''
|
||||||
mock_execute.return_value = FakeProcess()
|
mock_execute.return_value = FakeProcess()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
podman.discover_podman_socket(),
|
podman.discover_podman_socket(),
|
||||||
'/run/podman/io.podman'
|
'/run/podman/io.podman'
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('tobiko.shell.sh.execute')
|
@mock.patch('tobiko.shell.sh.execute')
|
||||||
def test_discover_podman_socket_none_result(self, mock_execute):
|
def test_discover_podman_socket_none_result(self, mock_execute):
|
||||||
class FakeProcess:
|
class FakeProcess:
|
||||||
exit_status = 1
|
exit_status = 1
|
||||||
stdout = ''
|
stdout = ''
|
||||||
stderr = 'boom'
|
stderr = 'boom'
|
||||||
mock_execute.return_value = FakeProcess()
|
mock_execute.return_value = FakeProcess()
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
podman.PodmanSocketNotFoundError,
|
podman.PodmanSocketNotFoundError,
|
||||||
podman.discover_podman_socket
|
podman.discover_podman_socket
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('tobiko.shell.sh.execute')
|
@mock.patch('tobiko.shell.sh.execute')
|
||||||
def test_discover_podman_socket_with_exit_code(self, mock_execute):
|
def test_discover_podman_socket_with_exit_code(self, mock_execute):
|
||||||
class FakeProcess:
|
class FakeProcess:
|
||||||
exit_status = 0
|
exit_status = 0
|
||||||
stdout = ''
|
stdout = ''
|
||||||
stderr = 'boom'
|
stderr = 'boom'
|
||||||
mock_execute.return_value = FakeProcess()
|
mock_execute.return_value = FakeProcess()
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
podman.PodmanSocketNotFoundError,
|
podman.PodmanSocketNotFoundError,
|
||||||
podman.discover_podman_socket
|
podman.discover_podman_socket
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('tobiko.shell.sh.execute')
|
@mock.patch('tobiko.shell.sh.execute')
|
||||||
def test_is_podman_running(self, mock_execute):
|
def test_is_podman_running(self, mock_execute):
|
||||||
class FakeProcess:
|
class FakeProcess:
|
||||||
exit_status = 0
|
exit_status = 0
|
||||||
stdout = '/run/podman/io.podman'
|
stdout = '/run/podman/io.podman'
|
||||||
stderr = ''
|
stderr = ''
|
||||||
mock_execute.return_value = FakeProcess()
|
mock_execute.return_value = FakeProcess()
|
||||||
self.assertEqual(podman.is_podman_running(), True)
|
self.assertEqual(podman.is_podman_running(), True)
|
||||||
|
|
||||||
@mock.patch('tobiko.shell.sh.execute')
|
@mock.patch('tobiko.shell.sh.execute')
|
||||||
def test_is_podman_running_without_socket(self, mock_execute):
|
def test_is_podman_running_without_socket(self, mock_execute):
|
||||||
class FakeProcess:
|
class FakeProcess:
|
||||||
exit_status = 1
|
exit_status = 1
|
||||||
stdout = ''
|
stdout = ''
|
||||||
stderr = 'boom'
|
stderr = 'boom'
|
||||||
mock_execute.return_value = FakeProcess()
|
mock_execute.return_value = FakeProcess()
|
||||||
self.assertEqual(podman.is_podman_running(), False)
|
self.assertEqual(podman.is_podman_running(), False)
|
||||||
|
|
|
@ -15,9 +15,10 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import testtools
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
from tobiko.tests import unit
|
from tobiko.tests import unit
|
||||||
import testtools
|
|
||||||
|
|
||||||
|
|
||||||
class SomeException(tobiko.TobikoException):
|
class SomeException(tobiko.TobikoException):
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
|
# Copyright 2020 Red Hat
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from validations_libs import validation_actions
|
from validations_libs import validation_actions
|
||||||
from validations_libs import constants as v_consts
|
from validations_libs import constants as v_consts
|
||||||
|
|
||||||
|
|
12
tox.ini
12
tox.ini
|
@ -76,7 +76,7 @@ deps =
|
||||||
{[testenv]deps}
|
{[testenv]deps}
|
||||||
-r{toxinidir}/linters-requirements.txt
|
-r{toxinidir}/linters-requirements.txt
|
||||||
commands =
|
commands =
|
||||||
flake8 --max-complexity 10
|
pre-commit run -a flake8
|
||||||
|
|
||||||
|
|
||||||
[testenv:pylint]
|
[testenv:pylint]
|
||||||
|
@ -95,11 +95,8 @@ whitelist_externals = bash
|
||||||
deps = {[testenv:pep8]deps}
|
deps = {[testenv:pep8]deps}
|
||||||
envdir = {toxworkdir}/pep8
|
envdir = {toxworkdir}/pep8
|
||||||
commands =
|
commands =
|
||||||
pre-commit --version
|
pre-commit run -a
|
||||||
pre-commit autoupdate
|
|
||||||
pre-commit run --all-files
|
|
||||||
pre-commit install
|
pre-commit install
|
||||||
{[testenv:pep8]commands}
|
|
||||||
mypy --ignore-missing-imports tobiko/
|
mypy --ignore-missing-imports tobiko/
|
||||||
# Ansible lint
|
# Ansible lint
|
||||||
# [ANSIBLE0012] Commands should not change things if nothing needs doing
|
# [ANSIBLE0012] Commands should not change things if nothing needs doing
|
||||||
|
@ -120,10 +117,11 @@ commands =
|
||||||
enable-extensions = H106,H203,H204,H205,H904
|
enable-extensions = H106,H203,H204,H205,H904
|
||||||
|
|
||||||
show-source = true
|
show-source = true
|
||||||
exclude = ./.*,*lib/python*,build,dist,doc,*egg*,releasenotes,.venv
|
exclude = ./.*,*lib/python*,build,dist,doc,*egg*,releasenotes,.venv,.tox
|
||||||
|
application-import-names = tobiko
|
||||||
|
max-complexity = 10
|
||||||
import-order-style = pep8
|
import-order-style = pep8
|
||||||
|
|
||||||
|
|
||||||
# --- integration test environments ------------------------------------------
|
# --- integration test environments ------------------------------------------
|
||||||
|
|
||||||
[integration]
|
[integration]
|
||||||
|
|
Loading…
Reference in New Issue