Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 14, 2023
1 parent 5305584 commit 2572fce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
9 changes: 4 additions & 5 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,10 @@ def call_extra(
hookimpl = HookImpl(None, "<temp>", method, opts)
# Find last non-tryfirst nonwrapper method.
i = len(hookimpls) - 1
while (
i >= 0
and (hookimpls[i].tryfirst
or hookimpls[i].hookwrapper
or hookimpls[i].wrapper)
while i >= 0 and (
hookimpls[i].tryfirst
or hookimpls[i].hookwrapper
or hookimpls[i].wrapper
):
i -= 1
hookimpls.insert(i + 1, hookimpl)
Expand Down
33 changes: 16 additions & 17 deletions testing/test_hookcaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,35 +449,37 @@ def conflict(self) -> None:
"<class 'test_hookcaller.test_hook_conflict.<locals>.Api1'>"
)


# the following tests is to ensure that the modified call_extra function is still calling the hooks in the right order
# (when hookwrapper=False and wrapper=False)
def test_call_extra_hookorder1(hc, addmeth) -> None:
# this hook should be executed first
# this hook should be executed first
@addmeth(tryfirst=True, hookwrapper=False, wrapper=False)
def method1(arg: str) -> int:
return 1

@addmeth(tryfirst=False, hookwrapper=False, wrapper=False)
def method2(arg: str) -> int:
return 2

result = hc.call_extra([method1, method2], {"arg": "test"})
assert result[0] == 1 # value of first hook
assert result[0] == 1 # value of first hook


# the following test is to ensure that the modified call_extra function is still calling the hooks in the right order
# (when hookwrapper=False and wrapper=False)
def test_call_extra_hookorder2(hc, addmeth) -> None:
@addmeth(tryfirst=False, hookwrapper=False, wrapper=False)
def method1(arg: str) -> int:
return 1
# this hook should be executed first

# this hook should be executed first
@addmeth(tryfirst=True, hookwrapper=False, wrapper=False)
def method2(arg: str) -> int:
return 2

result = hc.call_extra([method1, method2], {"arg": "test"})
assert result[0] == 2 # value of first hook
assert result[0] == 2 # value of first hook


# the following test is to ensure that the modified call_extra function is still calling the hooks in the right order
Expand All @@ -486,24 +488,21 @@ def test_call_extra_hookorder3(hc, addmeth) -> None:
@addmeth(tryfirst=False, hookwrapper=False, wrapper=False)
def method1(arg: str) -> int:
return 1

# this hook should be executed last
@addmeth(trylast=True, hookwrapper=False, wrapper=False)
def method2(arg: str) -> int:
return 2

@addmeth(tryfirst=False, hookwrapper=False, wrapper=False)
def method3(arg: str) -> int:
return 3

# this hook should be executed first
@addmeth(tryfirst=True, hookwrapper=False, wrapper=False)
def method4(arg: str) -> int:
return 4

result = hc.call_extra([method1, method2, method3, method4], {"arg": "test"})
assert result[0] == 4 # value of first hook
assert result[-1] == 2 # value of last hook



result = hc.call_extra([method1, method2, method3, method4], {"arg": "test"})
assert result[0] == 4 # value of first hook
assert result[-1] == 2 # value of last hook

0 comments on commit 2572fce

Please sign in to comment.