@@ -410,7 +410,8 @@ def hello(self, arg: object) -> None:
410410
411411 pm .add_hookspecs (Api )
412412
413- # make sure a bad signature still raises an error when using specname
413+ """make sure a bad signature still raises an error when using specname"""
414+
414415 class Plugin :
415416 @hookimpl (specname = "hello" )
416417 def foo (self , arg : int , too , many , args ) -> int :
@@ -419,8 +420,9 @@ def foo(self, arg: int, too, many, args) -> int:
419420 with pytest .raises (PluginValidationError ):
420421 pm .register (Plugin ())
421422
422- # make sure check_pending still fails if specname doesn't have a
423- # corresponding spec. EVEN if the function name matches one.
423+ """make sure check_pending still fails if specname doesn't have a
424+ corresponding spec. EVEN if the function name matches one."""
425+
424426 class Plugin2 :
425427 @hookimpl (specname = "bar" )
426428 def hello (self , arg : int ) -> int :
@@ -451,14 +453,55 @@ def conflict(self) -> None:
451453 )
452454
453455
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
456+ def test_hook_impl_initialization () -> None :
457+ # Mock data
458+ plugin = "example_plugin"
459+ plugin_name = "ExamplePlugin"
460+ function = lambda x : x
461+ hook_impl_opts = {
462+ "wrapper" : False ,
463+ "hookwrapper" : False ,
464+ "optionalhook" : False ,
465+ "tryfirst" : False ,
466+ "trylast" : False ,
467+ }
468+
469+ # Initialize HookImpl
470+ hook_impl = HookImpl (plugin , plugin_name , function , hook_impl_opts )
471+
472+ # Verify attributes are set correctly
473+ assert hook_impl .function == function
474+ assert hook_impl .argnames == ("x" ,)
475+ assert hook_impl .kwargnames == ()
476+ assert hook_impl .plugin == plugin
477+ assert hook_impl .opts == hook_impl_opts
478+ assert hook_impl .plugin_name == plugin_name
479+ assert not hook_impl .wrapper
480+ assert not hook_impl .hookwrapper
481+ assert not hook_impl .optionalhook
482+ assert not hook_impl .tryfirst
483+ assert not hook_impl .trylast
484+
485+
486+ def test_hook_impl_representation () -> None :
487+ # Mock data
488+ plugin = "example_plugin"
489+ plugin_name = "ExamplePlugin"
490+ function = lambda x : x
491+ hook_impl_opts = {
492+ "wrapper" : False ,
493+ "hookwrapper" : False ,
494+ "optionalhook" : False ,
495+ "tryfirst" : False ,
496+ "trylast" : False ,
497+ }
498+
499+ # Initialize HookImpl
500+ hook_impl = HookImpl (plugin , plugin_name , function , hook_impl_opts )
501+
502+ # Verify __repr__ method
503+ expected_repr = (
504+ f"<HookImpl plugin_name={ saferepr (plugin_name )} , "
505+ f"plugin={ saferepr (plugin )} >"
506+ )
507+ assert repr (hook_impl ) == expected_repr
0 commit comments