Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 03477bf

Browse files
author
Anselm Kruis
committed
Stackless issue #147: fix deprecation warnings in Stackless tests
Don't use deprecated functions in the Stackless test suite. (cherry picked from commit 6c49d91)
1 parent bdf5986 commit 03477bf

8 files changed

+36
-38
lines changed

Stackless/unittests/test_defects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def test_tasklet_end_with_wrong_recursion_level(self):
375375
# test for issue #91 https://bitbucket.org/stackless-dev/stackless/issues/91/
376376
"""A test for issue #91, wrong recursion level after tasklet re-binding
377377
378-
Assertion failed: ts->recursion_depth == 0 || (ts->st.main == NULL && prev == next), file ..\Stackless\module\scheduling.c, line 1291
378+
Assertion failed: ts->recursion_depth == 0 || (ts->st.main == NULL && prev == next), file ../Stackless/module/scheduling.c, line 1291
379379
The assertion fails with ts->recursion_depth > 0
380380
381381
It is in function

Stackless/unittests/test_miscell.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def t():
281281
s.throw(TaskletExit)
282282
# the tasklet should be dead
283283
stackless.run()
284-
self.assertRaisesRegexp(RuntimeError, "dead", s.run)
284+
self.assertRaisesRegex(RuntimeError, "dead", s.run)
285285

286286
def test_dead(self):
287287
c = stackless.channel()
@@ -684,7 +684,7 @@ def test_handler(self):
684684
def test_borken_handler(self):
685685
stackless.tasklet(self.func)(self.borken_handler)
686686
with self.handlerctxt(self.borken_handler):
687-
self.assertRaisesRegexp(IndexError, "mods", stackless.run)
687+
self.assertRaisesRegex(IndexError, "mods", stackless.run)
688688
self.assertTrue(self.ran)
689689
self.assertTrue(self.handled)
690690

@@ -871,13 +871,13 @@ def test_bind(self):
871871

872872
self.assertFalse(t.alive)
873873
self.assertIsNone(t.frame)
874-
self.assertEquals(t.nesting_level, 0)
874+
self.assertEqual(t.nesting_level, 0)
875875

876876
t.bind(None) # must not change the tasklet
877877

878878
self.assertFalse(t.alive)
879879
self.assertIsNone(t.frame)
880-
self.assertEquals(t.nesting_level, 0)
880+
self.assertEqual(t.nesting_level, 0)
881881

882882
t.bind(self.task)
883883
t.setup(False)
@@ -900,7 +900,7 @@ def test_bind(self):
900900
def test_bind_fail_not_callable(self):
901901
class C(object):
902902
pass
903-
self.assertRaisesRegexp(TypeError, "callable", stackless.getcurrent().bind, C())
903+
self.assertRaisesRegex(TypeError, "callable", stackless.getcurrent().bind, C())
904904

905905
def test_unbind_ok(self):
906906
if not stackless.enable_softswitch(None):
@@ -926,7 +926,7 @@ def test_unbind_ok(self):
926926
self.assertEqual(self.finally_run_count, 0)
927927

928928
def test_unbind_fail_current(self):
929-
self.assertRaisesRegexp(RuntimeError, "current tasklet", stackless.getcurrent().bind, None)
929+
self.assertRaisesRegex(RuntimeError, "current tasklet", stackless.getcurrent().bind, None)
930930

931931
def test_unbind_fail_scheduled(self):
932932
t = stackless.tasklet(self.task)(False)
@@ -938,7 +938,7 @@ def test_unbind_fail_scheduled(self):
938938
self.assertTrue(t.alive)
939939
self.assertIsInstance(t.frame, types.FrameType)
940940

941-
self.assertRaisesRegexp(RuntimeError, "scheduled", t.bind, None)
941+
self.assertRaisesRegex(RuntimeError, "scheduled", t.bind, None)
942942

943943
def test_unbind_fail_cstate(self):
944944
t = stackless.tasklet(self.task)(True)
@@ -951,7 +951,7 @@ def test_unbind_fail_cstate(self):
951951
self.assertGreaterEqual(t.nesting_level, 1)
952952
self.assertIsInstance(t.frame, types.FrameType)
953953

954-
self.assertRaisesRegexp(RuntimeError, "C state", t.bind, None)
954+
self.assertRaisesRegex(RuntimeError, "C state", t.bind, None)
955955

956956
# remove the tasklet. Must run the finally clause
957957
t = None
@@ -1180,7 +1180,7 @@ def test_switch_blocked(self):
11801180
t = stackless.tasklet(self.blocked_target)()
11811181
t.run()
11821182
self.assertTrue(t.blocked)
1183-
self.assertRaisesRegexp(RuntimeError, "blocked", t.switch)
1183+
self.assertRaisesRegex(RuntimeError, "blocked", t.switch)
11841184
self.c.send(None)
11851185
self.assertTrue(self.finished)
11861186

@@ -1195,7 +1195,7 @@ def test_switch_trapped(self):
11951195
t = stackless.tasklet(self.target)()
11961196
self.assertFalse(t.paused)
11971197
with switch_trapped():
1198-
self.assertRaisesRegexp(RuntimeError, "switch_trap", t.switch)
1198+
self.assertRaisesRegex(RuntimeError, "switch_trap", t.switch)
11991199
self.assertFalse(t.paused)
12001200
t.switch()
12011201
self.assertTrue(self.finished)
@@ -1210,7 +1210,7 @@ def test_switch_blocked_trapped(self):
12101210
t.run()
12111211
self.assertTrue(t.blocked)
12121212
with switch_trapped():
1213-
self.assertRaisesRegexp(RuntimeError, "blocked", t.switch)
1213+
self.assertRaisesRegex(RuntimeError, "blocked", t.switch)
12141214
self.assertTrue(t.blocked)
12151215
self.c.send(None)
12161216
self.assertTrue(self.finished)
@@ -1220,7 +1220,7 @@ def test_switch_paused_trapped(self):
12201220
t.bind(args=())
12211221
self.assertTrue(t.paused)
12221222
with switch_trapped():
1223-
self.assertRaisesRegexp(RuntimeError, "switch_trap", t.switch)
1223+
self.assertRaisesRegex(RuntimeError, "switch_trap", t.switch)
12241224
self.assertTrue(t.paused)
12251225
t.switch()
12261226
self.assertTrue(self.finished)

Stackless/unittests/test_pickle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def f2():
565565
wrap_frame = r[0](*r[1])
566566
self.assertIsInstance(wrap_frame, stackless._wrap.frame)
567567
invalid_state = r[2][:-2] + ((("Not a", "tuple of 3", "integers"),), r[2][-1])
568-
self.assertRaisesRegexp(TypeError, "an integer is required", wrap_frame.__setstate__, invalid_state)
568+
self.assertRaisesRegex(TypeError, "an integer is required", wrap_frame.__setstate__, invalid_state)
569569
# must not raise an assertion
570570
wrap_frame.__setstate__(r[2])
571571
self.assertIs(type(wrap_frame), types.FrameType)

Stackless/unittests/test_sched_cb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def cb(prev, next):
141141
stackless.set_schedule_callback(None)
142142
for real_name, ex, current_name in switches:
143143
if real_name:
144-
self.assertEquals(real_name, current_name)
144+
self.assertEqual(real_name, current_name)
145145
if ex:
146-
self.assertEquals(ex.name, current_name)
146+
self.assertEqual(ex.name, current_name)
147147

148148
def testGetCallback(self):
149149
mon = SchedulingMonitor()

Stackless/unittests/test_thread.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def job():
282282
def test_rebind_nontrivial(self):
283283
end, task = self.create_remote_tasklet(nontrivial=True)
284284
try:
285-
self.assertRaisesRegexp(RuntimeError, "C state", task.bind_thread)
285+
self.assertRaisesRegex(RuntimeError, "C state", task.bind_thread)
286286
finally:
287287
end()
288288

@@ -385,7 +385,7 @@ def test_rebound_tasklet_from_dead_thread(self):
385385

386386
def test_bind_runnable(self):
387387
theThread, t = self.create_thread_task()
388-
self.assertRaisesRegexp(RuntimeError, "runnable", t.bind_thread)
388+
self.assertRaisesRegex(RuntimeError, "runnable", t.bind_thread)
389389
theThread.join()
390390

391391
def test_death(self):
@@ -586,7 +586,7 @@ def tasklet_runnable_action(self):
586586
def test_rebind_runnable(self):
587587
theThread, t = self.create_thread_task(self.tasklet_runnable_action)
588588
with theThread:
589-
self.assertRaisesRegexp(RuntimeError, 'runnable', t.bind_thread)
589+
self.assertRaisesRegex(RuntimeError, 'runnable', t.bind_thread)
590590
self.channel.send(None)
591591

592592

@@ -603,7 +603,7 @@ def test_switch(self):
603603
with theThread:
604604
time.sleep(0.01)
605605
self.assertTrue(t.paused)
606-
self.assertRaisesRegexp(RuntimeError, "different thread", t.switch)
606+
self.assertRaisesRegex(RuntimeError, "different thread", t.switch)
607607

608608

609609
class SetupFromDifferentThreadTest(RemoteTaskletTests):

Stackless/unittests/test_tracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ def testSetTraceOnCurrent(self):
128128
def testSetTraceOnDeadTasklet(self):
129129
t = stackless.tasklet()
130130
self.assertIsNone(t.trace_function)
131-
self.assertRaisesRegexp(RuntimeError, "tasklet is not alive",
131+
self.assertRaisesRegex(RuntimeError, "tasklet is not alive",
132132
setattr, t, "trace_function", self.nullTraceFunc)
133133

134134
def testSetProfileOnDeadTasklet(self):
135135
t = stackless.tasklet()
136136
self.assertIsNone(t.trace_function)
137-
self.assertRaisesRegexp(RuntimeError, "tasklet is not alive",
137+
self.assertRaisesRegex(RuntimeError, "tasklet is not alive",
138138
setattr, t, "profile_function", self.nullTraceFunc)
139139

140140
def testSetTraceOnTasklet1(self):

Stackless/unittests/test_tstate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def testTracedMainNormalTasklet(self):
255255
self.maxDiff = None
256256
expected = [('mark', self.Tasklet2.__name__, i) for i in
257257
('start', 'before schedule', 'after schedule', 'end schedule')]
258-
self.assertEquals(trace_in_tasklet, expected)
258+
self.assertEqual(trace_in_tasklet, expected)
259259

260260
# Test the combination of Exception and Trace State
261261

@@ -334,7 +334,7 @@ def testReduceOfTracingState(self):
334334
# test if the tracing cframe is present / not present
335335
reduce_frame = get_reduce_frame()
336336
self.assertListEqual(reduced_tasklet1[2][3], [reduce_frame(frame)])
337-
self.assertEquals(len(reduced_tasklet2[2][3]), 2)
337+
self.assertEqual(len(reduced_tasklet2[2][3]), 2)
338338
self.assertIs(reduced_tasklet2[2][3][0], reduce_frame(frame))
339339
self.assertIsInstance(reduced_tasklet2[2][3][1], stackless.cframe)
340340

Stackless/unittests/test_watchdog.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,14 @@ def test_nested2(self):
188188

189189
def test_tasklet_with_schedule(self):
190190
# make sure that we get enough tick counting
191-
try:
192-
hold = sys.getcheckinterval()
193-
except AttributeError:
194-
hold = 10 # default before 2.3
195-
sys.setcheckinterval(10)
191+
hold = sys.getswitchinterval()
192+
self.addCleanup(sys.setswitchinterval, hold)
193+
sys.setswitchinterval(0.001)
196194

197195
n1 = self.run_tasklets(runtask)
198196
n2 = self.run_tasklets(runtask2)
199197

200-
sys.setcheckinterval(hold)
198+
sys.setswitchinterval(hold)
201199
if self.verbose:
202200
print()
203201
print(20 * "*", "runtask:", n1, "runtask2:", n2)
@@ -333,26 +331,26 @@ class TestDeadlock(StacklessTestCase):
333331
def testReceiveOnMain(self):
334332
"""Thest that we get a deadock exception if main tries to block"""
335333
self.c = stackless.channel()
336-
self.assertRaisesRegexp(RuntimeError, "Deadlock", self.c.receive)
334+
self.assertRaisesRegex(RuntimeError, "Deadlock", self.c.receive)
337335

338336
def test_main_receiving_endttasklet(self):
339337
"""Test that the main tasklet is interrupted when a tasklet ends"""
340338
c = stackless.channel()
341339
t = stackless.tasklet(lambda: None)()
342-
self.assertRaisesRegexp(RuntimeError, "receiving", c.receive)
340+
self.assertRaisesRegex(RuntimeError, "receiving", c.receive)
343341

344342
def test_main_sending_enddtasklet(self):
345343
"""Test that the main tasklet is interrupted when a tasklet ends"""
346344
c = stackless.channel()
347345
t = stackless.tasklet(lambda: None)()
348-
self.assertRaisesRegexp(RuntimeError, "sending", c.send, None)
346+
self.assertRaisesRegex(RuntimeError, "sending", c.send, None)
349347

350348
def test_main_gets_exception(self):
351349
"""Test that a custom exception is transfered to a blocked main"""
352350
def task():
353351
raise ZeroDivisionError("mumbai")
354352
stackless.tasklet(task)()
355-
self.assertRaisesRegexp(ZeroDivisionError, "mumbai", stackless.channel().receive)
353+
self.assertRaisesRegex(ZeroDivisionError, "mumbai", stackless.channel().receive)
356354

357355
@require_one_thread
358356
def test_tasklet_deadlock(self):
@@ -361,7 +359,7 @@ def test_tasklet_deadlock(self):
361359

362360
def task():
363361
c = stackless.channel()
364-
self.assertRaisesRegexp(RuntimeError, "Deadlock", c.receive)
362+
self.assertRaisesRegex(RuntimeError, "Deadlock", c.receive)
365363
mc.send(None)
366364
t = stackless.tasklet(task)()
367365
mc.receive()
@@ -375,7 +373,7 @@ def task():
375373
stackless.channel().receive()
376374
t = stackless.tasklet(task)()
377375
# main should get the tasklet's exception
378-
self.assertRaisesRegexp(RuntimeError, "Deadlock", mc.receive)
376+
self.assertRaisesRegex(RuntimeError, "Deadlock", mc.receive)
379377

380378
def test_error_propagation_when_not_deadlock(self):
381379
def task1():
@@ -386,7 +384,7 @@ def task2():
386384

387385
t1 = stackless.tasklet(task1)()
388386
t2 = stackless.tasklet(task2)()
389-
self.assertRaisesRegexp(ZeroDivisionError, "bar", stackless.run)
387+
self.assertRaisesRegex(ZeroDivisionError, "bar", stackless.run)
390388

391389

392390
class TestNewWatchdog(StacklessTestCase):
@@ -471,7 +469,7 @@ def errfunc():
471469

472470
def runner_func():
473471
stackless.tasklet(errfunc)()
474-
self.assertRaisesRegexp(RuntimeError, "foo", stackless.run)
472+
self.assertRaisesRegex(RuntimeError, "foo", stackless.run)
475473
self.done += 1
476474
stackless.tasklet(runner_func)()
477475
stackless.run()

0 commit comments

Comments
 (0)