Skip to content

Commit 2c615d7

Browse files
committed
Tighten up tests a bit
1 parent dfee405 commit 2c615d7

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

hypothesis-python/tests/ghostwriter/test_ghostwriter_cli.py

+11-25
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
import pytest
1919

20-
import hypothesis.strategies
2120
from hypothesis.errors import StopTest
2221
from hypothesis.extra.ghostwriter import (
2322
binary_operation,
2423
equivalent,
2524
fuzz,
2625
idempotent,
27-
magic,
2826
roundtrip,
2927
)
3028

@@ -44,11 +42,10 @@
4442
"--roundtrip json.loads json.dumps --except ValueError",
4543
lambda: roundtrip(json.loads, json.dumps, except_=ValueError),
4644
),
47-
("hypothesis.strategies.builds", lambda: fuzz(hypothesis.strategies.builds)),
48-
# Discover methods in class
49-
("hypothesis.errors.StopTest", lambda: magic(StopTest)),
5045
# Imports submodule (importlib.import_module passes; __import__ fails)
51-
("hypothesis.strategies", lambda: magic(hypothesis.strategies)),
46+
("hypothesis.errors.StopTest", lambda: fuzz(StopTest)),
47+
# We can write tests for classes even without classmethods or staticmethods
48+
("hypothesis.errors.StopTest", lambda: fuzz(StopTest)),
5249
# Search for identity element does not print e.g. "You can use @seed ..."
5350
("--binary-op operator.add", lambda: binary_operation(operator.add)),
5451
],
@@ -155,36 +152,25 @@ def test_can_import_from_class(tmpdir, func):
155152

156153

157154
@pytest.mark.parametrize(
158-
"classname,funcname,err_msg",
155+
"classname,thing,kind",
159156
[
160-
(
161-
"XX",
162-
"XX",
163-
"Found the 'mycode' module, but it doesn't have a 'XX' class.",
164-
),
165-
(
166-
"MyClass",
167-
"XX",
168-
"Found the 'mycode' module and 'MyClass' class, but it doesn't have a 'XX' attribute.",
169-
),
170-
(
171-
"my_func",
172-
"XX",
173-
"Found the 'mycode' module and 'my_func' attribute, but it doesn't have a 'XX' attribute.",
174-
),
157+
("XX", "", "class"),
158+
("MyClass", " and 'MyClass' class", "attribute"),
159+
("my_func", " and 'my_func' attribute", "attribute"),
175160
],
176161
)
177-
def test_error_import_from_class(tmpdir, classname, funcname, err_msg):
162+
def test_error_import_from_class(tmpdir, classname, thing, kind):
178163
(tmpdir / "mycode.py").write(CLASS_CODE_TO_TEST)
179164
result = subprocess.run(
180-
f"hypothesis write mycode.{classname}.{funcname}",
165+
f"hypothesis write mycode.{classname}.XX",
181166
capture_output=True,
182167
shell=True,
183168
text=True,
184169
cwd=tmpdir,
185170
)
171+
msg = f"Error: Found the 'mycode' module{thing}, but it doesn't have a 'XX' {kind}."
186172
assert result.returncode == 2
187-
assert "Error: " + err_msg in result.stderr
173+
assert msg in result.stderr
188174

189175

190176
def test_magic_discovery_from_module(tmpdir):

0 commit comments

Comments
 (0)