Skip to content

Commit 4e90c00

Browse files
committed
PYTHON-5784 Rename ex to executor in tests
1 parent 2fa2988 commit 4e90c00

2 files changed

Lines changed: 146 additions & 146 deletions

File tree

test/asynchronous/test_periodic_executor.py

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -49,66 +49,66 @@ async def target():
4949

5050
class AsyncPeriodicExecutorTestBase(AsyncUnitTest):
5151
async def asyncSetUp(self):
52-
self.ex = _make_executor()
52+
self.executor = _make_executor()
5353

5454
async def asyncTearDown(self):
55-
self.ex.close()
56-
await self.ex.join(timeout=2)
55+
self.executor.close()
56+
await self.executor.join(timeout=2)
5757

5858

5959
class TestAsyncPeriodicExecutorRepr(AsyncUnitTest):
6060
async def test_repr_contains_class_and_name(self):
61-
ex = _make_executor(name="exec")
62-
r = repr(ex)
61+
executor = _make_executor(name="exec")
62+
r = repr(executor)
6363
self.assertIn("AsyncPeriodicExecutor", r)
6464
self.assertIn("exec", r)
6565

6666

6767
class TestAsyncPeriodicExecutorBasic(AsyncPeriodicExecutorTestBase):
6868
async def test_wake_sets_event(self):
69-
self.assertFalse(self.ex._event)
70-
self.ex.wake()
71-
self.assertTrue(self.ex._event)
69+
self.assertFalse(self.executor._event)
70+
self.executor.wake()
71+
self.assertTrue(self.executor._event)
7272

7373
async def test_update_interval(self):
74-
self.ex.update_interval(60)
75-
self.assertEqual(self.ex._interval, 60)
74+
self.executor.update_interval(60)
75+
self.assertEqual(self.executor._interval, 60)
7676

7777
async def test_skip_sleep(self):
78-
self.assertFalse(self.ex._skip_sleep)
79-
self.ex.skip_sleep()
80-
self.assertTrue(self.ex._skip_sleep)
78+
self.assertFalse(self.executor._skip_sleep)
79+
self.executor.skip_sleep()
80+
self.assertTrue(self.executor._skip_sleep)
8181

8282

8383
class TestAsyncPeriodicExecutorLifecycle(AsyncPeriodicExecutorTestBase):
8484
async def test_open_starts_worker(self):
85-
self.ex.open()
85+
self.executor.open()
8686
if _IS_SYNC:
87-
self.assertIsNotNone(self.ex._thread)
88-
self.assertTrue(self.ex._thread.is_alive())
87+
self.assertIsNotNone(self.executor._thread)
88+
self.assertTrue(self.executor._thread.is_alive())
8989
else:
90-
self.assertIsNotNone(self.ex._task)
90+
self.assertIsNotNone(self.executor._task)
9191

9292
async def test_close_sets_stopped(self):
93-
self.ex.open()
94-
self.ex.close()
95-
self.assertTrue(self.ex._stopped)
96-
await self.ex.join(timeout=1)
93+
self.executor.open()
94+
self.executor.close()
95+
self.assertTrue(self.executor._stopped)
96+
await self.executor.join(timeout=1)
9797

9898
async def test_join_without_open_is_safe(self):
99-
await self.ex.join(timeout=0.01)
99+
await self.executor.join(timeout=0.01)
100100

101101
async def test_multiple_open_calls_have_no_effect(self):
102-
self.ex.open()
102+
self.executor.open()
103103
if _IS_SYNC:
104-
worker_id = id(self.ex._thread)
104+
worker_id = id(self.executor._thread)
105105
else:
106-
worker_id = id(self.ex._task)
107-
self.ex.open()
106+
worker_id = id(self.executor._task)
107+
self.executor.open()
108108
if _IS_SYNC:
109-
self.assertEqual(worker_id, id(self.ex._thread))
109+
self.assertEqual(worker_id, id(self.executor._thread))
110110
else:
111-
self.assertEqual(worker_id, id(self.ex._task))
111+
self.assertEqual(worker_id, id(self.executor._task))
112112

113113

114114
class TestAsyncPeriodicExecutorTarget(AsyncPeriodicExecutorTestBase):
@@ -122,14 +122,14 @@ async def target():
122122
ran.set()
123123
return False
124124

125-
self.ex = _make_executor(target=target)
126-
self.ex.open()
125+
self.executor = _make_executor(target=target)
126+
self.executor.open()
127127
if _IS_SYNC:
128128
self.assertTrue(ran.wait(timeout=2), "target never ran")
129129
else:
130130
await asyncio.wait_for(ran.wait(), timeout=2)
131-
await self.ex.join(timeout=2)
132-
self.assertTrue(self.ex._stopped)
131+
await self.executor.join(timeout=2)
132+
self.assertTrue(self.executor._stopped)
133133

134134
async def test_target_exception_stops_executor(self):
135135
if _IS_SYNC:
@@ -147,13 +147,13 @@ def target():
147147
ran.set()
148148
raise RuntimeError("boom")
149149

150-
self.ex = _make_executor(target=target)
151-
self.ex.open()
150+
self.executor = _make_executor(target=target)
151+
self.executor.open()
152152
self.assertTrue(ran.wait(timeout=2), "target never ran")
153-
self.ex.join(timeout=2)
153+
self.executor.join(timeout=2)
154154
finally:
155155
threading.excepthook = orig_excepthook
156-
self.assertTrue(self.ex._stopped)
156+
self.assertTrue(self.executor._stopped)
157157
self.assertEqual(len(captured_exc), 1)
158158
self.assertIsInstance(captured_exc[0], RuntimeError)
159159
else:
@@ -163,13 +163,13 @@ async def target():
163163
ran.set()
164164
raise RuntimeError("async boom")
165165

