Skip to content

Commit 11d6c28

Browse files
Anusha ShekharAnusha Shekhar
authored andcommitted
Codecov
1 parent cb4bb02 commit 11d6c28

File tree

2 files changed

+65
-17
lines changed

2 files changed

+65
-17
lines changed

testing/test_hookcaller.py

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pluggy import PluginValidationError
1212
from pluggy._hooks import HookCaller
1313
from pluggy._hooks import HookImpl
14+
from pluggy._hooks import HookimplOpts
1415
from pluggy._tracing import saferepr
1516

1617
hookspec = HookspecMarker("example")
@@ -410,7 +411,8 @@ def hello(self, arg: object) -> None:
410411

411412
pm.add_hookspecs(Api)
412413

413-
# make sure a bad signature still raises an error when using specname
414+
"""make sure a bad signature still raises an error when using specname"""
415+
414416
class Plugin:
415417
@hookimpl(specname="hello")
416418
def foo(self, arg: int, too, many, args) -> int:
@@ -419,8 +421,9 @@ def foo(self, arg: int, too, many, args) -> int:
419421
with pytest.raises(PluginValidationError):
420422
pm.register(Plugin())
421423

422-
# make sure check_pending still fails if specname doesn't have a
423-
# corresponding spec. EVEN if the function name matches one.
424+
"""make sure check_pending still fails if specname doesn't have a
425+
corresponding spec. EVEN if the function name matches one."""
426+
424427
class Plugin2:
425428
@hookimpl(specname="bar")
426429
def hello(self, arg: int) -> int:
@@ -451,14 +454,62 @@ def conflict(self) -> None:
451454
)
452455

453456

454-
def test_hookcaller_repr_with_saferepr_failure(
455-
hc: HookCaller, addmeth: AddMeth
456-
) -> None:
457-
@addmeth()
458-
def he_method2() -> None:
459-
# Intentional error to make the repr fail
460-
raise ValueError("Intentional error in he_method2")
461-
462-
# Verify that HookCaller.repr with saferepr still works despite the error
463-
expected_repr = f"<HookCaller {saferepr(hc.name)}>"
464-
assert repr(hc) == expected_repr
457+
def test_hook_impl_initialization() -> None:
458+
# Mock data
459+
plugin = "example_plugin"
460+
plugin_name = "ExamplePlugin"
461+
462+
def example_function(x):
463+
return x
464+
465+
hook_impl_opts: HookimplOpts = {
466+
"wrapper": False,
467+
"hookwrapper": False,
468+
"optionalhook": False,
469+
"tryfirst": False,
470+
"trylast": False,
471+
"specname": "",
472+
}
473+
474+
# Initialize HookImpl
475+
hook_impl = HookImpl(plugin, plugin_name, example_function, hook_impl_opts)
476+
477+
# Verify attributes are set correctly
478+
assert hook_impl.function == example_function
479+
assert hook_impl.argnames == ("x",)
480+
assert hook_impl.kwargnames == ()
481+
assert hook_impl.plugin == plugin
482+
assert hook_impl.opts == hook_impl_opts
483+
assert hook_impl.plugin_name == plugin_name
484+
assert not hook_impl.wrapper
485+
assert not hook_impl.hookwrapper
486+
assert not hook_impl.optionalhook
487+
assert not hook_impl.tryfirst
488+
assert not hook_impl.trylast
489+
490+
491+
def test_hook_impl_representation() -> None:
492+
# Mock data
493+
plugin = "example_plugin"
494+
plugin_name = "ExamplePlugin"
495+
496+
def example_function(x):
497+
return x
498+
499+
hook_impl_opts: HookimplOpts = {
500+
"wrapper": False,
501+
"hookwrapper": False,
502+
"optionalhook": False,
503+
"tryfirst": False,
504+
"trylast": False,
505+
"specname": "",
506+
}
507+
508+
# Initialize HookImpl
509+
hook_impl = HookImpl(plugin, plugin_name, example_function, hook_impl_opts)
510+
511+
# Verify __repr__ method
512+
expected_repr = (
513+
f"<HookImpl plugin_name={saferepr(plugin_name)}, " f"plugin={saferepr(plugin)}>"
514+
)
515+
assert repr(hook_impl) == expected_repr

testing/test_tracer.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ def test_saferepr_broken_getattribute():
243243
"""
244244

245245
class SomeClass:
246-
def __getattribute__(self, attr):
247-
raise RuntimeError
248-
249246
def __repr__(self):
250247
raise RuntimeError
251248

0 commit comments

Comments
 (0)