aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Liu <liujiong@gohighsec.com>2016-11-24 14:25:42 +0800
committerJeremy Liu <liujiong@gohighsec.com>2016-11-24 15:55:43 +0800
commitc756896e904c0ca48236bd4a9c08dff7fa1b4e86 (patch)
treed25d68943954788f176525fb6312aabb924fc60b
parent390b4a24f83c10ea0845b0df58070d687eabe509 (diff)
downloadkolla-c756896e904c0ca48236bd4a9c08dff7fa1b4e86.tar.gz
kolla-c756896e904c0ca48236bd4a9c08dff7fa1b4e86.zip
Add HACKING.rst and hacking test case.
Currently, we have hacking check in kolla, but no place where we can define hacking check rules. This patch adds HACKING.rst file for that. And also add test cases for hacking. Change-Id: I87f8768138d91bf6a5a1db91d37392f794f3f0ba
-rw-r--r--HACKING.rst13
-rw-r--r--kolla/hacking/checks.py6
-rw-r--r--kolla/tests/test_hacking.py46
-rw-r--r--test-requirements.txt1
4 files changed, 63 insertions, 3 deletions
diff --git a/HACKING.rst b/HACKING.rst
new file mode 100644
index 000000000..7d5ef11bd
--- /dev/null
+++ b/HACKING.rst
@@ -0,0 +1,13 @@
+Kolla Style Commandments
+============================
+
+- Step 1: Read the OpenStack Style Commandments
+ http://docs.openstack.org/developer/hacking/
+- Step 2: Read on
+
+
+Kolla Specific Commandments
+-------------------------------
+
+- [K301] Method's default argument shouldn't be mutable.
+- [K302] Use LOG.warning instead of LOG.warn.
diff --git a/kolla/hacking/checks.py b/kolla/hacking/checks.py
index 9eba06c01..593b8bf83 100644
--- a/kolla/hacking/checks.py
+++ b/kolla/hacking/checks.py
@@ -21,16 +21,16 @@ def no_log_warn(logical_line):
Deprecated LOG.warn(), instead use LOG.warning
https://bugs.launchpad.net/senlin/+bug/1508442
- N352
+ K302
"""
- msg = ("N352: LOG.warn is deprecated, please use LOG.warning!")
+ msg = ("K302: LOG.warn is deprecated, please use LOG.warning!")
if "LOG.warn(" in logical_line:
yield (0, msg)
def no_mutable_default_args(logical_line):
- msg = "N301: Method's default argument shouldn't be mutable!"
+ msg = "K301: Method's default argument shouldn't be mutable!"
if mutable_default_args.match(logical_line):
yield (0, msg)
diff --git a/kolla/tests/test_hacking.py b/kolla/tests/test_hacking.py
new file mode 100644
index 000000000..6605673ea
--- /dev/null
+++ b/kolla/tests/test_hacking.py
@@ -0,0 +1,46 @@
+# Copyright 2016 GohighSec
+#
+# 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 ddt
+
+from kolla.hacking import checks
+from kolla.tests import base
+
+
+@ddt.ddt
+class HackingTestCase(base.TestCase):
+ """Hacking test cases
+
+ This class tests the hacking checks in kolla.hacking.checks by passing
+ strings to the check methods like the pep8/flake8 parser would. The parser
+ loops over each line in the file and then passes the parameters to the
+ check method.
+ """
+
+ def test_no_log_warn_check(self):
+ self.assertEqual(0, len(list(checks.no_log_warn(
+ "LOG.warning('This should not trigger LOG.warn"
+ "hacking check.')"))))
+ self.assertEqual(1, len(list(checks.no_log_warn(
+ "LOG.warn('We should not use LOG.warn')"))))
+
+ def test_no_mutable_default_args(self):
+ self.assertEqual(1, len(list(checks.no_mutable_default_args(
+ "def get_info_from_bdm(virt_type, bdm, mapping=[])"))))
+
+ self.assertEqual(0, len(list(checks.no_mutable_default_args(
+ "defined = []"))))
+
+ self.assertEqual(0, len(list(checks.no_mutable_default_args(
+ "defined, undefined = [], {}"))))
diff --git a/test-requirements.txt b/test-requirements.txt
index 839291cd0..43564f93a 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -4,6 +4,7 @@
bandit>=1.1.0 # Apache-2.0
bashate>=0.2 # Apache-2.0
beautifulsoup4 # MIT
+ddt>=1.0.1 # MIT
doc8 # Apache-2.0
extras # MIT
graphviz!=0.5.0,>=0.4.0 # MIT License