Skip to content

Commit 42dfdb7

Browse files
committed
swap testing with xml to custom class
1 parent 9364727 commit 42dfdb7

File tree

5 files changed

+41
-179
lines changed

5 files changed

+41
-179
lines changed

hypothesis-python/src/hypothesis/extra/ghostwriter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,11 @@ def magic(
891891
for thing in modules_or_functions:
892892
if callable(thing):
893893
functions.add(thing)
894-
funcs: list = []
894+
# class need to be added for exploration
895+
if inspect.isclass(thing):
896+
funcs = [thing]
897+
else:
898+
funcs = []
895899
elif isinstance(thing, types.ModuleType):
896900
if hasattr(thing, "__all__"):
897901
funcs = [getattr(thing, name, None) for name in thing.__all__]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This test code was written by the `hypothesis.extra.ghostwriter` module
2+
# and is provided under the Creative Commons Zero public domain dedication.
3+
4+
import test_expected_output
5+
from hypothesis import given, strategies as st
6+
7+
8+
@given(arg=st.integers())
9+
def test_fuzz_A_Class_a_staticmethod(arg):
10+
test_expected_output.A_Class.a_staticmethod(arg=arg)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This test code was written by the `hypothesis.extra.ghostwriter` module
2+
# and is provided under the Creative Commons Zero public domain dedication.
3+
4+
import test_expected_output
5+
from hypothesis import given, strategies as st
6+
7+
8+
@given()
9+
def test_fuzz_A_Class():
10+
test_expected_output.A_Class()
11+
12+
13+
@given(arg=st.integers())
14+
def test_fuzz_A_Class_a_classmethod(arg):
15+
test_expected_output.A_Class.a_classmethod(arg=arg)
16+
17+
18+
@given(arg=st.integers())
19+
def test_fuzz_A_Class_a_staticmethod(arg):
20+
test_expected_output.A_Class.a_staticmethod(arg=arg)

hypothesis-python/tests/ghostwriter/recorded/xml_etree_ElementTree.txt

Lines changed: 0 additions & 169 deletions
This file was deleted.

hypothesis-python/tests/ghostwriter/test_expected_output.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class A_Class:
6666
def a_classmethod(cls, arg: int):
6767
pass
6868

69+
@staticmethod
70+
def a_staticmethod(arg: int):
71+
pass
72+
6973

7074
def add(a: float, b: float) -> float:
7175
return a + b
@@ -87,6 +91,7 @@ def divide(a: int, b: int) -> float:
8791
("fuzz_sorted", ghostwriter.fuzz(sorted)),
8892
("fuzz_with_docstring", ghostwriter.fuzz(with_docstring)),
8993
("fuzz_classmethod", ghostwriter.fuzz(A_Class.a_classmethod)),
94+
("fuzz_staticmethod", ghostwriter.fuzz(A_Class.a_staticmethod)),
9095
("fuzz_ufunc", ghostwriter.fuzz(numpy.add)),
9196
("magic_gufunc", ghostwriter.magic(numpy.matmul)),
9297
("magic_base64_roundtrip", ghostwriter.magic(base64.b64encode)),
@@ -177,6 +182,7 @@ def divide(a: int, b: int) -> float:
177182
style="unittest",
178183
),
179184
),
185+
("magic_class", ghostwriter.magic(A_Class)),
180186
pytest.param(
181187
("magic_builtins", ghostwriter.magic(builtins)),
182188
marks=[
@@ -186,15 +192,6 @@ def divide(a: int, b: int) -> float:
186192
)
187193
],
188194
),
189-
pytest.param(
190-
("xml_etree_ElementTree", ghostwriter.magic(xml.etree.ElementTree)),
191-
marks=[
192-
pytest.mark.skipif(
193-
sys.version_info[:2] not in [(3, 9), (3, 10)],
194-
reason="xml.etree.ElementTree.indent new in version 3.9",
195-
)
196-
],
197-
),
198195
],
199196
ids=lambda x: x[0],
200197
)

0 commit comments

Comments
 (0)