166-
self.ex = _make_executor(target=target)
167-
self.ex.open()
166+
self.executor = _make_executor(target=target)
167+
self.executor.open()
168168
await asyncio.wait_for(ran.wait(), timeout=2)
169-
await self.ex.join(timeout=2)
170-
self.assertTrue(self.ex._stopped)
171-
if self.ex._task is not None and self.ex._task.done():
172-
self.ex._task.exception()
169+
await self.executor.join(timeout=2)
170+
self.assertTrue(self.executor._stopped)
171+
if self.executor._task is not None and self.executor._task.done():
172+
self.executor._task.exception()
173173

174174
async def test_skip_sleep_flag_skips_interval(self):
175175
call_times = []
@@ -180,10 +180,10 @@ async def target():
180180
return False
181181
return True
182182

183-
self.ex = _make_executor(interval=30.0, min_interval=0.001, target=target)
184-
self.ex.skip_sleep()
185-
self.ex.open()
186-
await self.ex.join(timeout=3)
183+
self.executor = _make_executor(interval=30.0, min_interval=0.001, target=target)
184+
self.executor.skip_sleep()
185+
self.executor.open()
186+
await self.executor.join(timeout=3)
187187
self.assertGreaterEqual(len(call_times), 2)
188188
self.assertLess(call_times[1] - call_times[0], 5.0)
189189

@@ -202,14 +202,14 @@ async def target():
202202
return False
203203
return True
204204

205-
self.ex = _make_executor(interval=30.0, min_interval=0.01, target=target)
206-
self.ex.open()
205+
self.executor = _make_executor(interval=30.0, min_interval=0.01, target=target)
206+
self.executor.open()
207207
if _IS_SYNC:
208208
woken.wait(timeout=2)
209209
else:
210210
await asyncio.wait_for(woken.wait(), timeout=2)
211-
self.ex.wake()
212-
await self.ex.join(timeout=3)
211+
self.executor.wake()
212+
await self.executor.join(timeout=3)
213213
self.assertGreaterEqual(call_count[0], 2)
214214

215215
async def test_open_after_target_returns_false(self):
@@ -219,32 +219,32 @@ async def target():
219219
called[0] += 1
220220
return False
221221

222-
self.ex = _make_executor(target=target)
223-
self.ex.open()
224-
await self.ex.join(timeout=2)
225-
self.assertTrue(self.ex._stopped)
222+
self.executor = _make_executor(target=target)
223+
self.executor.open()
224+
await self.executor.join(timeout=2)
225+
self.assertTrue(self.executor._stopped)
226226
if not _IS_SYNC:
227-
first_task = self.ex._task
228-
self.ex.open()
229-
await self.ex.join(timeout=2)
227+
first_task = self.executor._task
228+
self.executor.open()
229+
await self.executor.join(timeout=2)
230230
self.assertGreaterEqual(called[0], 2)
231231
if not _IS_SYNC:
232-
self.assertIsNot(self.ex._task, first_task)
232+
self.assertIsNot(self.executor._task, first_task)
233233

234234

235235
class TestShouldStop(AsyncUnitTest):
236236
if _IS_SYNC:
237237

238238
def test_returns_false_when_not_stopped(self):
239-
ex = _make_executor()
240-
self.assertFalse(ex._should_stop())
241-
self.assertFalse(ex._thread_will_exit)
239+
executor = _make_executor()
240+
self.assertFalse(executor._should_stop())
241+
self.assertFalse(executor._thread_will_exit)
242242

243243
def test_returns_true_and_sets_thread_will_exit(self):
244-
ex = _make_executor()
245-
ex._stopped = True
246-
self.assertTrue(ex._should_stop())
247-
self.assertTrue(ex._thread_will_exit)
244+
executor = _make_executor()
245+
executor._stopped = True
246+
self.assertTrue(executor._should_stop())
247+
self.assertTrue(executor._thread_will_exit)
248248

249249

250250
class TestRegisterExecutor(AsyncUnitTest):
@@ -258,12 +258,12 @@ def tearDown(self):
258258
periodic_executor._EXECUTORS.update(self._orig)
259259

260260
def test_register_adds_weakref(self):
261-
ex = _make_executor()
261+
executor = _make_executor()
262262
before = len(periodic_executor._EXECUTORS)
263-
_register_executor(ex)
263+
_register_executor(executor)
264264
self.assertEqual(len(periodic_executor._EXECUTORS), before + 1)
265-
ref = next(r for r in periodic_executor._EXECUTORS if r() is ex)
266-
del ex
265+
ref = next(r for r in periodic_executor._EXECUTORS if r() is executor)
266+
del executor
267267
gc.collect()
268268
self.assertNotIn(ref, periodic_executor._EXECUTORS)
269269

@@ -274,12 +274,12 @@ def target():
274274
ran.set()
275275
return True
276276

277-
ex = _make_executor(target=target)
278-
ex.open()
277+
executor = _make_executor(target=target)
278+
executor.open()
279279
self.assertTrue(ran.wait(timeout=2), "target never ran")
280280
_shutdown_executors()
281-
ex.join(timeout=2)
282-
self.assertTrue(ex._stopped)
281+
executor.join(timeout=2)
282+
self.assertTrue(executor._stopped)
283283

284284
def test_shutdown_executors_safe_when_empty(self):
285285
periodic_executor._EXECUTORS.clear()

0 commit comments

Comments
 (0)