diff options
author | Mike Frysinger <vapier@google.com> | 2022-05-02 13:11:38 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2022-05-02 13:11:38 -0400 |
commit | 23372d07143d92acaa510ae271038a4377acc156 (patch) | |
tree | 86cabafa1cfaf5ec199b19f899442c10351b153e | |
parent | 0522922843c6ea447d027e6b88a0b22eb6c652a4 (diff) | |
download | repohooks-23372d07143d92acaa510ae271038a4377acc156.tar.gz |
hooks: require that hooks & tools dicts are sorted
Bug: None
Test: ./rh/hooks_unittest.py passes
Change-Id: I3f3644fb891518b800c2df31a34e3e9d76e5fbfa
-rw-r--r-- | rh/hooks.py | 2 | ||||
-rwxr-xr-x | rh/hooks_unittest.py | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/rh/hooks.py b/rh/hooks.py index d473cb9..24499d9 100644 --- a/rh/hooks.py +++ b/rh/hooks.py @@ -1006,10 +1006,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 03f45ca..ebfb92d 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') |