Skip to content

Commit afdec04

Browse files
committed
Tests: Refactor inline mw.click_download_button()
1 parent a4e5e3f commit afdec04

File tree

8 files changed

+24
-44
lines changed

8 files changed

+24
-44
lines changed

src/crystal/tests/test_do_not_download_groups.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def test_when_browse_to_html_page_and_browser_requests_embedded_resource_t
8484
assert home_ti is not None
8585
home_ti.SelectItem()
8686
async with wait_for_download_task_to_start_and_finish(project):
87-
await mw.click_download_button()
87+
click_button(mw.download_button)
8888

8989
# Start server
9090
home_ti.SelectItem()
@@ -120,9 +120,7 @@ async def test_given_embedded_resource_selected_in_entity_tree_when_press_downlo
120120

121121
comic_image_r_ti.SelectItem()
122122
async with wait_for_download_task_to_start_and_finish(project):
123-
await mw.click_download_button(
124-
# NOTE: May "finish immediately" because has no embedded subresources
125-
immediate_finish_ok=True)
123+
click_button(mw.download_button)
126124
assert comic_image_r.has_any_revisions()
127125

128126

@@ -135,7 +133,7 @@ async def test_given_do_not_download_group_selected_in_entity_tree_when_press_do
135133
assert home_ti is not None
136134
home_ti.SelectItem()
137135
async with wait_for_download_task_to_start_and_finish(project):
138-
await mw.click_download_button()
136+
click_button(mw.download_button)
139137

140138
# Expand group children in entity tree
141139
comic_image_rg_ti = root_ti.find_child(comic_image_rg_pattern)
@@ -149,7 +147,7 @@ async def test_given_do_not_download_group_selected_in_entity_tree_when_press_do
149147

150148
comic_image_rg_ti.SelectItem()
151149
async with wait_for_download_task_to_start_and_finish(project):
152-
await mw.click_download_button()
150+
click_button(mw.download_button)
153151
assert comic_image_r.has_any_revisions()
154152

155153

src/crystal/tests/test_load_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ async def test_given_project_database_on_ssd_given_resource_group_node_selected_
182182

183183
# Wait for download to start and complete
184184
async with wait_for_download_task_to_start_and_finish(project):
185-
await mw.click_download_button()
185+
click_button(mw.download_button)
186186

187187
# Ensure did not show LoadUrlsProgressDialog
188188
assert 0 == progress_listener_method.call_count

src/crystal/tests/test_new_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ async def test_given_resource_node_with_multiple_link_children_matching_url_patt
257257
grouped_subresources_ti.SelectItem()
258258
assert mw.download_button.IsEnabled()
259259
async with wait_for_download_task_to_start_and_finish(project):
260-
await mw.click_download_button()
260+
click_button(mw.download_button)
261261

262262
# Forget the group to unbundle the links
263263
if True:

