From 1b837ce2ae7e1cc274656ffcde109e50dd0fb130 Mon Sep 17 00:00:00 2001 From: Giampaolo Lauria Date: Wed, 1 May 2013 11:22:07 -0400 Subject: [PATCH] Create Flake8 extension for tempest checks Implements bp Flake8 extensions for specific tempest style checks Change-Id: Ica93bcba872ef8b1ecee12c61d8f602f4ae37c2f --- tools/__init__.py | 0 tools/hacking/__init__.py | 0 tools/hacking/tempest.py | 42 +++++++++++++++++++++++++++++++++++++++ tox.ini | 3 +++ 4 files changed, 45 insertions(+) create mode 100644 tools/__init__.py create mode 100644 tools/hacking/__init__.py create mode 100644 tools/hacking/tempest.py diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/hacking/__init__.py b/tools/hacking/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/hacking/tempest.py b/tools/hacking/tempest.py new file mode 100644 index 0000000000..1db8419db8 --- /dev/null +++ b/tools/hacking/tempest.py @@ -0,0 +1,42 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 IBM Corp. +# +# 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. + +import re + + +SKIP_DECORATOR = '@testtools.skip(' + + +def skip_bugs(physical_line): + """Check skip lines for proper bug entries + + T101: Bug not in skip line + T102: Bug in message formatted incorrectly + """ + + pos = physical_line.find(SKIP_DECORATOR) + + skip_re = re.compile(r'^\s*@testtools.skip.*') + + if pos != -1 and skip_re.match(physical_line): + bug = re.compile(r'^.*\bbug\b.*', re.IGNORECASE) + if bug.match(physical_line) is None: + return (pos, 'T101: skips must have an associated bug') + + bug_re = re.compile(r'.*skip\(.*Bug\s\#\d+', re.IGNORECASE) + + if bug_re.match(physical_line) is None: + return (pos, 'T102: Bug number formatted incorrectly') diff --git a/tox.ini b/tox.ini index 7d3d245384..1a14f1de38 100644 --- a/tox.ini +++ b/tox.ini @@ -54,6 +54,9 @@ commands = flake8 deps = -r{toxinidir}/tools/pip-requires -r{toxinidir}/tools/test-requires +[hacking] +local-check = tools.hacking.tempest.skip_bugs + [flake8] ignore = E125,H302,H404 show-source = True