hooks: fix unittests in CQ Mock out the find_repo_root API using the existing helper. Bug: None Test: `./rh/hooks_unittest.py` passes in CQ Change-Id: Ie1df1e31ae93ac927883b1a63ff62716ce09d778 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repohooks/+/564901 Commit-Queue: Mike Frysinger <vapier@google.com> Reviewed-by: Raul Rangel <rrangel@google.com> Tested-by: Mike Frysinger <vapier@google.com>
diff --git a/rh/hooks_unittest.py b/rh/hooks_unittest.py index 382911e..c382700 100755 --- a/rh/hooks_unittest.py +++ b/rh/hooks_unittest.py
@@ -20,8 +20,6 @@ import unittest from unittest import mock -import pytest - _path = os.path.realpath(__file__ + "/../..") if sys.path[0] != _path: sys.path.insert(0, _path) @@ -266,9 +264,11 @@ class HookOptionsTests(unittest.TestCase): """Verify behavior of HookOptions object.""" - @pytest.mark.skip_cq("TODO: Relies on .repo dir") + @mock.patch.object( + rh.git, "find_repo_root", side_effect=mock_find_repo_root + ) @mock.patch.object(rh.hooks, "_get_build_os_name", return_value="vapier os") - def testExpandVars(self, m): + def testExpandVars(self, m, _m): """Verify expand_vars behavior.""" # Simple pass through. args = ["who", "goes", "there ?"] @@ -279,8 +279,10 @@ exp_args = ["who", "goes", "there ?", f"{m.return_value} is great"] self.assertEqual(exp_args, rh.hooks.HookOptions.expand_vars(args)) - @pytest.mark.skip_cq("TODO: Relies on .repo dir") - def testArgs(self): + @mock.patch.object( + rh.git, "find_repo_root", side_effect=mock_find_repo_root + ) + def testArgs(self, _m): """Verify args behavior.""" # Verify initial args to __init__ has higher precedent. args = ["start", "args"] @@ -294,8 +296,10 @@ self.assertEqual(options.args(), []) self.assertEqual(options.args(default_args=args), args) - @pytest.mark.skip_cq("TODO: Relies on .repo dir") - def testToolPath(self): + @mock.patch.object( + rh.git, "find_repo_root", side_effect=mock_find_repo_root + ) + def testToolPath(self, _): """Verify tool_path behavior.""" options = rh.hooks.HookOptions( "hook name",