Skip to content

Commit

Permalink
test: replace pycodestyle and pyflakes with flake8
Browse files Browse the repository at this point in the history
flake8 is a wrapper over pyflakes and pycodestyle, and most importantly
supports ignoring specific lines with `noqa`. This allows us to drop our
custom grep filters. The last remaning grep is for inotify which is a
special case as it used by combined with other scripts and therefore
can't be imported.
  • Loading branch information
jelly authored and martinpitt committed Jul 13, 2022
1 parent c287ce3 commit 5f04024
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 36 deletions.
2 changes: 1 addition & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ For running integration tests, the following dependencies are required:

$ sudo dnf install curl expect xz rpm-build chromium-headless \
libvirt-daemon-driver-storage-core libvirt-daemon-driver-qemu libvirt-client python3-libvirt \
python3-pyflakes python3-pycodestyle python3-pyyaml
python3-flake8 python3-pyyaml

Creating VM images locally (not necessary for running tests) needs the
following:
Expand Down
3 changes: 1 addition & 2 deletions containers/unit-tests/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies="\
curl \
dbus \
firefox-esr \
flake8 \
gcc-multilib \
gdb \
git \
Expand Down Expand Up @@ -39,9 +40,7 @@ dependencies="\
npm \
nodejs \
pkg-config \
pyflakes3 \
python3 \
python3-pycodestyle \
sassc \
ssh \
strace \
Expand Down
2 changes: 1 addition & 1 deletion src/client/cockpit-client
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import textwrap
gi.require_version("Gtk", "3.0") # NOQA
gi.require_version("WebKit2", "4.0") # NOQA

from gi.repository import GLib, Gio, Gtk, WebKit2
from gi.repository import GLib, Gio, Gtk, WebKit2 # NOQA: E402

try:
gi.require_version("Handy", "1")
Expand Down
6 changes: 3 additions & 3 deletions test/common/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import importlib.util

import parent
parent.ensure_bots() # NOQA: testvm lives in bots/
import testlib
import testvm
import testlib # NOQA: imported through parent.py
import testvm # NOQA: imported through parent.py

from lcov import prepare_for_code_coverage, create_coverage_report
from lcov import prepare_for_code_coverage, create_coverage_report # NOQA: E402

sys.dont_write_bytecode = True
os.environ['PYTHONUNBUFFERED'] = '1'
Expand Down
6 changes: 3 additions & 3 deletions test/image-prepare
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import subprocess

from common.parent import BASE_DIR, TEST_DIR, BOTS_DIR, ensure_bots
ensure_bots() # NOQA: testvm lives in bots/
from lib import testmap
from lib.constants import DEFAULT_IMAGE
from machine.machine_core import machine_virtual
from lib import testmap # NOQA: imported through parent.py
from lib.constants import DEFAULT_IMAGE # NOQA: imported through parent.py
from machine.machine_core import machine_virtual # NOQA: imported through parent.py


def build_rpms(dist_tar, image, verbose, quick):
Expand Down
30 changes: 4 additions & 26 deletions test/static-code
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# run static code checks like pyflakes and pycodestyle
# run static code checks like flake8, pyvulture.

set -eu

Expand All @@ -24,32 +24,10 @@ find_python_files() {
find_scripts 'python3' '*.py'
}

test_pyflakes() {
# Run pyflakes on all Python files except those in test/verify/

python3 -c 'import pyflakes' 2>/dev/null || skip 'no pyflakes'
test_flake8() {
python3 -c 'import flake8' 2>/dev/null || skip 'no flake8'
filter="(undefined name '(Inotify|IN_[A-Z_]+)'|'parent' imported but unused)" # inotify.py get pasted together with other files
! find_python_files | grep -zv '^test/verify' | xargs -r -0 python3 -m pyflakes 2>&1 | grep -Ev "${filter}"
}

test_pyflakes_test_verify() {
# Run pyflakes on all Python files in test/verify/

python3 -c 'import pyflakes' 2>/dev/null || skip 'no pyflakes'

# TODO: there are currently a lot of pyflakes errors like
# 'parent' imported but unused
# 'from testlib import *' used; unable to detect undefined names
# Filter these out until these get fixed properly.
filter="(unable to detect undefined names|'parent' imported but unused)"
! find_python_files | grep -z '^test/verify' | xargs -r -0 python3 -m pyflakes 2>&1 | grep -Ev "${filter}"
}

test_pycodestyle() {
# pycodestyle python syntax check

python3 -c 'import pycodestyle' 2>/dev/null || skip 'no pycodestyle'
find_python_files | xargs -r -0 python3 -m pycodestyle --max-line-length=200 --ignore W504
! find_python_files | xargs -r -0 python3 -m flake8 --max-line-length=200 --ignore W504 2>&1 | grep -Ev "${filter}"
}

test_pyvulture() {
Expand Down

0 comments on commit 5f04024

Please sign in to comment.