-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Issue 424/add saferepr #460
base: main
Are you sure you want to change the base?
Changes from all commits
3499ef5
cff191d
86a0b35
e7f6b98
5fa1164
cb4bb02
11d6c28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
from pluggy import PluginValidationError | ||
from pluggy._hooks import HookCaller | ||
from pluggy._hooks import HookImpl | ||
from pluggy._hooks import HookimplOpts | ||
from pluggy._tracing import saferepr | ||
|
||
hookspec = HookspecMarker("example") | ||
hookimpl = HookimplMarker("example") | ||
|
@@ -409,7 +411,8 @@ | |
|
||
pm.add_hookspecs(Api) | ||
|
||
# make sure a bad signature still raises an error when using specname | ||
"""make sure a bad signature still raises an error when using specname""" | ||
|
||
class Plugin: | ||
@hookimpl(specname="hello") | ||
def foo(self, arg: int, too, many, args) -> int: | ||
|
@@ -418,8 +421,9 @@ | |
with pytest.raises(PluginValidationError): | ||
pm.register(Plugin()) | ||
|
||
# make sure check_pending still fails if specname doesn't have a | ||
# corresponding spec. EVEN if the function name matches one. | ||
"""make sure check_pending still fails if specname doesn't have a | ||
corresponding spec. EVEN if the function name matches one.""" | ||
|
||
class Plugin2: | ||
@hookimpl(specname="bar") | ||
def hello(self, arg: int) -> int: | ||
|
@@ -448,3 +452,64 @@ | |
"Hook 'conflict' is already registered within namespace " | ||
"<class 'test_hookcaller.test_hook_conflict.<locals>.Api1'>" | ||
) | ||
|
||
|
||
def test_hook_impl_initialization() -> None: | ||
# Mock data | ||
plugin = "example_plugin" | ||
plugin_name = "ExamplePlugin" | ||
|
||
def example_function(x): | ||
return x | ||
|
||
hook_impl_opts: HookimplOpts = { | ||
"wrapper": False, | ||
"hookwrapper": False, | ||
"optionalhook": False, | ||
"tryfirst": False, | ||
"trylast": False, | ||
"specname": "", | ||
} | ||
|
||
# Initialize HookImpl | ||
hook_impl = HookImpl(plugin, plugin_name, example_function, hook_impl_opts) | ||
|
||
# Verify attributes are set correctly | ||
assert hook_impl.function == example_function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that type of test adds no value as far as can tell - lets keep experiments out of the codebase |
||
assert hook_impl.argnames == ("x",) | ||
assert hook_impl.kwargnames == () | ||
assert hook_impl.plugin == plugin | ||
assert hook_impl.opts == hook_impl_opts | ||
assert hook_impl.plugin_name == plugin_name | ||
assert not hook_impl.wrapper | ||
assert not hook_impl.hookwrapper | ||
assert not hook_impl.optionalhook | ||
assert not hook_impl.tryfirst | ||
assert not hook_impl.trylast | ||
|
||
|
||
def test_hook_impl_representation() -> None: | ||
# Mock data | ||
plugin = "example_plugin" | ||
plugin_name = "ExamplePlugin" | ||
|
||
def example_function(x): | ||
return x | ||
|
||
hook_impl_opts: HookimplOpts = { | ||
"wrapper": False, | ||
"hookwrapper": False, | ||
"optionalhook": False, | ||
"tryfirst": False, | ||
"trylast": False, | ||
"specname": "", | ||
} | ||
|
||
# Initialize HookImpl | ||
hook_impl = HookImpl(plugin, plugin_name, example_function, hook_impl_opts) | ||
|
||
# Verify __repr__ method | ||
expected_repr = ( | ||
f"<HookImpl plugin_name={saferepr(plugin_name)}, " f"plugin={saferepr(plugin)}>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we shouldnt add safe-repr all over the place for everything |
||
) | ||
assert repr(hook_impl) == expected_repr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why blindly replace all usages?