Merge "Add a simple hacking test for iter{items,keys,values}"
This commit is contained in:
@@ -287,7 +287,7 @@ class DockerWorker(object):
|
||||
|
||||
new_binds = list()
|
||||
if binds:
|
||||
for k, v in binds.iteritems():
|
||||
for k, v in binds.items():
|
||||
new_binds.append("{}:{}:{}".format(k, v['bind'], v['mode']))
|
||||
|
||||
if set(new_binds).symmetric_difference(set(current_binds)):
|
||||
@@ -300,7 +300,7 @@ class DockerWorker(object):
|
||||
k, v = kv.split('=', 1)
|
||||
current_env.update({k: v})
|
||||
|
||||
for k, v in self.params.get('environment').iteritems():
|
||||
for k, v in self.params.get('environment').items():
|
||||
if k not in current_env:
|
||||
return True
|
||||
if current_env[k] != v:
|
||||
|
||||
@@ -168,7 +168,7 @@ def dict_update(d, u):
|
||||
if not isinstance(u, collections.Mapping):
|
||||
return u
|
||||
|
||||
for k, v in u.iteritems():
|
||||
for k, v in u.items():
|
||||
if isinstance(v, collections.Mapping):
|
||||
d[k] = dict_update(d.get(k, {}), v)
|
||||
else:
|
||||
|
||||
@@ -620,7 +620,7 @@ class RenderNovaConfTest(base.BaseTestCase):
|
||||
'rabbitmq_password': 'jumpforjoy',
|
||||
'rabbitmq_port': '9090',
|
||||
'nova_api_database_user': 'sucker'}
|
||||
for nam, val in variables.iteritems():
|
||||
for nam, val in variables.items():
|
||||
self.client.create('/kolla/did/variables/%s' % nam,
|
||||
getattr(self, nam, val),
|
||||
makepath=True)
|
||||
|
||||
0
kolla_mesos/tests/hacking/__init__.py
Normal file
0
kolla_mesos/tests/hacking/__init__.py
Normal file
56
kolla_mesos/tests/hacking/checks.py
Normal file
56
kolla_mesos/tests/hacking/checks.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
"""
|
||||
Guidelines for writing new hacking checks
|
||||
|
||||
- Use only for kolla-mesos specific tests. OpenStack general tests
|
||||
should be submitted to the common 'hacking' module.
|
||||
- Pick numbers in the range H3xx. Find the current test with
|
||||
the highest allocated number and then pick the next value.
|
||||
- Keep the test method code in the source file ordered based
|
||||
on the H3xx value.
|
||||
- List the new rule in the top level HACKING.rst file
|
||||
- Add test cases for each new rule to kolla_mesos/tests/test_hacking.py
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def check_python3_no_iteritems(logical_line):
|
||||
msg = ("H301: Use six.iteritems() instead of dict.iteritems().")
|
||||
|
||||
if re.search(r".*\.iteritems\(\)", logical_line):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def check_python3_no_iterkeys(logical_line):
|
||||
msg = ("H302: Use six.iterkeys() instead of dict.iterkeys().")
|
||||
|
||||
if re.search(r".*\.iterkeys\(\)", logical_line):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def check_python3_no_itervalues(logical_line):
|
||||
msg = ("H303: Use six.itervalues() instead of dict.itervalues().")
|
||||
|
||||
if re.search(r".*\.itervalues\(\)", logical_line):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(check_python3_no_iteritems)
|
||||
register(check_python3_no_iterkeys)
|
||||
register(check_python3_no_itervalues)
|
||||
38
kolla_mesos/tests/hacking/test_hacking.py
Normal file
38
kolla_mesos/tests/hacking/test_hacking.py
Normal file
@@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
|
||||
from kolla_mesos.tests import base
|
||||
from kolla_mesos.tests.hacking import checks
|
||||
|
||||
|
||||
class HackingTestCase(base.BaseTestCase):
|
||||
def test_dict_iteritems(self):
|
||||
self.assertEqual(1, len(list(checks.check_python3_no_iteritems(
|
||||
"obj.iteritems()"))))
|
||||
|
||||
self.assertEqual(0, len(list(checks.check_python3_no_iteritems(
|
||||
"six.iteritems(ob))"))))
|
||||
|
||||
def test_dict_iterkeys(self):
|
||||
self.assertEqual(1, len(list(checks.check_python3_no_iterkeys(
|
||||
"obj.iterkeys()"))))
|
||||
|
||||
self.assertEqual(0, len(list(checks.check_python3_no_iterkeys(
|
||||
"six.iterkeys(ob))"))))
|
||||
|
||||
def test_dict_itervalues(self):
|
||||
self.assertEqual(1, len(list(checks.check_python3_no_itervalues(
|
||||
"obj.itervalues()"))))
|
||||
|
||||
self.assertEqual(0, len(list(checks.check_python3_no_itervalues(
|
||||
"six.itervalues(ob))"))))
|
||||
Reference in New Issue
Block a user