-
Notifications
You must be signed in to change notification settings - Fork 586
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
Teach the Ghostwriter about @staticmethod and @classmethod methods
#3318
Comments
|
This looks really interesting. Do you mind if I dip my toe into it? (I don't know if it will be a good issue for me but I am happy to spend time on it, tell me if I should go something else instead) |
|
Go for it! Just expect to also need a while to read through the module, there's A Lot Of Code. You might also find it helpful to read "callers to callees" rather than "top to bottom", starting with the |
|
quick report of what I found by testing the from hypothesis.extra import ghostwriter
def just_func(variable: int):
return varibale
class A:
@staticmethod
def stat_func(variable: int):
return varibale
@classmethod
def class_func(cls, variable: int):
return varibale
print(ghostwriter.equivalent(A.class_func, just_func))
print("================")
print(ghostwriter.equivalent(A.class_func, just_func))Will gives: # This test code was written by the `hypothesis.extra.ghostwriter` module
# and is provided under the Creative Commons Zero public domain dedication.
from hypothesis import given, strategies as st
@given(variable=st.integers())
def test_equivalent_A_class_func_just_func(variable):
result_class_func = A.class_func(variable=variable)
result_just_func = just_func(variable=variable)
assert result_class_func == result_just_func, (result_class_func, result_just_func)
================
# This test code was written by the `hypothesis.extra.ghostwriter` module
# and is provided under the Creative Commons Zero public domain dedication.
from hypothesis import given, strategies as st
@given(variable=st.integers())
def test_equivalent_A_class_func_just_func(variable):
result_class_func = A.class_func(variable=variable)
result_just_func = just_func(variable=variable)
assert result_class_func == result_just_func, (result_class_func, result_just_func)So I guess for the 1st task it just need to rename the test to |
|
It got more complicated when using with CLI as |
|
|
Ah sorry, I actually know the syntax highlighting but am too lazy to use it. My bad |
|
For the CLI stuff actually I was working on it so don't mind including it |
The Hypothesis Ghostwriter currently only writes tests for functions, because they're a natural starting point for property-based tests and the primary design goal is to make it incredibly easy to get started.
It's also usually unclear what properties you could guess for classes or instances, but in conversation at PyCon today we worked out that there are a few special cases in which we can test something after all:
@staticmethodis just like a function (albeit glued onto a class), so we could treat it just like we do any other function, replacing the dot with triple-underscore for name-based analyses.@classmethods are similar in that they don't require a pre-build instance. In addition to the "fuzz" tests which just check for internal errors, we can also:from_*classmethods return an instance of the class (by strong convention)to_*method (if one exists) inverts this.The text was updated successfully, but these errors were encountered: