-
Notifications
You must be signed in to change notification settings - Fork 47
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
Use qualname to avoid key collisions #257
base: main
Are you sure you want to change the base?
Changes from 3 commits
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from dogpile.cache import util | ||
|
||
|
||
class A: | ||
@classmethod | ||
def class_method(cls): | ||
pass | ||
|
||
@staticmethod | ||
def static_method(): | ||
pass | ||
|
||
def instance_method(self): | ||
pass | ||
|
||
def nested_method(self): | ||
def nested(): | ||
pass | ||
|
||
return nested | ||
|
||
|
||
def test_function_key_generator_qualname(): | ||
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. I would break up each test case here and have them come in using pytest.mark.parametrize as a decorator on |
||
key_generator = util.function_key_generator( | ||
None, A.class_method, use_qual_name=True | ||
) | ||
assert key_generator() == "tests.cache.test_util:A.class_method|" | ||
|
||
key_generator = util.function_key_generator( | ||
None, A.static_method, use_qual_name=True | ||
) | ||
assert key_generator() == "tests.cache.test_util:A.static_method|" | ||
|
||
key_generator = util.function_key_generator( | ||
None, A.instance_method, use_qual_name=True | ||
) | ||
assert key_generator() == "tests.cache.test_util:A.instance_method|" | ||
|
||
key_generator = util.function_key_generator( | ||
"namespace", A.class_method, use_qual_name=True | ||
) | ||
assert key_generator() == "tests.cache.test_util:A.class_method|namespace|" | ||
|
||
nested = A().nested_method() | ||
key_generator = util.function_key_generator( | ||
None, nested, use_qual_name=True | ||
) | ||
assert ( | ||
key_generator() | ||
== "tests.cache.test_util:A.nested_method.<locals>.nested|" | ||
) | ||
|
||
|
||
def test_function_key_generator(): | ||
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. same here, then also for the multi key and kwarg versions |
||
key_generator = util.function_key_generator(None, A.class_method) | ||
assert key_generator() == "tests.cache.test_util:class_method|" | ||
|
||
key_generator = util.function_key_generator(None, A.static_method) | ||
assert key_generator() == "tests.cache.test_util:static_method|" | ||
|
||
key_generator = util.function_key_generator(None, A.instance_method) | ||
assert key_generator() == "tests.cache.test_util:instance_method|" | ||
|
||
key_generator = util.function_key_generator("namespace", A.class_method) | ||
assert key_generator() == "tests.cache.test_util:class_method|namespace|" | ||
|
||
nested = A().nested_method() | ||
key_generator = util.function_key_generator(None, nested) | ||
assert key_generator() == "tests.cache.test_util:nested|" |
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.
how about also in:
def function_multi_key_generator
def kwarg_function_key_generator