|
17 | 17 |
|
18 | 18 | import pytest
|
19 | 19 |
|
20 |
| -import hypothesis.strategies |
21 | 20 | from hypothesis.errors import StopTest
|
22 | 21 | from hypothesis.extra.ghostwriter import (
|
23 | 22 | binary_operation,
|
24 | 23 | equivalent,
|
25 | 24 | fuzz,
|
26 | 25 | idempotent,
|
27 |
| - magic, |
28 | 26 | roundtrip,
|
29 | 27 | )
|
30 | 28 |
|
|
44 | 42 | "--roundtrip json.loads json.dumps --except ValueError",
|
45 | 43 | lambda: roundtrip(json.loads, json.dumps, except_=ValueError),
|
46 | 44 | ),
|
47 |
| - ("hypothesis.strategies.builds", lambda: fuzz(hypothesis.strategies.builds)), |
48 |
| - # Discover methods in class |
49 |
| - ("hypothesis.errors.StopTest", lambda: magic(StopTest)), |
50 | 45 | # 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)), |
52 | 49 | # Search for identity element does not print e.g. "You can use @seed ..."
|
53 | 50 | ("--binary-op operator.add", lambda: binary_operation(operator.add)),
|
54 | 51 | ],
|
@@ -155,36 +152,25 @@ def test_can_import_from_class(tmpdir, func):
|
155 | 152 |
|
156 | 153 |
|
157 | 154 | @pytest.mark.parametrize(
|
158 |
| - "classname,funcname,err_msg", |
| 155 | + "classname,thing,kind", |
159 | 156 | [
|
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"), |
175 | 160 | ],
|
176 | 161 | )
|
177 |
| -def test_error_import_from_class(tmpdir, classname, funcname, err_msg): |
| 162 | +def test_error_import_from_class(tmpdir, classname, thing, kind): |
178 | 163 | (tmpdir / "mycode.py").write(CLASS_CODE_TO_TEST)
|
179 | 164 | result = subprocess.run(
|
180 |
| - f"hypothesis write mycode.{classname}.{funcname}", |
| 165 | + f"hypothesis write mycode.{classname}.XX", |
181 | 166 | capture_output=True,
|
182 | 167 | shell=True,
|
183 | 168 | text=True,
|
184 | 169 | cwd=tmpdir,
|
185 | 170 | )
|
| 171 | + msg = f"Error: Found the 'mycode' module{thing}, but it doesn't have a 'XX' {kind}." |
186 | 172 | assert result.returncode == 2
|
187 |
| - assert "Error: " + err_msg in result.stderr |
| 173 | + assert msg in result.stderr |
188 | 174 |
|
189 | 175 |
|
190 | 176 | def test_magic_discovery_from_module(tmpdir):
|
|
0 commit comments