hacking: check for common double word typos

Adds a local hacking check for common double word typos
like "the the", "to to", etc.

Change-Id: I824a4a4b0f3bc18a16d5df50bd66cc626888ebaf
This commit is contained in:
Daniel P. Berrange
2015-11-24 13:03:50 +00:00
parent 5d6e0086b5
commit aaff356e18
11 changed files with 37 additions and 9 deletions

View File

@@ -53,6 +53,7 @@ Nova Specific Commandments
- [N340] Check nova.utils.spawn() is used instead of greenthread.spawn() and eventlet.spawn()
- [N341] contextlib.nested is deprecated
- [N342] Config options should be in the central location ``nova/conf/``
- [N343] Check for common double word typos
Creating Unit Tests
-------------------

View File

@@ -1277,7 +1277,7 @@ class CellV2Commands(object):
if cell_uuid is None:
raise Exception(_("cell_uuid must be set"))
else:
# Validate the the cell exists
# Validate the cell exists
cell_mapping = objects.CellMapping.get_by_uuid(ctxt, cell_uuid)
filters = {}
instances = objects.InstanceList.get_by_filters(

View File

@@ -1913,7 +1913,7 @@ def instance_get_all_by_filters(context, filters, sort_key, sort_dir,
def instance_get_all_by_filters_sort(context, filters, limit=None, marker=None,
columns_to_join=None, use_slave=False,
sort_keys=None, sort_dirs=None):
"""Return instances that match all filters sorted the the given keys.
"""Return instances that match all filters sorted by the given keys.
Deleted instances will be returned by default, unless there's a filter that
says otherwise.

View File

@@ -101,6 +101,8 @@ http_not_implemented_re = re.compile(r"raise .*HTTPNotImplemented\(")
spawn_re = re.compile(
r".*(eventlet|greenthread)\.(?P<spawn_part>spawn(_n)?)\(.*\)")
contextlib_nested = re.compile(r"^with (contextlib\.)?nested\(")
doubled_words_re = re.compile(
r"\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b")
class BaseASTChecker(ast.NodeVisitor):
@@ -576,6 +578,19 @@ def check_config_option_in_central_place(logical_line, filename):
yield(0, msg)
def check_doubled_words(physical_line, filename):
"""Check for the common doubled-word typos
N343
"""
msg = ("N343: Doubled word '%(word)s' typo found")
match = re.search(doubled_words_re, physical_line)
if match:
return (0, msg % {'word': match.group(1)})
def factory(register):
register(import_no_db_in_virt)
register(no_db_session_in_public_api)
@@ -605,3 +620,4 @@ def factory(register):
register(check_no_contextlib_nested)
register(check_greenthread_spawns)
register(check_config_option_in_central_place)
register(check_doubled_words)

View File

@@ -2748,7 +2748,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
uuids.instance, 'fake-mac',
start_period=0, use_slave=True)
# NOTE(sdague): bw_usage_update happens at some time in
# the future, so what last_refreshed is is irrelevant.
# the future, so what last_refreshed is irrelevant.
bw_usage_update.assert_called_once_with(self.context,
uuids.instance,
'fake-mac', 0, 4, 6, 1, 2,

View File

@@ -628,3 +628,14 @@ class HackingTestCase(test.NoDBTestCase):
checks.check_config_option_in_central_place,
filename="nova/cmd/serialproxy.py",
expected_errors=errors)
def test_check_doubled_words(self):
errors = [(1, 0, "N343")]
# Artificial break to stop pep8 detecting the test !
code = "This is the" + " the best comment"
self._assert_has_errors(code, checks.check_doubled_words,
expected_errors=errors)
code = "This is the then best comment"
self._assert_has_no_errors(code, checks.check_doubled_words)

View File

@@ -1351,7 +1351,7 @@ class ComputeDriver(object):
:param nova.objects.aggregate.Aggregate aggregate:
The aggregate which should add the given `host`
:param str host:
The name of the host to add to the the given `aggregate`.
The name of the host to add to the given `aggregate`.
:param dict kwargs:
A free-form thingy...
@@ -1370,7 +1370,7 @@ class ComputeDriver(object):
:param nova.objects.aggregate.Aggregate aggregate:
The aggregate which should remove the given `host`
:param str host:
The name of the host to remove from the the given `aggregate`.
The name of the host to remove from the given `aggregate`.
:param dict kwargs:
A free-form thingy...

View File

@@ -1373,7 +1373,7 @@ def get_host_numa_usage_from_instance(host, instance, free=False,
:param host: nova.objects.ComputeNode instance, or a db object or dict
:param instance: nova.objects.Instance instance, or a db object or dict
:param free: if True the the returned topology will have it's usage
:param free: if True the returned topology will have it's usage
decreased instead.
:param never_serialize_result: if True result will always be an instance of
objects.NUMATopology class.

View File

@@ -454,7 +454,7 @@ def get_instance_path(instance, forceold=False, relative=False):
def get_instance_path_at_destination(instance, migrate_data=None):
"""Get the the instance path on destination node while live migration.
"""Get the instance path on destination node while live migration.
This method determines the directory name for instance storage on
destination node, while live migration.

View File

@@ -40,7 +40,7 @@ DcInfo = collections.namedtuple('DcInfo',
['ref', 'name', 'vmFolder'])
# A cache for datastore/datacenter mappings. The key will be
# the datastore moref. The value will the the DcInfo object.
# the datastore moref. The value will be the DcInfo object.
_DS_DC_MAPPING = {}

View File

@@ -330,7 +330,7 @@ class Application(object):
res = exc.HTTPForbidden(explanation='Nice try')
# Option 3: a webob Response object (in case you need to play with
# headers, or you want to be treated like an iterable, or or or)
# headers, or you want to be treated like an iterable, or ...)
res = Response()
res.app_iter = open('somefile')