1- """Tests for the asyncio tools script."""
2-
31import unittest
42
53from asyncio import tools
@@ -595,13 +593,13 @@ class TestAsyncioToolsTree(unittest.TestCase):
595593 def test_asyncio_utils (self ):
596594 for input_ , tree in TEST_INPUTS_TREE :
597595 with self .subTest (input_ ):
598- self .assertEqual (tools .print_async_tree (input_ ), tree )
596+ self .assertEqual (tools .build_async_tree (input_ ), tree )
599597
600598 def test_asyncio_utils_cycles (self ):
601599 for input_ , cycles in TEST_INPUTS_CYCLES_TREE :
602600 with self .subTest (input_ ):
603601 try :
604- tools .print_async_tree (input_ )
602+ tools .build_async_tree (input_ )
605603 except tools .CycleFoundException as e :
606604 self .assertEqual (e .cycles , cycles )
607605
@@ -615,10 +613,10 @@ def test_asyncio_utils(self):
615613
616614class TestAsyncioToolsBasic (unittest .TestCase ):
617615 def test_empty_input_tree (self ):
618- """Test print_async_tree with empty input."""
616+ """Test build_async_tree with empty input."""
619617 result = []
620618 expected_output = []
621- self .assertEqual (tools .print_async_tree (result ), expected_output )
619+ self .assertEqual (tools .build_async_tree (result ), expected_output )
622620
623621 def test_empty_input_table (self ):
624622 """Test build_task_table with empty input."""
@@ -629,7 +627,7 @@ def test_empty_input_table(self):
629627 def test_only_independent_tasks_tree (self ):
630628 input_ = [(1 , [(10 , "taskA" , []), (11 , "taskB" , [])])]
631629 expected = [["└── (T) taskA" ], ["└── (T) taskB" ]]
632- result = tools .print_async_tree (input_ )
630+ result = tools .build_async_tree (input_ )
633631 self .assertEqual (sorted (result ), sorted (expected ))
634632
635633 def test_only_independent_tasks_table (self ):
@@ -640,7 +638,7 @@ def test_only_independent_tasks_table(self):
640638 )
641639
642640 def test_single_task_tree (self ):
643- """Test print_async_tree with a single task and no awaits."""
641+ """Test build_async_tree with a single task and no awaits."""
644642 result = [
645643 (
646644 1 ,
@@ -654,7 +652,7 @@ def test_single_task_tree(self):
654652 "└── (T) Task-1" ,
655653 ]
656654 ]
657- self .assertEqual (tools .print_async_tree (result ), expected_output )
655+ self .assertEqual (tools .build_async_tree (result ), expected_output )
658656
659657 def test_single_task_table (self ):
660658 """Test build_task_table with a single task and no awaits."""
@@ -670,7 +668,7 @@ def test_single_task_table(self):
670668 self .assertEqual (tools .build_task_table (result ), expected_output )
671669
672670 def test_cycle_detection (self ):
673- """Test print_async_tree raises CycleFoundException for cyclic input."""
671+ """Test build_async_tree raises CycleFoundException for cyclic input."""
674672 result = [
675673 (
676674 1 ,
@@ -681,11 +679,11 @@ def test_cycle_detection(self):
681679 )
682680 ]
683681 with self .assertRaises (tools .CycleFoundException ) as context :
684- tools .print_async_tree (result )
682+ tools .build_async_tree (result )
685683 self .assertEqual (context .exception .cycles , [[3 , 2 , 3 ]])
686684
687685 def test_complex_tree (self ):
688- """Test print_async_tree with a more complex tree structure."""
686+ """Test build_async_tree with a more complex tree structure."""
689687 result = [
690688 (
691689 1 ,
@@ -705,7 +703,7 @@ def test_complex_tree(self):
705703 " └── (T) Task-3" ,
706704 ]
707705 ]
708- self .assertEqual (tools .print_async_tree (result ), expected_output )
706+ self .assertEqual (tools .build_async_tree (result ), expected_output )
709707
710708 def test_complex_table (self ):
711709 """Test build_task_table with a more complex tree structure."""
@@ -747,7 +745,7 @@ def test_deep_coroutine_chain(self):
747745 " └── (T) leaf" ,
748746 ]
749747 ]
750- result = tools .print_async_tree (input_ )
748+ result = tools .build_async_tree (input_ )
751749 self .assertEqual (result , expected )
752750
753751 def test_multiple_cycles_same_node (self ):
@@ -762,7 +760,7 @@ def test_multiple_cycles_same_node(self):
762760 )
763761 ]
764762 with self .assertRaises (tools .CycleFoundException ) as ctx :
765- tools .print_async_tree (input_ )
763+ tools .build_async_tree (input_ )
766764 cycles = ctx .exception .cycles
767765 self .assertTrue (any (set (c ) == {1 , 2 , 3 } for c in cycles ))
768766
@@ -789,7 +787,7 @@ def test_task_awaits_self(self):
789787 """A task directly awaits itself – should raise a cycle."""
790788 input_ = [(1 , [(1 , "Self-Awaiter" , [[["loopback" ], 1 ]])])]
791789 with self .assertRaises (tools .CycleFoundException ) as ctx :
792- tools .print_async_tree (input_ )
790+ tools .build_async_tree (input_ )
793791 self .assertIn ([1 , 1 ], ctx .exception .cycles )
794792
795793 def test_task_with_missing_awaiter_id (self ):
@@ -811,7 +809,7 @@ def test_duplicate_coroutine_frames(self):
811809 ],
812810 )
813811 ]
814- tree = tools .print_async_tree (input_ )
812+ tree = tools .build_async_tree (input_ )
815813 # Both children should be under the same coroutine node
816814 flat = "\n " .join (tree [0 ])
817815 self .assertIn ("frameA" , flat )
@@ -827,13 +825,13 @@ def test_task_with_no_name(self):
827825 """Task with no name in id2name – should still render with fallback."""
828826 input_ = [(1 , [(1 , "root" , [[["f1" ], 2 ]]), (2 , None , [])])]
829827 # If name is None, fallback to string should not crash
830- tree = tools .print_async_tree (input_ )
828+ tree = tools .build_async_tree (input_ )
831829 self .assertIn ("(T) None" , "\n " .join (tree [0 ]))
832830
833831 def test_tree_rendering_with_custom_emojis (self ):
834832 """Pass custom emojis to the tree renderer."""
835833 input_ = [(1 , [(1 , "MainTask" , [[["f1" , "f2" ], 2 ]]), (2 , "SubTask" , [])])]
836- tree = tools .print_async_tree (input_ , task_emoji = "🧵" , cor_emoji = "🔁" )
834+ tree = tools .build_async_tree (input_ , task_emoji = "🧵" , cor_emoji = "🔁" )
837835 flat = "\n " .join (tree [0 ])
838836 self .assertIn ("🧵 MainTask" , flat )
839837 self .assertIn ("🔁 f1" , flat )
0 commit comments