66from crystal .tests .util .controls import click_button , click_checkbox , TreeItem
77from crystal .tests .util .server import MockHttpServer , served_project
88from crystal .tests .util .ssd import database_on_ssd
9- from crystal .tests .util .tasks import wait_for_download_task_to_start_and_finish , wait_for_download_to_start_and_finish
9+ from crystal .tests .util .tasks import wait_for_download_task_to_start_and_finish
1010from crystal .tests .util .wait import (
1111 first_child_of_tree_item_is_not_loading_condition ,
1212 tree_has_no_children_condition , tree_item_has_no_children_condition ,
@@ -190,8 +190,8 @@ async def test_given_resource_node_with_multiple_link_children_matching_url_patt
190190 (home_ti ,) = root_ti .Children
191191
192192 # Expand home URL
193- home_ti . Expand ()
194- await wait_for_download_to_start_and_finish ( mw . task_tree )
193+ async with wait_for_download_task_to_start_and_finish ( project ):
194+ home_ti . Expand ( )
195195 assert first_child_of_tree_item_is_not_loading_condition (home_ti )()
196196
197197 # Select a comic link from the home URL
@@ -326,7 +326,7 @@ async def test_given_node_is_selected_in_entity_tree_when_press_new_group_button
326326 comic_rgn = _find_child (root_ti , comic_pattern , url_prefix )
327327
328328 # Children of RootResourceNode (a kind of _ResourceNode) that is inside RootNode
329- await _expand_node (home_rrn , mw , will_download = True )
329+ await _expand_node (home_rrn , project , will_download = True )
330330 home_rrn__atom_feed_rrn = _find_child (
331331 home_rrn , atom_feed_url , url_prefix )
332332 home_rrn__about_rrn = _find_child (
@@ -361,21 +361,21 @@ async def test_given_node_is_selected_in_entity_tree_when_press_new_group_button
361361 # ---
362362
363363 # Children of LinkedResourceNode (a kind of _ResourceNode) that is inside GroupedLinkedResourceNode
364- await _expand_node (home_rrn__feed_glrn__rss_feed_lrn , mw , will_download = True )
364+ await _expand_node (home_rrn__feed_glrn__rss_feed_lrn , project , will_download = True )
365365 home_rrn__feed_glrn__rss_feed_lrn__home_rrn = _find_child (
366366 home_rrn__feed_glrn__rss_feed_lrn , home_url , url_prefix )
367367
368368 # Children of LinkedResourceNode (a kind of _ResourceNode) that is inside RootResourceNode
369369 # HACK: Relies on Crystal's "Not in Archive" page to provide a
370370 # link to the original URL (which is offsite)
371- await _expand_node (home_rrn__archive_lrn , mw ) # not in archive
371+ await _expand_node (home_rrn__archive_lrn , project ) # not in archive
372372 home_rrn__archive_lrn__offsite_cn = _find_child_by_title (
373373 home_rrn__archive_lrn , 'Offsite' )
374374
375375 # Children of LinkedResourceNode (a kind of _ResourceNode) that is inside ClusterNode
376376 # HACK: Relies on Crystal's "Not in Archive" page to provide a
377377 # link to the original URL (which is offsite)
378- await _expand_node (home_rrn__offsite_cn__twitter_lrn , mw ) # not in archive
378+ await _expand_node (home_rrn__offsite_cn__twitter_lrn , project ) # not in archive
379379 home_rrn__offsite_cn__twitter_lrn__offsite_cn = _find_child_by_title (
380380 home_rrn__offsite_cn__twitter_lrn , 'Offsite' )
381381 await _expand_node (home_rrn__embedded_cn__stylesheet_lrn ) # already downloaded
@@ -430,15 +430,14 @@ async def test_given_node_is_selected_in_entity_tree_when_press_new_group_button
430430 assertEqual ('Feed' , await _source_name_for_node (feed_rgn__rss_feed_nrn__home_rrn , mw ))
431431
432432
433- async def _expand_node (node_ti : TreeItem , mw : MainWindow | None = None , * , will_download : bool = False ) -> None :
434- node_ti .Expand ()
433+ async def _expand_node (node_ti : TreeItem , project : Project | None = None , * , will_download : bool = False ) -> None :
435434 if will_download :
436- if mw is None :
437- raise ValueError ('Need mw parameter when will_download=True' )
438- await wait_for_download_to_start_and_finish (
439- mw . task_tree ,
440- immediate_finish_ok = True ,
441- stacklevel_extra = 1 )
435+ if project is None :
436+ raise ValueError ('Need project parameter when will_download=True' )
437+ async with wait_for_download_task_to_start_and_finish ( project ):
438+ node_ti . Expand ()
439+ else :
440+ node_ti . Expand ( )
442441 await wait_for (
443442 first_child_of_tree_item_is_not_loading_condition (node_ti ),
444443 timeout = 3.0 , # took 2.2s on Windows CI
@@ -501,8 +500,8 @@ async def test_given_urls_loaded_and_new_url_created_when_show_new_group_dialog_
501500 assert progress_listener_method .call_count >= 1
502501
503502 # Expand home URL, to discover initial comic URLs
504- home_ti . Expand ()
505- await wait_for_download_to_start_and_finish ( mw . task_tree )
503+ async with wait_for_download_task_to_start_and_finish ( project ):
504+ home_ti . Expand ( )
506505 assert first_child_of_tree_item_is_not_loading_condition (home_ti )()
507506 assert len (comic_ti .Children ) >= 2 # contains at least the first and last comics
508507
@@ -532,8 +531,8 @@ async def test_when_add_group_then_does_not_download_immediately_by_default() ->
532531 with _served_simple_site_with_group () as (home_url , comic_pattern ):
533532 async with (await OpenOrCreateDialog .wait_for ()).create () as (mw , project ):
534533 rr = RootResource (project , 'Home' , Resource (project , home_url ))
535- rr . download ()
536- await wait_for_download_to_start_and_finish ( mw . task_tree )
534+ async with wait_for_download_task_to_start_and_finish ( project ):
535+ rr . download ( )
537536
538537 assert mw .new_group_button .Enabled
539538 click_button (mw .new_group_button )
@@ -553,8 +552,8 @@ async def test_when_add_group_can_download_group_immediately_with_1_extra_click(
553552 with _served_simple_site_with_group () as (home_url , comic_pattern ):
554553 async with (await OpenOrCreateDialog .wait_for ()).create () as (mw , project ):
555554 rr = RootResource (project , 'Home' , Resource (project , home_url ))
556- rr . download ()
557- await wait_for_download_to_start_and_finish ( mw . task_tree )
555+ async with wait_for_download_task_to_start_and_finish ( project ):
556+ rr . download ( )
558557
559558 assert mw .new_group_button .Enabled
560559 click_button (mw .new_group_button )
@@ -563,12 +562,12 @@ async def test_when_add_group_can_download_group_immediately_with_1_extra_click(
563562 ngd .pattern_field .Value = comic_pattern
564563 ngd .name_field .Value = 'Comic'
565564 click_checkbox (ngd .download_immediately_checkbox ) # extra click #1
566- await ngd . ok ()
567-
568- # Ensure started downloading
569- root_ti = TreeItem . GetRootItem ( mw . entity_tree . window )
570- root_ti . find_child ( comic_pattern , project . default_url_prefix )
571- await wait_for_download_to_start_and_finish ( mw . task_tree )
565+ async with wait_for_download_task_to_start_and_finish ( project ):
566+ await ngd . ok ()
567+
568+ # Ensure started downloading
569+ root_ti = TreeItem . GetRootItem ( mw . entity_tree . window )
570+ root_ti . find_child ( comic_pattern , project . default_url_prefix )
572571
573572
574573async def test_when_edit_group_then_new_group_options_not_shown () -> None :
0 commit comments