Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame^] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 IBM Corp. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import re |
| 18 | |
| 19 | |
| 20 | SKIP_DECORATOR = '@testtools.skip(' |
| 21 | |
| 22 | |
| 23 | def skip_bugs(physical_line): |
| 24 | """Check skip lines for proper bug entries |
| 25 | |
| 26 | T101: Bug not in skip line |
| 27 | T102: Bug in message formatted incorrectly |
| 28 | """ |
| 29 | |
| 30 | pos = physical_line.find(SKIP_DECORATOR) |
| 31 | |
| 32 | skip_re = re.compile(r'^\s*@testtools.skip.*') |
| 33 | |
| 34 | if pos != -1 and skip_re.match(physical_line): |
| 35 | bug = re.compile(r'^.*\bbug\b.*', re.IGNORECASE) |
| 36 | if bug.match(physical_line) is None: |
| 37 | return (pos, 'T101: skips must have an associated bug') |
| 38 | |
| 39 | bug_re = re.compile(r'.*skip\(.*Bug\s\#\d+', re.IGNORECASE) |
| 40 | |
| 41 | if bug_re.match(physical_line) is None: |
| 42 | return (pos, 'T102: Bug number formatted incorrectly') |