Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 1 | # Copyright 2013 IBM Corp. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import re |
| 16 | |
| 17 | |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 18 | PYTHON_CLIENTS = ['cinder', 'glance', 'keystone', 'nova', 'swift', 'neutron'] |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 19 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 20 | PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS)) |
Matthew Treinish | 6ba951a | 2013-09-09 22:06:18 +0000 | [diff] [blame] | 21 | TEST_DEFINITION = re.compile(r'^\s*def test.*') |
Matthew Treinish | ecf212c | 2013-12-06 18:23:54 +0000 | [diff] [blame] | 22 | SETUPCLASS_DEFINITION = re.compile(r'^\s*def setUpClass') |
Matthew Treinish | 6ba951a | 2013-09-09 22:06:18 +0000 | [diff] [blame] | 23 | SCENARIO_DECORATOR = re.compile(r'\s*@.*services\(') |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 24 | |
| 25 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 26 | def import_no_clients_in_api(physical_line, filename): |
| 27 | """Check for client imports from tempest/api tests |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 28 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 29 | T102: Cannot import OpenStack python clients |
| 30 | """ |
Giampaolo Lauria | 1b837ce | 2013-05-01 11:22:07 -0400 | [diff] [blame] | 31 | |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 32 | if "tempest/api" in filename: |
| 33 | res = PYTHON_CLIENT_RE.match(physical_line) |
| 34 | if res: |
| 35 | return (physical_line.find(res.group(1)), |
| 36 | ("T102: python clients import not allowed" |
| 37 | " in tempest/api/* tests")) |
Giampaolo Lauria | d50c27d | 2013-05-23 15:23:12 -0400 | [diff] [blame] | 38 | |
| 39 | |
Matthew Treinish | 6ba951a | 2013-09-09 22:06:18 +0000 | [diff] [blame] | 40 | def scenario_tests_need_service_tags(physical_line, filename, |
| 41 | previous_logical): |
| 42 | """Check that scenario tests have service tags |
| 43 | |
| 44 | T104: Scenario tests require a services decorator |
| 45 | """ |
| 46 | |
| 47 | if 'tempest/scenario' in filename: |
| 48 | if TEST_DEFINITION.match(physical_line): |
| 49 | if not SCENARIO_DECORATOR.match(previous_logical): |
| 50 | return (physical_line.find('def'), |
| 51 | "T104: Scenario tests require a service decorator") |
| 52 | |
| 53 | |
Matthew Treinish | ecf212c | 2013-12-06 18:23:54 +0000 | [diff] [blame] | 54 | def no_setupclass_for_unit_tests(physical_line, filename): |
| 55 | if 'tempest/tests' in filename: |
| 56 | if SETUPCLASS_DEFINITION.match(physical_line): |
| 57 | return (physical_line.find('def'), |
| 58 | "T105: setUpClass can not be used with unit tests") |
| 59 | |
| 60 | |
Giampaolo Lauria | d50c27d | 2013-05-23 15:23:12 -0400 | [diff] [blame] | 61 | def factory(register): |
Giampaolo Lauria | b8424eb | 2013-05-23 15:56:21 -0400 | [diff] [blame] | 62 | register(import_no_clients_in_api) |
Matthew Treinish | 6ba951a | 2013-09-09 22:06:18 +0000 | [diff] [blame] | 63 | register(scenario_tests_need_service_tags) |
Matthew Treinish | ecf212c | 2013-12-06 18:23:54 +0000 | [diff] [blame] | 64 | register(no_setupclass_for_unit_tests) |