aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-05-03 03:39:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2022-05-03 03:39:35 +0000
commitceb6fb38d93597cae05d9c9ab0c6a0c0270051d5 (patch)
tree1e5b00d42951da4fb8d9aa9a1359e04e163baf7c
parentdf057d3b9aaf80c938d07849b0dd11b918844c8a (diff)
parent23372d07143d92acaa510ae271038a4377acc156 (diff)
downloadrepohooks-ceb6fb38d93597cae05d9c9ab0c6a0c0270051d5.tar.gz
Merge "hooks: require that hooks & tools dicts are sorted"
-rw-r--r--rh/hooks.py2
-rwxr-xr-xrh/hooks_unittest.py14
2 files changed, 15 insertions, 1 deletions
diff --git a/rh/hooks.py b/rh/hooks.py
index 643001c..6cb3214 100644
--- a/rh/hooks.py
+++ b/rh/hooks.py
@@ -1042,10 +1042,10 @@ BUILTIN_HOOKS = {
'commit_msg_bug_field': check_commit_msg_bug_field,
'commit_msg_changeid_field': check_commit_msg_changeid_field,
'commit_msg_prebuilt_apk_fields': check_commit_msg_prebuilt_apk_fields,
- 'commit_msg_test_field': check_commit_msg_test_field,
'commit_msg_relnote_field_format': check_commit_msg_relnote_field_format,
'commit_msg_relnote_for_current_txt':
check_commit_msg_relnote_for_current_txt,
+ 'commit_msg_test_field': check_commit_msg_test_field,
'cpplint': check_cpplint,
'gofmt': check_gofmt,
'google_java_format': check_google_java_format,
diff --git a/rh/hooks_unittest.py b/rh/hooks_unittest.py
index 389aad8..f522ee9 100755
--- a/rh/hooks_unittest.py
+++ b/rh/hooks_unittest.py
@@ -267,6 +267,20 @@ class UtilsTests(unittest.TestCase):
self.assertTrue(isinstance(ret, str))
self.assertNotEqual(ret, '')
+ def testSortedToolPaths(self):
+ """Check TOOL_PATHS is sorted."""
+ # This assumes dictionary key ordering matches insertion/definition
+ # order which Python 3.7+ has codified.
+ # https://docs.python.org/3.7/library/stdtypes.html#dict
+ self.assertEqual(list(rh.hooks.TOOL_PATHS), sorted(rh.hooks.TOOL_PATHS))
+
+ def testSortedBuiltinHooks(self):
+ """Check BUILTIN_HOOKS is sorted."""
+ # This assumes dictionary key ordering matches insertion/definition
+ # order which Python 3.7+ has codified.
+ # https://docs.python.org/3.7/library/stdtypes.html#dict
+ self.assertEqual(
+ list(rh.hooks.BUILTIN_HOOKS), sorted(rh.hooks.BUILTIN_HOOKS))
@mock.patch.object(rh.utils, 'run')