src/crystal/tests/test_new_root_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def test_can_create_root_url(
8787
# Download a revision of the root URL
8888
home_ti.SelectItem()
8989
async with wait_for_download_task_to_start_and_finish(project):
90-
await mw.click_download_button()
90+
click_button(mw.download_button)
9191
await _assert_tree_item_icon_tooltip_contains(home_ti, 'Fresh')
9292

9393
# Forget root URL

src/crystal/tests/test_server.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def test_given_default_serving_port_in_use_when_start_serving_project_then
7676
# Download the URL
7777
home_ti.SelectItem()
7878
async with wait_for_download_task_to_start_and_finish(project):
79-
await mw.click_download_button()
79+
click_button(mw.download_button)
8080

8181
# Try to start second server, also on _DEFAULT_SERVER_PORT.
8282
# Expect it to actually start on (_DEFAULT_SERVER_PORT + 1).
@@ -700,7 +700,7 @@ async def test_given_nia_page_visible_when_download_button_pressed_then_download
700700
# Download the home page
701701
home_ti.SelectItem()
702702
async with wait_for_download_task_to_start_and_finish(project):
703-
await mw.click_download_button()
703+
click_button(mw.download_button)
704704

705705
home_url_in_archive = get_request_url(
706706
home_url,
@@ -791,7 +791,7 @@ async def test_when_download_complete_and_successful_download_with_fetch_error_t
791791
# Download the home page
792792
home_ti.SelectItem()
793793
async with wait_for_download_task_to_start_and_finish(project):
794-
await mw.click_download_button()
794+
click_button(mw.download_button)
795795

796796
home_url_in_archive = get_request_url(
797797
home_url,
@@ -2826,7 +2826,7 @@ async def _not_in_archive_page_visible_temporarily() -> AsyncIterator[tuple[str,
28262826
# Download the home page
28272827
home_ti.SelectItem()
28282828
async with wait_for_download_task_to_start_and_finish(project):
2829-
await mw.click_download_button()
2829+
click_button(mw.download_button)
28302830

28312831
home_url_in_archive = get_request_url(
28322832
home_url,
@@ -2874,8 +2874,7 @@ async def _fetch_error_page_visible() -> AsyncIterator[tuple[WebPage, str]]:
28742874
with network_down():
28752875
home_ti.SelectItem()
28762876
async with wait_for_download_task_to_start_and_finish(project):
2877-
await mw.click_download_button(
2878-
immediate_finish_ok=True)
2877+
click_button(mw.download_button)
28792878

28802879
home_url_in_archive = get_request_url(
28812880
home_url,

src/crystal/tests/test_tasktree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ async def test_when_top_level_task_is_interactive_priority_then_is_scheduled_bef
658658

659659
# Start download of comic group at non-interactive priority
660660
comic_group_ti.SelectItem()
661-
await mw.click_download_button(project=project)
661+
click_button(mw.download_button)
662662

663663
if populate_download_group_task_members:
664664
# Populate download tasks for the group's members
@@ -741,7 +741,7 @@ async def test_when_download_resource_at_interactive_priority_given_same_resourc
741741

742742
# Start download of comic #1 at non-interactive priority
743743
comic1_ti.SelectItem()
744-
await mw.click_download_button(project=project)
744+
click_button(mw.download_button)
745745

746746
# Start download of comic #2 at interactive priority
747747
comic2_ti.SelectItem()
@@ -789,7 +789,7 @@ async def test_when_download_resource_at_interactive_priority_given_same_resourc
789789
# by selecting corresponding entity tree node and pressing Download button
790790
() = project.root_task.children
791791
comic1_ti.SelectItem()
792-
await mw.click_download_button(project=project)
792+
click_button(mw.download_button)
793793
append_deferred_top_level_tasks(project)
794794

795795
# Ensure DownloadResourceTask for comic #1 scheduled at top-level of task tree

src/crystal/tests/test_workflows.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ async def test_can_download_and_serve_a_static_site_using_main_window_ui() -> No
412412
# Test can download root resource (using download button)
413413
assert home_ti.IsSelected()
414414
async with wait_for_download_task_to_start_and_finish(project):
415-
await mw.click_download_button()
415+
click_button(mw.download_button)
416416

417417
# Test can view resource (that has a downloaded revision)
418418
assert False == (await is_url_not_in_archive(home_url))
@@ -546,7 +546,7 @@ async def test_can_download_and_serve_a_static_site_using_main_window_ui() -> No
546546

547547
feed_group_ti.SelectItem()
548548
async with wait_for_download_task_to_start_and_finish(project):
549-
await mw.click_download_button()
549+
click_button(mw.download_button)
550550

551551
assert False == (await is_url_not_in_archive(atom_feed_url))
552552
assert False == (await is_url_not_in_archive(rss_feed_url))
@@ -885,7 +885,7 @@ async def test_can_download_and_serve_a_site_requiring_dynamic_url_discovery() -
885885

886886
home_ti.SelectItem()
887887
async with wait_for_download_task_to_start_and_finish(project):
888-
await mw.click_download_button()
888+
click_button(mw.download_button)
889889

890890
# Start server
891891
with assert_does_open_webbrowser_to(get_request_url(home_url)):
@@ -1099,7 +1099,7 @@ async def test_can_download_and_serve_a_site_requiring_dynamic_link_rewriting()
10991099

11001100
home_ti.SelectItem()
11011101
async with wait_for_download_task_to_start_and_finish(project):
1102-
await mw.click_download_button()
1102+
click_button(mw.download_button)
11031103

11041104
# Home page has JavaScript that will load sound URLs when
11051105
# executed, but Crystal isn't smart enough to find those
@@ -1218,7 +1218,7 @@ async def test_cannot_download_anything_given_project_is_opened_as_readonly() ->
12181218

12191219
home_ti.SelectItem()
12201220
async with wait_for_download_task_to_start_and_finish(project):
1221-
await mw.click_download_button()
1221+
click_button(mw.download_button)
12221222

12231223
# Ensure home page has link to Comic #1
12241224
home_ti.Expand()
@@ -1344,11 +1344,11 @@ async def test_can_update_downloaded_site_with_newer_page_revisions() -> None:
13441344

13451345
home_ti.SelectItem()
13461346
async with wait_for_download_task_to_start_and_finish(project):
1347-
await mw.click_download_button()
1347+
click_button(mw.download_button)
13481348

13491349
comic1_ti.SelectItem()
13501350
async with wait_for_download_task_to_start_and_finish(project):
1351-
await mw.click_download_button()
1351+
click_button(mw.download_button)
13521352

13531353
# Ensure resource status badge says URL is fresh
13541354
await _assert_tree_item_icon_tooltip_contains(home_ti, 'Fresh')
@@ -1373,17 +1373,11 @@ async def test_can_update_downloaded_site_with_newer_page_revisions() -> None:
13731373

13741374
# Download: Home, Comic #1
13751375
if True:
1376-
# NOTE: Use direct download rather than
1377-
# click_download_button(..., immediate_finish_ok=True)
1378-
# because the latter takes multiple seconds to run
13791376
revision_future = Resource(project, home_url).download(
13801377
wait_for_embedded=True, needs_result=False)
13811378
while not revision_future.done():
13821379
await bg_sleep(DEFAULT_WAIT_PERIOD)
13831380

1384-
# NOTE: Use direct download rather than
1385-
# click_download_button(..., immediate_finish_ok=True)
1386-
# because the latter takes multiple seconds to run
13871381
revision_future = Resource(project, comic1_url).download(
13881382
wait_for_embedded=True, needs_result=False)
13891383
while not revision_future.done():
@@ -1411,13 +1405,11 @@ async def test_can_update_downloaded_site_with_newer_page_revisions() -> None:
14111405
if True:
14121406
home_ti.SelectItem()
14131407
async with wait_for_download_task_to_start_and_finish(project):
1414-
await mw.click_download_button(
1415-
immediate_finish_ok=True)
1408+
click_button(mw.download_button)
14161409

14171410
comic1_ti.SelectItem()
14181411
async with wait_for_download_task_to_start_and_finish(project):
1419-
await mw.click_download_button(
1420-
immediate_finish_ok=True)
1412+
click_button(mw.download_button)
14211413

14221414
# Ensure resource status badge says URL is fresh
14231415
await _assert_tree_item_icon_tooltip_contains(home_ti, 'Fresh')

src/crystal/tests/util/windows.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,6 @@ def edit_button_label_type(self) -> Literal['Edit', 'Get Info']:
397397
else:
398398
raise AssertionError('Unexpected label for edit button: {label!r}')
399399

400-
# === Operations ===
401-
402-
# TODO: Inline
403-
async def click_download_button(self,
404-
*, immediate_finish_ok: bool=False,
405-
project: Project | None=None
406-
) -> None:
407-
click_button(self.download_button)
408-
409400
# === Close ===
410401

411402
CLOSE_TIMEOUT = 4.0

0 commit comments

Comments
 (0)