Skip to content

Commit 152b3d7

Browse files
mgmacias95pablogsal
authored andcommitted
improve tests
1 parent 6f8bd4c commit 152b3d7

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

Lib/asyncio/tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def _cor_node(parent_key, frame_name):
7373

7474

7575
def _roots(id2label, children):
76-
roots = [n for n, lbl in id2label.items() if lbl == "Task-1"]
77-
if roots:
78-
return roots
76+
# roots = [n for n, lbl in id2label.items() if lbl == "Task-1"]
77+
# if roots:
78+
# return roots
7979
all_children = {c for kids in children.values() for c in kids}
8080
return [n for n in id2label if n not in all_children]
8181

@@ -187,6 +187,7 @@ def build_task_table(result):
187187
print(f"Error retrieving tasks: {e}")
188188
sys.exit(1)
189189

190+
print(tasks)
190191
if args.tree:
191192
# Print the async call tree
192193
result = print_async_tree(tasks)

Lib/test/test_asyncio/test_tools.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Tests for the asyncio tools script."""
22

3+
import unittest
4+
35
from Lib.asyncio import tools
4-
from test.test_asyncio import utils as test_utils
56

67

78
# mock output of get_all_awaited_by function.
@@ -209,48 +210,53 @@
209210
# test case containing two roots
210211
(
211212
(
212-
1,
213+
9,
213214
[
214-
(2, "Task-1", []),
215-
(3, "timer", [[["awaiter"], 4]]),
216-
(4, "subtask1", [[["main"], 2]]),
215+
(5, "Task-5", []),
216+
(6, "Task-6", [[["main2"], 5]]),
217+
(7, "Task-7", [[["main2"], 5]]),
218+
(8, "Task-8", [[["main2"], 5]]),
217219
],
218220
),
219221
(
220-
5,
222+
10,
221223
[
222-
(6, "Task-1", []),
223-
(7, "sleeper", [[["awaiter2"], 8]]),
224-
(8, "subtask2", [[["main"], 6]]),
224+
(1, "Task-1", []),
225+
(2, "Task-2", [[["main"], 1]]),
226+
(3, "Task-3", [[["main"], 1]]),
227+
(4, "Task-4", [[["main"], 1]]),
225228
],
226229
),
230+
(11, []),
227231
(0, []),
228232
),
229233
([]),
230234
(
231235
[
232236
[
233-
"└── (T) Task-1",
234-
" └── main",
235-
" ── (T) subtask1",
236-
" ── awaiter",
237-
" └── (T) timer",
237+
"└── (T) Task-5",
238+
" └── main2",
239+
" ── (T) Task-6",
240+
" ── (T) Task-7",
241+
" └── (T) Task-8",
238242
],
239243
[
240244
"└── (T) Task-1",
241245
" └── main",
242-
" ── (T) subtask2",
243-
" ── awaiter2",
244-
" └── (T) sleeper",
246+
" ── (T) Task-2",
247+
" ── (T) Task-3",
248+
" └── (T) Task-4",
245249
],
246250
]
247251
),
248252
(
249253
[
250-
[1, "0x3", "timer", "awaiter", "subtask1", "0x4"],
251-
[1, "0x4", "subtask1", "main", "Task-1", "0x2"],
252-
[5, "0x7", "sleeper", "awaiter2", "subtask2", "0x8"],
253-
[5, "0x8", "subtask2", "main", "Task-1", "0x6"],
254+
[9, "0x6", "Task-6", "main2", "Task-5", "0x5"],
255+
[9, "0x7", "Task-7", "main2", "Task-5", "0x5"],
256+
[9, "0x8", "Task-8", "main2", "Task-5", "0x5"],
257+
[10, "0x2", "Task-2", "main", "Task-1", "0x1"],
258+
[10, "0x3", "Task-3", "main", "Task-1", "0x1"],
259+
[10, "0x4", "Task-4", "main", "Task-1", "0x1"],
254260
]
255261
),
256262
],
@@ -366,7 +372,7 @@
366372
]
367373

368374

369-
class TestAsyncioTools(test_utils.TestCase):
375+
class TestAsyncioTools(unittest.TestCase):
370376

371377
def test_asyncio_utils(self):
372378
for input_, cycles, tree, table in TEST_INPUTS:
@@ -376,7 +382,5 @@ def test_asyncio_utils(self):
376382
except tools.CycleFoundException as e:
377383
self.assertEqual(e.cycles, cycles)
378384
else:
379-
print(tools.print_async_tree(input_))
380385
self.assertEqual(tools.print_async_tree(input_), tree)
381-
print(tools.build_task_table(input_))
382386
self.assertEqual(tools.build_task_table(input_), table)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy