Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit b0f367b

Browse files
committed
timing: turn deprecation-warning to exception on 'wait()' w/o 'message'
1 parent 49f64cd commit b0f367b

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

easypy/timing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,13 @@ def iter_wait(timeout, pred=None, sleep=0.5, message=None,
206206
progressbar=True, throw=True, allow_interruption=False, caption=None):
207207

208208
# Calling wait() with a predicate and no message is very not informative
209-
# and is pending deprecation (throw=False or message=False disables this behavior)
209+
# (throw=False or message=False disables this behavior)
210210
if message is False:
211211
message = None
212212
elif throw and pred and not message:
213-
stack_level = stack_level_to_get_out_of_file()
214-
warnings.warn(
213+
raise Exception(
215214
"Function iter_wait()'s parameter `message` is required if "
216215
"`pred` is passed",
217-
category=DeprecationWarning,
218-
stacklevel=stack_level
219216
)
220217

221218
if timeout is None:

tests/test_timing.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,32 @@
33

44
from easypy.timing import iter_wait, wait, repeat, iter_wait_progress, Timer, TimeoutException
55
from easypy.bunch import Bunch
6-
from easypy.concurrency import concurrent
76

87

9-
# Temporary tests for iter_wait() warnings
10-
def test_wait_warning():
11-
with warnings.catch_warnings(record=True) as w:
12-
warnings.simplefilter("always")
8+
def test_wait_exception():
9+
with pytest.raises(Exception, match=".*`message` is required.*"):
1310
wait(0.1, pred=lambda: True)
14-
wait(0.1)
15-
wait(0.1, pred=lambda: True, message='message')
16-
wait(0.1, pred=lambda: True, message=False)
17-
repeat(0.1, callback=lambda: True)
1811

19-
# Only the first call should throw a DeprecationWarning
20-
assert len(w) == 1
21-
assert issubclass(w[-1].category, DeprecationWarning)
22-
assert "wait()" in str(w[-1].message)
12+
wait(0.1)
13+
wait(0.1, pred=lambda: True, message='message')
14+
wait(0.1, pred=lambda: True, message=False)
15+
repeat(0.1, callback=lambda: True)
2316

2417

2518
def test_iter_wait_warning():
26-
with warnings.catch_warnings(record=True) as w:
27-
warnings.simplefilter("always")
19+
with pytest.raises(Exception, match=".*`message` is required.*"):
2820
for _ in iter_wait(0.1, pred=lambda: True):
2921
pass
3022

31-
no_warn_iters = [
32-
iter_wait(0.1),
33-
iter_wait(0.1, pred=lambda: True, message='message'),
34-
iter_wait(0.1, pred=lambda: True, throw=False),
35-
iter_wait(0.1, pred=lambda: True, message=False)
36-
]
37-
for i in no_warn_iters:
38-
for _ in i:
39-
pass
40-
41-
# Only the first call should throw a DeprecationWarning
42-
assert len(w) == 1
43-
assert issubclass(w[-1].category, DeprecationWarning)
44-
assert "wait()" in str(w[-1].message)
23+
no_warn_iters = [
24+
iter_wait(0.1),
25+
iter_wait(0.1, pred=lambda: True, message='message'),
26+
iter_wait(0.1, pred=lambda: True, throw=False),
27+
iter_wait(0.1, pred=lambda: True, message=False)
28+
]
29+
for i in no_warn_iters:
30+
for _ in i:
31+
pass
4532

4633

4734
def test_iter_wait_progress_inbetween_sleep():
@@ -96,7 +83,7 @@ def pred():
9683
finally:
9784
wait(3)
9885

99-
wait(2, pred)
86+
wait(2, pred, message=False)
10087

10188

10289
def test_wait_with_callable_message():

0 commit comments

Comments
 (0)