"Fossies" - the Fresh Open Source Software Archive

Member "murano-8.0.0/murano/hacking/checks.py" (16 Oct 2019, 2373 Bytes) of package /linux/misc/openstack/murano-8.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "checks.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.2.0_vs_4.0.0.

    1 # Copyright (c) 2015 Intel, Inc.
    2 # All Rights Reserved.
    3 #
    4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 # not use this file except in compliance with the License. You may obtain
    6 # a copy of the License at
    7 #
    8 #      http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 # Unless required by applicable law or agreed to in writing, software
   11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 # License for the specific language governing permissions and limitations
   14 # under the License.
   15 
   16 import re
   17 
   18 """
   19 Guidelines for writing new hacking checks
   20  - Use only for Murano specific tests. OpenStack general tests
   21    should be submitted to the common 'hacking' module.
   22  - Pick numbers in the range M3xx. Find the current test with
   23    the highest allocated number and then pick the next value.
   24    If nova has an N3xx code for that test, use the same number.
   25  - Keep the test method code in the source file ordered based
   26    on the M3xx value.
   27  - List the new rule in the top level HACKING.rst file
   28  - Add test cases for each new rule to /tests/unit/test_hacking.py
   29 """
   30 
   31 mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
   32 assert_equal_end_with_none_re = re.compile(
   33     r"(.)*assertEqual\((\w|\.|\'|\"|\[|\])+, None\)")
   34 assert_equal_start_with_none_re = re.compile(
   35     r"(.)*assertEqual\(None, (\w|\.|\'|\"|\[|\])+\)")
   36 
   37 
   38 def assert_equal_none(logical_line):
   39     """Check for assertEqual(A, None) or assertEqual(None, A) sentences
   40 
   41     M318
   42     """
   43     msg = ("M318: assertEqual(A, None) or assertEqual(None, A) "
   44            "sentences not allowed")
   45     res = (assert_equal_start_with_none_re.match(logical_line) or
   46            assert_equal_end_with_none_re.match(logical_line))
   47     if res:
   48         yield (0, msg)
   49 
   50 
   51 def no_mutable_default_args(logical_line):
   52     msg = "M322: Method's default argument shouldn't be mutable!"
   53     if mutable_default_args.match(logical_line):
   54         yield (0, msg)
   55 
   56 
   57 def check_no_basestring(logical_line):
   58     if re.search(r"\bbasestring\b", logical_line):
   59         msg = ("M326: basestring is not Python3-compatible, use "
   60                "six.string_types instead.")
   61         yield(0, msg)
   62 
   63 
   64 def factory(register):
   65     register(assert_equal_none)
   66     register(no_mutable_default_args)
   67     register(check_no_basestring)