Add hacking check to ensure not use xrange()
Added hacking check to ensure not to use xrange. Also, fixed issues with EoF missing newline [W391]. Change-Id: Iba8d240c042e46cb34eb6ed057534d62efb6f903 Closes-Bug: #1538118
This commit is contained in:
parent
972cdba6ee
commit
8d0b16292d
@ -23,6 +23,7 @@ Octavia Specific Commandments
|
||||
assertEqual(A in B, False) or assertEqual(False, A in B) to the more
|
||||
specific assertIn/NotIn(A, B)
|
||||
- [O339] LOG.warn() is not allowed. Use LOG.warning()
|
||||
- [O340] Don't use xrange()
|
||||
|
||||
Creating Unit Tests
|
||||
-------------------
|
||||
|
@ -37,4 +37,4 @@ def setup_app(pecan_config=None, debug=False):
|
||||
debug=debug,
|
||||
hooks=app_hooks,
|
||||
wsme=pecan_config.wsme
|
||||
)
|
||||
)
|
||||
|
@ -199,4 +199,4 @@ class LBCascadeDeleteController(LoadBalancersController):
|
||||
@wsme_pecan.wsexpose(None, status_code=202)
|
||||
def delete(self):
|
||||
"""Deletes a load balancer."""
|
||||
return self._delete(self.lb_id, cascade=True)
|
||||
return self._delete(self.lb_id, cascade=True)
|
||||
|
@ -44,4 +44,4 @@ class InfoContainer(object):
|
||||
return True
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
return not self == other
|
||||
|
@ -73,6 +73,8 @@ assert_not_equal_end_with_none_re = re.compile(
|
||||
r"(.)*assertNotEqual\(.+, None\)")
|
||||
assert_not_equal_start_with_none_re = re.compile(
|
||||
r"(.)*assertNotEqual\(None, .+\)")
|
||||
assert_no_xrange_re = re.compile(
|
||||
r"\s*xrange\s*\(")
|
||||
|
||||
|
||||
def _directory_to_check_translation(filename):
|
||||
@ -209,6 +211,15 @@ def no_log_warn(logical_line):
|
||||
yield(0, "O339:Use LOG.warning() rather than LOG.warn()")
|
||||
|
||||
|
||||
def no_xrange(logical_line):
|
||||
"""Disallow 'xrange()'
|
||||
|
||||
O340
|
||||
"""
|
||||
if assert_no_xrange_re.match(logical_line):
|
||||
yield(0, "O340: Do not use xrange().")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(assert_true_instance)
|
||||
register(assert_equal_or_not_none)
|
||||
@ -220,3 +231,4 @@ def factory(register):
|
||||
register(no_mutable_default_args)
|
||||
register(assert_equal_in)
|
||||
register(no_log_warn)
|
||||
register(no_xrange)
|
||||
|
@ -112,4 +112,4 @@ class BaseLocalCSRTestCase(base.TestCase):
|
||||
cn=cn,
|
||||
validity=2 * 365 * 24 * 60 * 60,
|
||||
)
|
||||
self.assertTrue(m.called)
|
||||
self.assertTrue(m.called)
|
||||
|
@ -135,4 +135,4 @@ class TestLocalGenerator(local_csr.BaseLocalCSRTestCase):
|
||||
data=cert_object.private_key,
|
||||
password=cert_object.private_key_passphrase,
|
||||
backend=backends.default_backend())
|
||||
self.assertIsNotNone(key)
|
||||
self.assertIsNotNone(key)
|
||||
|
@ -36,4 +36,4 @@ class TestUpdateSerializer(base.TestCase):
|
||||
obj_payload = {'test': [3, 2, 1, 6], id: obj_id, 'x': {'y': 1}}
|
||||
obj = update_serializer.InfoContainer(obj_id, obj_type, obj_payload)
|
||||
cloned_obj = update_serializer.InfoContainer.from_dict(obj.to_dict())
|
||||
self.assertEqual(obj, cloned_obj)
|
||||
self.assertEqual(obj, cloned_obj)
|
||||
|
@ -30,4 +30,4 @@ class TestCertTasks(base.TestCase):
|
||||
self.assertEqual(
|
||||
pem, dummy_cert.get_certificate() + dummy_cert.get_private_key())
|
||||
mock_driver.generate_cert_key_pair.assert_called_once_with(
|
||||
cn='123', validity=cert_task.CERT_VALIDITY)
|
||||
cn='123', validity=cert_task.CERT_VALIDITY)
|
||||
|
@ -1448,4 +1448,4 @@ class TestDatabaseTasks(base.TestCase):
|
||||
# Test the revert
|
||||
|
||||
mock_listener_repo_update.reset_mock()
|
||||
update_server_group_info.revert(LB_ID, SERVER_GROUP_ID)
|
||||
update_server_group_info.revert(LB_ID, SERVER_GROUP_ID)
|
||||
|
@ -135,3 +135,10 @@ class HackingTestCase(base.BaseTestCase):
|
||||
|
||||
self.assertEqual(0, len(list(checks.no_log_warn(
|
||||
"LOG.warning()"))))
|
||||
|
||||
def test_no_xrange(self):
|
||||
self.assertEqual(1, len(list(checks.no_xrange(
|
||||
"xrange(45)"))))
|
||||
|
||||
self.assertEqual(0, len(list(checks.no_xrange(
|
||||
"range(45)"))))
|
||||
|
Loading…
Reference in New Issue
Block a user